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

[lib] MCLAnalyser: optimize forbidden solutions; optimize calculation of inact frontiers

parent 57e85c7b
......@@ -219,9 +219,14 @@ class MCLAnalyser(object):
@precondition: fsolution is a frontier solution for the query
"""
# Collect inactivated frontier places
### TODO: avoir un attribut non pas pour toutes les frontieres mais juste celles inactives
# OLD:
# final_dsol = [[var] for var in fsolution.frontier_values if var < 0]
# Intersection between pre-computed negative values for all frontiers
# and all frontiers (negative and positive) in the given solution
final_dsol = \
[[var] for var in fsolution.frontier_values if var < 0]
[[var] for var in
self.unfolder.frontiers_negative_values & fsolution.frontier_values]
# Prepend inactivated frontier places as a start property in DIMACS form
if query.dim_start:
query.dim_start = final_dsol + query.dim_start
......@@ -467,6 +472,7 @@ class MCLAnalyser(object):
# list of timed minimal activation conditions on frontier (dimacs code)
# i.e list<DimacsFrontierSol>
mac_list = []
forbidden_frontier_values = []
reachable = self.sq_is_satisfiable(query, max_step)
print("reachable ?", reachable)
......@@ -476,24 +482,15 @@ class MCLAnalyser(object):
query.set_steps_before_reach(min_step)
while reachable:
# compute forbidden solutions: already discovered macs
# Ban all sets of activated frontiers (1 set = 1 sol)
# Forbidden solutions: already discovered macs (see at the end of the while loop)
# Ban all sets of activated frontiers (1 set = 1 solution)
# Equivalent of wrapping each previous solution with a logical OR:
# OR( not (frontier places))
## TODO: check in unfolder: dim_start elements joined by OR or AND operator ?
print("forbidden_frontier_values", forbidden_frontier_values)
####TODO: optimiser pr éviter de refaire la négation de toutes les macs à chaque fois
### garder en mémoire le résultat précédent
####Yield le résultat à chaque fois
forbidden_sol = \
[
# Get all activated frontiers in each DimacsFrontierSol
[-var for var in dimacs_front_sol.activated_frontier_values]
for dimacs_front_sol in mac_list
]
print("forbidden sol", forbidden_sol)
query.dim_start = forbidden_sol
## equivaut à mettre à jour le start_prop ou __initial_property avec l'ancienne méthode ??
query.dim_start = forbidden_frontier_values
## TODO: equivaut à mettre à jour le start_prop ou __initial_property avec l'ancienne méthode ??
## si non, faudrait ptetre éviter de recompiler ça à chaque fois dans __init_initial_constraint_0
#### redondance code next_mac()
# Solutions differ on frontiers: Search only 2 different solutions
......@@ -520,8 +517,13 @@ class MCLAnalyser(object):
else:
yield current_mac
mac_list.append(current_mac)
# Return all macs found
#return tuple(mac_list)
# Keep a list of frontier values to be banned in the next search
# - Get all activated frontiers on the current DimacsFrontierSol
# - Build a list of their opposite values
forbidden_frontier_values.append(
[-var for var in current_mac.activated_frontier_values]
)
def next_mac(self, query, max_step):
......
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