Skip to content

Commit

Permalink
Handle special case in solve permutation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcere committed Oct 16, 2024
1 parent 4dcb40f commit b85ade7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/greedy/greedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,10 @@ def solve_permutation(self, cstack: List[var_T], solved: List[int]):
assert (cstack.count(e) == self._final_stack.count(e))
assert (0 in solved)
i = 1
while i < len(cstack) - 1 and i in solved:

# If the element is equal to the topmost, it enters an infinite loop.
# Hence, we need to add an extra condition to ensure we don't choose the same element
while i < len(cstack) - 1 and (i in solved or cstack[0] == cstack[i]):
i += 1
# print(i,cstack,self._final_stack,solved)
assert (i not in solved)
Expand Down

0 comments on commit b85ade7

Please sign in to comment.