Commit 15b4017a authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Improve extract_frontier_values(): pythonic code, limit func calls

parent 2f783745
......@@ -157,22 +157,40 @@ class RawSolution(object):
@return: a dimacs code list of the activation state on the frontier for sol
"""
jmax = len(self.__unfolder.get_frontier())
fsol = []
# Old API
# jmax = len(self.__unfolder.get_frontier())
# fsol = []
# j = 0
# dec = self.__shift_step * self.__current_step
# sol = self.__solution
# for i in range(len(sol)):
# # the variable is frontier var:
# if abs(sol[i]) == self.__unfolder.get_frontier()[j]:
# if self.__shift_direction == "FORWARD":
# fsol.append(sol[i])
# else:
# fsol.append(sol[i+dec]) # look for initial values
# j += 1
# if j == jmax:
# return fsol
# return fsol # never reach this point
frontiers = self.__unfolder.get_frontier()
jmax = len(frontiers)
fsol = list()
j = 0
sol = self.__solution
dec = self.__shift_step * self.__current_step
for i in range(len(sol)):
for i, sol in enumerate(self.__solution):
# the variable is frontier var:
if abs(sol[i]) == self.__unfolder.get_frontier()[j]:
if abs(sol) == frontiers[j]:
if self.__shift_direction == "FORWARD":
fsol.append(sol[i])
fsol.append(self.__solution[i])
else:
fsol.append(sol[i+dec]) # look for initial values
fsol.append(self.__solution[i+dec])# look for initial values
j += 1
if j == jmax:
return fsol
return fsol # never reach this point
def extract_act_frontier_values(self, sol):
......
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