Commit d8fa5629 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[lib] Improve RawSolution.extract_act_input_clock_seq(): processing of...

[lib] Improve RawSolution.extract_act_input_clock_seq(): processing of solutions is ~15% more efficient
parent d00efdc2
......@@ -106,27 +106,26 @@ class CLUnfolder(object):
self.__aux_list = [] # code to name
# list no_frontier place DIMACS codes
self.__no_frontier_init = []
for nfp in self.__dyn_sys.no_frontier:
self.__no_frontier_init.append([- self.__var_code_table[nfp]])
self.__no_frontier_init = [[-self.__var_code_table[nfp]] for nfp in self.__dyn_sys.no_frontier]
# ordered list of frontier place DIMACS codes for extraction (inv)
self.__frontier = []
for frp in self.__dyn_sys.frontier:
self.__frontier.append(self.__var_code_table[frp])
self.__frontier = [self.__var_code_table[frp] for frp in self.__dyn_sys.frontier]
self.__frontier.sort()
# Convenient attribute for RawSolution.extract_frontier_values()
# all frontiers and their opposite version
# operations with sets are much faster
self._frontiers_pos_and_neg = \
frozenset(-frontier for frontier in self.__frontier) | frozenset(self.__frontier)
# ordered list of input places DIMACS code for extraction (inv)
self.__inputs = []
for inp in self.__dyn_sys.inputs:
self.__inputs.append(self.__var_code_table[inp])
self.__inputs.sort()
self.__inputs = frozenset(self.__var_code_table[inp] for inp in self.__dyn_sys.inputs)
# ordered list of free clocks DIMACS code for extraction (invariant)
self.__free_clocks = []
for fcl in self.__dyn_sys.free_clocks:
self.__free_clocks.append(self.__var_code_table[fcl])
self.__free_clocks.sort()
self.__free_clocks = frozenset(self.__var_code_table[fcl] for fcl in self.__dyn_sys.free_clocks)
# Binding for a merged version of __inputs and __free_clocks
# Convenient attribute for RawSolution.extract_frontier_values()
self.__inputs_and_free_clocks = self.__inputs | self.__free_clocks
# properties to be checked
self.__initial_property = None # string
......@@ -303,6 +302,17 @@ class CLUnfolder(object):
"""
return self.__frontier
def get_frontiers_pos_and_neg(self):
"""
Convenient attribute for RawSolution.extract_frontier_values()
all frontiers and their opposite version
operations with sets are much faster
:return: Set of frontier positive and negative values.
:rtype: <frozenset>
"""
return self._frontiers_pos_and_neg
def get_free_clocks(self):
"""
@return: the DIMACS code of the free_clocks variables
......@@ -315,6 +325,15 @@ class CLUnfolder(object):
"""
return self.__inputs
def get_inputs_and_free_clocks(self):
"""Binding for a merged version of __inputs and __free_clocks
Convenient attribute for RawSolution.extract_frontier_values()
:return: the DIMACS code of the input and free_clocks variables
:rtype: <frozenset>
"""
return self.__inputs_and_free_clocks
def get_shift_direction(self):
"""
@return: string "FORWARD" or "BACKWARD"
......
......@@ -229,26 +229,25 @@ class RawSolution(object):
"""
extract active __inputs and clocks from a state vector
"""
# Old API
#return [s_varcode for s_varcode in s_vector
# if s_varcode > 0
# and s_varcode in self.__unfolder.get_inputs_and_free_clocks()]
inputs = frozenset(self.__unfolder.get_inputs())
free_clocks = frozenset(self.__unfolder.get_free_clocks())
return [s_varcode for s_varcode in s_vector
if (s_varcode > 0)
and ((s_varcode in inputs)
or (s_varcode in free_clocks))]
return tuple(self.__unfolder.get_inputs_and_free_clocks() & frozenset(s_vector))
def extract_act_input_clock_seq(self):
"""
Extract the sequence of activated __inputs and clocks in the solution sol
@return: list<list<int>> list of input vector
@old return: list<list<int>> list of input vector
@return: tuple<tuple<int>> list of input vector
"""
return [] \
if (len(self.__unfolder.get_inputs()) == 0) and (len(self.__unfolder.get_free_clocks()) == 0) \
else [self.extract_act_inputs_clocks(xic)
for xic in self.unflatten()] # list of lists
return tuple() \
if not self.__unfolder.get_inputs() and not self.__unfolder.get_free_clocks() \
else tuple(self.extract_act_inputs_clocks(xic)
for xic in self.unflatten()) # list of lists
def __str__(self):
"""
......
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