Mentions légales du service

Skip to content
Snippets Groups Projects
Commit d6c4b872 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[lib] MCLSolutions: refactor FrontierSolution

parent 6a7cbcdb
No related branches found
No related tags found
No related merge requests found
...@@ -433,7 +433,8 @@ class FrontierSolution(object): ...@@ -433,7 +433,8 @@ class FrontierSolution(object):
..TODO:: ..TODO::
- Faire une super classe dont héritent RawSolution et DimacsFrontierSol - Faire une super classe dont héritent RawSolution et DimacsFrontierSol
pour éviter la duplication de code... pour éviter la duplication de code et le stockage d'attributs qu'on
connait déjà dans les types de plus bas niveaux...
- ... Ou détecter le type d'objet dans le constructeur => ducktyping - ... Ou détecter le type d'objet dans le constructeur => ducktyping
- renommer l'attr activated_frontier en activated_frontiers - renommer l'attr activated_frontier en activated_frontiers
""" """
...@@ -458,10 +459,26 @@ class FrontierSolution(object): ...@@ -458,10 +459,26 @@ class FrontierSolution(object):
self.current_step = current_step self.current_step = current_step
@classmethod @classmethod
def build_input_clock_sequence(cls, obj, ic_sequence): def build_input_clock_sequence(cls, get_var_name, ic_sequence):
""" """Get strings representing timings of each step in the solution.
:param get_var_name: Method to call for a conversion of values to names.
(binding of the method get_var_name() of an unfolder).
:param ic_sequence:
- Each tuple is the state of literals in a step of the solution.
- Each literal in the tuple is an activated variable in a step.
- Variables are inputs or events (free clocks) ONLY!
:type get_var_name: <function>
:type ic_sequence: <tuple <tuple <int>>
:return: List of strings representing timings of each step in ic_sequence.
:rtype: <list <str>>
""" """
return [str("% " + " ".join(obj.get_var_name(iii) for iii in icv)).rstrip(" ") for icv in ic_sequence] # Strip used to remove trailing space on empty steps : "% "
return [
str("% " + " ".join(get_var_name(value)
for value in step_literals)).rstrip(" ")
for step_literals in ic_sequence
]
@classmethod @classmethod
def from_raw(cls, raw_sol): def from_raw(cls, raw_sol):
...@@ -483,10 +500,10 @@ class FrontierSolution(object): ...@@ -483,10 +500,10 @@ class FrontierSolution(object):
# 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
ic_seq = raw_sol.extract_act_input_clock_seq() ic_sequence = FrontierSolution.build_input_clock_sequence(
raw_sol.get_var_name,
# Strip used to remove trailing space on empty steps : "% " raw_sol.extract_act_input_clock_seq()
ic_sequence = [str("% " + " ".join(raw_sol.get_var_name(iii) for iii in icv)).rstrip(" ") for icv in ic_seq] )
# LOGGER.debug("FrontierSolution:from_raw:: ic_sequence %s", ic_sequence) # LOGGER.debug("FrontierSolution:from_raw:: ic_sequence %s", ic_sequence)
return cls(activated_frontiers, ic_sequence, raw_sol.current_step) return cls(activated_frontiers, ic_sequence, raw_sol.current_step)
...@@ -509,10 +526,10 @@ class FrontierSolution(object): ...@@ -509,10 +526,10 @@ class FrontierSolution(object):
# 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
ic_seq = dimacs_front_sol.ic_sequence ic_sequence = FrontierSolution.build_input_clock_sequence(
dimacs_front_sol.get_var_name,
# Strip used to remove trailing space on empty steps : "% " dimacs_front_sol.ic_sequence
ic_sequence = [str("% " + " ".join(dimacs_front_sol.get_var_name(iii) for iii in icv)).rstrip(" ") for icv in ic_seq] )
# LOGGER.debug("FrontierSolution:from_dimacs_front_sol:: ic_sequence %s", ic_sequence) # LOGGER.debug("FrontierSolution:from_dimacs_front_sol:: ic_sequence %s", ic_sequence)
return cls(activated_frontiers, ic_sequence, dimacs_front_sol.current_step) return cls(activated_frontiers, ic_sequence, dimacs_front_sol.current_step)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment