Commit 91045d41 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Fix typos

parent 6ff7665f
## Filename : MCLSolutions.py
## Author(s) : Michel Le Borgne
## Created : 03/9/2012
## Revision :
## Source :
## Revision :
## Source :
##
## Copyright 2012 : IRISA/IRSET
##
......@@ -33,8 +33,8 @@
## IRISA
## Symbiose team
## IRISA Campus de Beaulieu
## 35042 RENNES Cedex, FRANCE
##
## 35042 RENNES Cedex, FRANCE
##
##
## Contributor(s): Geoffroy Andrieux - IRISA/IRSET
##
......@@ -48,7 +48,7 @@ class MCLException(Exception):
"""
def __init__(self, mess):
self.message = mess
def __str__(self):
return self.message
......@@ -57,13 +57,13 @@ class RawSolution(object):
RawSolution objects contain a solution got from SAT solver with all
variable parameters from the unfolder. This permit different extractions.
IMPORTANT: the solution MUST correspond to the properties registered
for its computation. Any change in these properties will give incorrect
for its computation. Any change in these properties will give incorrect
results.
"""
def __init__(self, sol, cl_unfolder):
"""
@param sol: DIMACS encoded solution
@param cl_unfolder: the cl_unfolder (to be used for invariant constants)
@param cl_unfolder: the cl_unfolder (to be used for invariant constants)
"""
self.__solution = sol
self.__unfolder = cl_unfolder
......@@ -71,7 +71,7 @@ class RawSolution(object):
self.__shift_step = cl_unfolder.get_shift_step() # dependant on the run
self.__current_step = cl_unfolder.get_current_step()
self.__shift_direction = cl_unfolder.get_shift_direction()
def get_unshift_code(self, var_num):
"""
@param var_num: DIMACS literal coding of a shifted variable x_i
......@@ -88,37 +88,37 @@ class RawSolution(object):
return var_code*sign
else:
raise MCLException("Not a DIMACS code of an initial variable")
def get_var_name(self, var_num):
"""
For translation to symbolic representation
"""
return self.__unfolder.get_var_name(var_num)
def get_solution_size(self):
"""
@return: int
"""
return len(self.__solution)
def get_solution(self):
"""
DIMACS encoding of the solution from the solver
"""
return self.__solution
def get_nbsteps(self):
"""
@return: int
"""
return self.__nb_steps
def get_unfolder(self):
"""
@return: a clunfolder
"""
return self.__unfolder
def unflatten(self):
"""
Transform a flat DIMACS representation of a trajectory into a list<list<int>>
......@@ -141,12 +141,11 @@ class RawSolution(object):
return lv_traj
def extract_frontier_values(self):
"""
Extract values of the init frontier variables from a whole solution vector
Assert: sol is sorted by variable code
@return: a dimacs code list of the activation state on the frontier for sol
"""
jmax = len(self.__unfolder.get_frontier())
......@@ -164,8 +163,9 @@ class RawSolution(object):
j += 1
if j == jmax:
return fsol
return fsol # never reach this point
def extract_act_frontier_values(self, sol):
"""
frontier variables which are active at the beginning of whole solution vector
......@@ -190,9 +190,9 @@ class RawSolution(object):
j += 1
if j == jmax:
return fsol
return fsol # never reach this point
return fsol # never reach this point
def extract_act_inputs_clocks(self, s_vector):
"""
extract active __inputs and clocks from a state vector
......@@ -263,7 +263,7 @@ class FrontierSolution(object):
"""
class for symbolic frontier and timing representation (built from a raw solution)
"""
def __init__(self, act_frontier, ic_seq, horizon):
"""
Build a symbolic representation of frontier values and timing from
......@@ -273,16 +273,16 @@ class FrontierSolution(object):
self.activated_frontier = act_frontier # list<string>
self.ic_sequence = ic_seq # list<string> (format % h1 h2)
self.horizon = horizon # int
@classmethod
def from_raw(cls, raws):
def from_raw(cls, raws):
"""
Build a symbolic representation of frontier values and timing from
a raw solution
@param raws: a raw solution
"""
"""
# activated frontier places
dim_front = raws.extract_frontier_values()
out = []
......@@ -290,7 +290,7 @@ class FrontierSolution(object):
if dcod > 0:
out.append(raws.get_var_name(dcod))
activated_frontier = out
# activated input/clocks
ic_seq = raws.extract_act_input_clock_seq()
lic = []
......@@ -302,14 +302,14 @@ class FrontierSolution(object):
ic_sequence = lic
horizon = raws.get_nbsteps()
return cls(activated_frontier, ic_sequence, horizon)
@classmethod
def from_dimacs_front_sol(cls, fds):
def from_dimacs_front_sol(cls, fds):
"""
Build a symbolic representation of frontier values and timing from
a DimacsFrontierSolution solution
@param fds: a raw solution
"""
"""
# activated frontier places
dim_front = fds.frontier_values
out = []
......@@ -317,7 +317,7 @@ class FrontierSolution(object):
if dcod > 0:
out.append(fds.get_var_name(dcod))
activated_frontier = out
# activated input/clocks
ic_seq = fds.ic_sequence
lic = []
......@@ -328,10 +328,10 @@ class FrontierSolution(object):
lic.append(ic_act)
ic_sequence = lic
horizon = fds.get_nbsteps()
return cls(activated_frontier, ic_sequence, horizon)
return cls(activated_frontier, ic_sequence, horizon)
@classmethod
def from_file(cls, file_name):
def from_file(cls, file_name):
"""
Build a symbolic representation of frontier values and timing from
a DimacsFrontierSolution solution
......@@ -348,8 +348,8 @@ class FrontierSolution(object):
horizon += 1
ic_seq.append(step[:-1])
step = fr_f.readline()
return cls(act_front, ic_seq, horizon)
return cls(act_front, ic_seq, horizon)
def __str__(self):
"""
give a string representation of a Frontier solution
......@@ -386,11 +386,11 @@ class FrontierSolution(object):
outfile.write(' '.join(sorted(self.activated_frontier, key=lambda s: s.lower())) + '\n')
outfile.write('\n'.join(self.ic_sequence) + '\n')
outfile.flush()
class DimacsFrontierSol(object):
"""
class for solution frontier and timing representation
class for solution frontier and timing representation
(built from a raw solution) in Dimacs code
"""
def __init__(self, raws):
......@@ -403,41 +403,41 @@ class DimacsFrontierSol(object):
# self.frontier_values : list<int>
# self.ic_sequence : list<list<int>>
# self.horizon : int
# frontier places
self.frontier_values = raws.extract_frontier_values()
# activated input/clocks (may be empty if data-flow model without input)
self.ic_sequence = raws.extract_act_input_clock_seq()
self.horizon = raws.get_nbsteps()
# CLUnfolder
self.__unfolder = raws.get_unfolder()
def get_var_name(self, var_num):
"""
For translation to symbolic representation
"""
return self.__unfolder.get_var_name(var_num)
def get_solution_size(self):
"""
@return: int
"""
return len(self.frontier_values)
def get_solution(self):
"""
@return: list<int>
"""
return self.frontier_values
def get_nbsteps(self):
"""
@return: int
"""
return self.horizon
def has_same_frontier(self, other):
"""
Check if two DimacsFrontierSol have same frontier
......@@ -457,12 +457,12 @@ class DimacsFrontierSol(object):
Check if an object of ldfs has the same frontier list
@param ldfs: list of DimacsFrontierSol
@return bool
"""
"""
for dfs in ldfs:
if self.has_same_frontier(dfs):
return True
return False
def nb_activated(self):
"""
Count the number of activated places in solution
......@@ -473,7 +473,7 @@ class DimacsFrontierSol(object):
if vcod > 0:
cpt += 1
return cpt
def nb_timed(self):
"""
Count the number of events in solution
......@@ -482,28 +482,28 @@ class DimacsFrontierSol(object):
cpt = 0
for ic_act in self.ic_sequence:
cpt += len(ic_act)
return cpt
return cpt
def display(self):
"""
For tests and debug
"""
print 'Frontier solution:'
print self.frontier_values
# useful functions for solution lists
def extract_dimacs_init_frontier(lsol):
"""
Extract init values of the frontier variables from a whole solution vector for
Extract init values of the frontier variables from a whole solution vector for
a list of solution vectors.
Eliminate double frontier level
@param lsol: list of raw solutions
@return: a list of DimacsFrontierSol
"""
ext = []
ext1 = []
for sol in lsol:
esol = DimacsFrontierSol(sol)
if not esol.front_is_in(ext):
ext.append(esol)
return ext
if not esol.front_is_in(ext1):
ext1.append(esol)
return ext1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment