Skip to content

Commit

Permalink
#18 Handle deciding fixed elements where there are not enough element…
Browse files Browse the repository at this point in the history
…s to dup
  • Loading branch information
alexcere committed Jan 6, 2025
1 parent fa6b16a commit 0f714d2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/greedy/greedy_new_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,12 +1002,14 @@ def decide_fixed_elements(self, cstate: SymbolicState, instr: instr_JSON_T) -> T

# Last case: if there is no better alternative, we just consider whether to consider the first element to
# be swapped with the first element to consume
if best_idx == cstate.positive_idx2negative(-1):
if len(cstate.stack) > 0 and best_idx == cstate.positive_idx2negative(-1):
elements_to_dup = cstate.elements_to_dup()

# There are not enough elements to duplicate and swap. Hence, we need to reuse some of them
if len(input_vars) > elements_to_dup:
return 0, cstate.positive_idx2negative(len(input_vars) - elements_to_dup)
self.debug_logger.debug_message(f"{len(input_vars) - elements_to_dup} {cstate.max_solved - 1}")
return 0, cstate.positive_idx2negative(min(len(input_vars) - elements_to_dup, cstate.max_solved - 1,
len(cstate.stack) - 1))

# If I need to swap one of the arguments, I take the first element
if len(input_vars) > 0 and cstate.stack_var_copies_needed[input_vars[-1]] == 0 \
Expand Down

0 comments on commit 0f714d2

Please sign in to comment.