+ private boolean isTraceConstructed(Integer[] choiceList, IntChoiceFromSet backtrackCG) {
+ // Concatenate state ID and trace in a string, e.g., "1:10234"
+ int stateId = backtrackCG.getStateId();
+ StringBuilder sb = new StringBuilder();
+ sb.append(stateId);
+ sb.append(':');
+ for(Integer choice : choiceList) {
+ sb.append(choice);
+ }
+ // Check if the trace has been constructed as a backtrack point for this state
+ if (doneBacktrackSet.contains(sb.toString())) {
+ return true;
+ }
+ doneBacktrackSet.add(sb.toString());
+ return false;
+ }
+
+ private void resetStatesForNewExecution(IntChoiceFromSet icsCG) {
+ if (choices == null || choices != icsCG.getAllChoices()) {
+ // Reset state variables
+ choiceCounter = 0;
+ choices = icsCG.getAllChoices();
+ refChoices = copyChoices(choices);
+ lastCGStateId = icsCG.getStateId();
+ // Clearing data structures
+ conflictPairMap.clear();
+ readWriteFieldsMap.clear();
+ stateToEventMap.clear();
+ isEndOfExecution = false;
+ // Adding this CG as the first CG for this execution
+ cgList.add(icsCG);
+ }
+ }
+
+ private void setBacktrackCG(int stateId) {
+ // Set a backtrack CG based on a state ID
+ IntChoiceFromSet backtrackCG = cgMap.get(stateId);
+ LinkedList<Integer[]> backtrackChoices = backtrackMap.get(stateId);
+ backtrackCG.setNewValues(backtrackChoices.removeLast()); // Get the last from the queue
+ backtrackCG.reset();
+ // Remove from the queue if we don't have more backtrack points for that state
+ if (backtrackChoices.isEmpty()) {
+ cgMap.remove(stateId);
+ backtrackMap.remove(stateId);
+ backtrackStateQ.remove(stateId);
+ }
+ }
+
+ private void setNextBacktrackPoint(IntChoiceFromSet icsCG) {
+
+ HashSet<IntChoiceFromSet> backtrackCGs = new HashSet<>(cgMap.values());
+ if (!isFirstResetDone) {
+ // Reset the last CG of every LinkedList in the map and set done everything else
+ for (Integer stateId : cgMap.keySet()) {
+ setBacktrackCG(stateId);
+ }
+ isFirstResetDone = true;
+ } else {
+ // Check if we still have backtrack points for the last state after the last backtrack
+ if (backtrackMap.containsKey(lastCGStateId)) {
+ setBacktrackCG(lastCGStateId);
+ } else {
+ // We try to reset new CGs (if we do have) when we are running out of active CGs
+ if (!backtrackStateQ.isEmpty()) {
+ // Reset the next CG with the latest state
+ int hiStateId = backtrackStateQ.peek();
+ setBacktrackCG(hiStateId);
+ }
+ }
+ }
+ // Clear unused CGs
+ for(IntChoiceFromSet cg : cgList) {
+ if (!backtrackCGs.contains(cg)) {
+ cg.setDone();
+ }
+ }
+ cgList.clear();
+ }
+