Commit 575ffa3d authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[lib] MCLSolutions: Improve extract_activated_frontier_values() by caching...

[lib] MCLSolutions: Improve extract_activated_frontier_values() by caching result of frontier_pos_and_neg_values()
parent 8e0da86e
......@@ -158,7 +158,7 @@ class CLUnfolder(object):
# operations with sets are much faster
## plus forcément nécessaire... ou passer avec une @property et un lrucache dessus
## ou mieux juste un attr avec les frontières négatives,
## utilisé dans RawSolution.extract_frontier_values() avec l'union des frontieres positives self.frontier_values
## utilisé dans RawSolution.frontier_pos_and_neg_values pour faire l'intersection avec les variables d'une solution
## utilisé dans MCLAnalyser.__solve_with_inact_fsolution directement en utilisant l'objet unfolder
self.frontiers_negative_values = frozenset(-frontier for frontier in self.frontier_values)
self.frontiers_pos_and_neg = \
......@@ -171,7 +171,7 @@ class CLUnfolder(object):
self.__free_clocks = frozenset(self.__var_code_table[fcl] for fcl in self.dynamic_system.free_clocks)
# Binding for a merged version of __inputs and __free_clocks
# Convenient attribute for RawSolution.extract_frontier_values()
# Convenient attribute for RawSolution.extract_act_input_clock_seq()
# DIMACS codes of the input and free_clocks variables
self.inputs_and_free_clocks = self.__inputs | self.__free_clocks
......
......@@ -45,6 +45,8 @@ Various solution representations
# Standard imports
from __future__ import print_function
import itertools as it
#from functools import cached_property
from cached_property import cached_property
from cadbiom import commons as cm
......@@ -74,9 +76,9 @@ class RawSolution(object):
In addition to the solution in DIMACS form (including values for auxiliary
variables), a RawSolution object registers data which permit information
extraction from these raw solutions. The most important methods are:
extraction from these raw solutions. The most important methods/attributes are:
- extract_frontier_values():
- frontier_pos_and_neg_values:
Extracts the frontier values from the solution.
These values are in DIMACS code.
......@@ -204,19 +206,28 @@ class RawSolution(object):
:rtype: <set>
"""
if self.shift_direction == 'FORWARD':
# All frontiers and their opposite version Union
# Set of frontier positive and negative values.
return frozenset(self.unfolder.frontier_values) & frozenset(self.solution)
# frontier_values: Set of frontier positive values only.
## TODO: recherche quelques places parmi des centaines de milliers
## voir si les places qui nous intéressent ne seraient pas dans les premieres shift_step places
return frozenset(self.unfolder.frontier_values) & self.frontier_pos_and_neg_values
else:
NotImplementedError("BACKWARD shift direction is not yet implemented")
def extract_frontier_values(self):
@cached_property
def frontier_pos_and_neg_values(self):
"""Extracts the frontier values from the solution.
These values are in DIMACS code.
..warning:: This function returns values of active AND inactive frontiers.
.. warning:: This function returns values of active AND inactive frontiers.
.. warning:: Assert: solution is sorted by variable code
..warning:: Assert: solution is sorted by variable code
.. note:: This function makes set operations between all values of
frontiers and the current solution.
This last one is a list of hundreds of thousands items
(ex: ~500000 for a solution with 10 steps).
Thus, the operation is costly and we use a decorator @cached_property
to put the result in cache.
.. note::
frontiers (fixed size): 3824
......@@ -618,9 +629,8 @@ class DimacsFrontierSol(object):
:type raw_sol: <RawSolution>
"""
# Frontier places
###TODO: ESt-ce judicieux de se baser sur les états de TOUTES LES places
### au lieu de juste les places activées...
self.frontier_values = frozenset(raw_sol.extract_frontier_values()) #### DEJA un frozen set
#### DEJA un frozen set
self.frontier_values = frozenset(raw_sol.frontier_pos_and_neg_values)
# Activated input/events (clocks)
# (may be empty if data-flow model is without input)
......
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