From 0f714d23708c9263092eebb7a9668d1fa93c9301 Mon Sep 17 00:00:00 2001 From: alexcere <48130030+alexcere@users.noreply.github.com> Date: Mon, 6 Jan 2025 17:21:45 +0100 Subject: [PATCH] #18 Handle deciding fixed elements where there are not enough elements to dup --- src/greedy/greedy_new_version.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/greedy/greedy_new_version.py b/src/greedy/greedy_new_version.py index 1968ff45..d271a3ad 100644 --- a/src/greedy/greedy_new_version.py +++ b/src/greedy/greedy_new_version.py @@ -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 \