Attention une mise à jour du service Gitlab va être effectuée le mardi 30 novembre entre 17h30 et 18h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes. Cette mise à jour intermédiaire en version 14.0.12 nous permettra de rapidement pouvoir mettre à votre disposition une version plus récente.

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

[lib] MCLSolutions: black

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