diff --git a/library/cadbiom/models/clause_constraints/mcl/MCLSolutions.py b/library/cadbiom/models/clause_constraints/mcl/MCLSolutions.py index 577950caaaf485f815030af285d2a0af8827f8a3..96c6bd5b0d4758aa77bc11f5087f054a3e9eea21 100644 --- a/library/cadbiom/models/clause_constraints/mcl/MCLSolutions.py +++ b/library/cadbiom/models/clause_constraints/mcl/MCLSolutions.py @@ -433,7 +433,8 @@ class FrontierSolution(object): ..TODO:: - 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 - renommer l'attr activated_frontier en activated_frontiers """ @@ -458,10 +459,26 @@ class FrontierSolution(object): self.current_step = current_step @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 def from_raw(cls, raw_sol): @@ -483,10 +500,10 @@ class FrontierSolution(object): # Get raw activated inputs and free clocks (values) # and format them so that they are understandable by humans - ic_seq = raw_sol.extract_act_input_clock_seq() - - # Strip used to remove trailing space on empty steps : "% " - ic_sequence = [str("% " + " ".join(raw_sol.get_var_name(iii) for iii in icv)).rstrip(" ") for icv in ic_seq] + ic_sequence = FrontierSolution.build_input_clock_sequence( + raw_sol.get_var_name, + raw_sol.extract_act_input_clock_seq() + ) # LOGGER.debug("FrontierSolution:from_raw:: ic_sequence %s", ic_sequence) return cls(activated_frontiers, ic_sequence, raw_sol.current_step) @@ -509,10 +526,10 @@ class FrontierSolution(object): # Get raw activated inputs and free clocks (values) # and format them so that they are understandable by humans - ic_seq = dimacs_front_sol.ic_sequence - - # Strip used to remove trailing space on empty steps : "% " - ic_sequence = [str("% " + " ".join(dimacs_front_sol.get_var_name(iii) for iii in icv)).rstrip(" ") for icv in ic_seq] + ic_sequence = FrontierSolution.build_input_clock_sequence( + dimacs_front_sol.get_var_name, + dimacs_front_sol.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)