Commit 1847f4f5 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[lib] MCLSolutions: black

parent 1648c855
...@@ -69,6 +69,7 @@ LOGGER = cm.logger() ...@@ -69,6 +69,7 @@ LOGGER = cm.logger()
class MCLException(Exception): class MCLException(Exception):
"""Exception for MCLAnalyser""" """Exception for MCLAnalyser"""
def __init__(self, mess): def __init__(self, mess):
self.message = mess self.message = mess
...@@ -122,6 +123,7 @@ class RawSolution(object): ...@@ -122,6 +123,7 @@ class RawSolution(object):
:type unfolder: <CLUnfolder> :type unfolder: <CLUnfolder>
:type current_step: <int> :type current_step: <int>
""" """
def __init__(self, solution, unfolder): def __init__(self, solution, unfolder):
""" """
:param solution: DIMACS encoding of **a solution** from the solver :param solution: DIMACS encoding of **a solution** from the solver
...@@ -216,9 +218,12 @@ class RawSolution(object): ...@@ -216,9 +218,12 @@ class RawSolution(object):
:return: Set of activated frontier values. :return: Set of activated frontier values.
:rtype: <frozenset> :rtype: <frozenset>
""" """
if self.shift_direction == 'FORWARD': if self.shift_direction == "FORWARD":
# frontier_values: Set of frontier positive values only. # frontier_values: Set of frontier positive values only.
return frozenset(self.unfolder.frontier_values) & self.frontier_pos_and_neg_values return (
frozenset(self.unfolder.frontier_values)
& self.frontier_pos_and_neg_values
)
else: else:
NotImplementedError("BACKWARD shift direction is not yet implemented") NotImplementedError("BACKWARD shift direction is not yet implemented")
...@@ -286,7 +291,7 @@ class RawSolution(object): ...@@ -286,7 +291,7 @@ class RawSolution(object):
# return fsol # return fsol
#return fsol # never reach this point #return fsol # never reach this point
if self.shift_direction == 'FORWARD': if self.shift_direction == "FORWARD":
# frontiers_pos_and_neg: # frontiers_pos_and_neg:
# All frontiers and their opposite version Union # All frontiers and their opposite version Union
# Set of frontier positive and negative values. # Set of frontier positive and negative values.
...@@ -302,13 +307,13 @@ class RawSolution(object): ...@@ -302,13 +307,13 @@ class RawSolution(object):
for i, var in enumerate(self.solution): for i, var in enumerate(self.solution):
# the variable is frontier var: # the variable is frontier var:
if abs(var) == frontier: if abs(var) == frontier:
fsol.append(self.solution[i+dec])# look for initial values fsol.append(self.solution[i + dec]) # look for initial values
j += 1 j += 1
if j == jmax: if j == jmax:
# all frontiers are found # all frontiers are found
return frozenset(fsol) return frozenset(fsol)
frontier = frontiers[j] frontier = frontiers[j]
return frozenset(fsol) # never reach this point return frozenset(fsol) # never reach this point
# Useless proposition # Useless proposition
# ps: jmax allows to stop the search when the iteration is made on solution # ps: jmax allows to stop the search when the iteration is made on solution
...@@ -347,7 +352,6 @@ class RawSolution(object): ...@@ -347,7 +352,6 @@ class RawSolution(object):
# and s_varcode in self.unfolder.inputs_and_free_clocks] # and s_varcode in self.unfolder.inputs_and_free_clocks]
return tuple(self.unfolder.inputs_and_free_clocks & frozenset(state_vector)) return tuple(self.unfolder.inputs_and_free_clocks & frozenset(state_vector))
def extract_act_input_clock_seq(self): def extract_act_input_clock_seq(self):
"""Extract the sequence of activated *inputs* and *events/free clocks* """Extract the sequence of activated *inputs* and *events/free clocks*
in the current solution. in the current solution.
...@@ -369,12 +373,14 @@ class RawSolution(object): ...@@ -369,12 +373,14 @@ class RawSolution(object):
""" """
# unflatten() returns a list of state vectors in DIMACS format # unflatten() returns a list of state vectors in DIMACS format
# State vectors are (<list <int>>) # State vectors are (<list <int>>)
return tuple() \ return (
if not self.unfolder.inputs_and_free_clocks \ tuple()
if not self.unfolder.inputs_and_free_clocks
else tuple( else tuple(
self.extract_act_inputs_clocks(activated_inputs_and_clocks) self.extract_act_inputs_clocks(activated_inputs_and_clocks)
for activated_inputs_and_clocks in self.unflatten() # list of lists for activated_inputs_and_clocks in self.unflatten() # list of lists
) )
)
def __len__(self): def __len__(self):
"""Length of solution (number of tuples of literals) """Length of solution (number of tuples of literals)
...@@ -394,7 +400,7 @@ class RawSolution(object): ...@@ -394,7 +400,7 @@ class RawSolution(object):
if dcod > 0: if dcod > 0:
vect_n.append(self.get_var_name(dcod)) vect_n.append(self.get_var_name(dcod))
else: else:
vect_n.append("-"+self.get_var_name(dcod)) vect_n.append("-" + self.get_var_name(dcod))
stn.append(vect_n) stn.append(vect_n)
return str(stn) return str(stn)
...@@ -507,8 +513,9 @@ class FrontierSolution(object): ...@@ -507,8 +513,9 @@ class FrontierSolution(object):
# RawSolution has not activated_frontiers attr we must compute them # RawSolution has not activated_frontiers attr we must compute them
activated_frontier_values = raw_sol.extract_activated_frontier_values() activated_frontier_values = raw_sol.extract_activated_frontier_values()
activated_frontiers = \ activated_frontiers = {
{raw_sol.get_var_name(var_num) for var_num in activated_frontier_values} raw_sol.get_var_name(var_num) for var_num in activated_frontier_values
}
# Get raw activated inputs and free clocks (values) # Get raw activated inputs and free clocks (values)
# and format them so that they are understandable by humans # and format them so that they are understandable by humans
...@@ -532,9 +539,10 @@ class FrontierSolution(object): ...@@ -532,9 +539,10 @@ class FrontierSolution(object):
""" """
# Get names of activated frontier places # Get names of activated frontier places
# DimacsFrontierSol already has activated_frontiers attr # DimacsFrontierSol already has activated_frontiers attr
activated_frontiers = \ activated_frontiers = {
{dimacs_front_sol.get_var_name(var_num) dimacs_front_sol.get_var_name(var_num)
for var_num in dimacs_front_sol.activated_frontier_values} for var_num in dimacs_front_sol.activated_frontier_values
}
# Get raw activated inputs and free clocks (values) # Get raw activated inputs and free clocks (values)
# and format them so that they are understandable by humans # and format them so that they are understandable by humans
...@@ -567,8 +575,11 @@ class FrontierSolution(object): ...@@ -567,8 +575,11 @@ class FrontierSolution(object):
ic_seq.append(step[:-1]) ic_seq.append(step[:-1])
step = f_d.readline() step = f_d.readline()
LOGGER.debug("FrontierSolution:from_file:: ic_seq: %s; maxsteps: %s", LOGGER.debug(
ic_seq, current_step) "FrontierSolution:from_file:: ic_seq: %s; maxsteps: %s",
ic_seq,
current_step,
)
return cls(act_front, ic_seq, current_step) return cls(act_front, ic_seq, current_step)
@cached_property @cached_property
...@@ -593,9 +604,9 @@ class FrontierSolution(object): ...@@ -593,9 +604,9 @@ class FrontierSolution(object):
:type outfile: <open file> :type outfile: <open file>
:type only_macs: <boolean> :type only_macs: <boolean>
""" """
outfile.write(' '.join(self.sorted_activated_frontier) + '\n') outfile.write(" ".join(self.sorted_activated_frontier) + "\n")
if not only_macs: if not only_macs:
outfile.write('\n'.join(self.ic_sequence) + '\n') outfile.write("\n".join(self.ic_sequence) + "\n")
outfile.flush() outfile.flush()
def __eq__(self, other): def __eq__(self, other):
...@@ -816,5 +827,6 @@ class DimacsFrontierSol(object): ...@@ -816,5 +827,6 @@ class DimacsFrontierSol(object):
def __str__(self): def __str__(self):
"""For tests and debug""" """For tests and debug"""
return "<DimacsFrontierSol - Activated frontiers values: %s>".format(self.activated_frontier_values) return "<DimacsFrontierSol - Activated frontiers values: %s>".format(
self.activated_frontier_values
)
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