+ private void resetStatesForNewExecution(IntChoiceFromSet icsCG) {
+ if (choices == null || choices != icsCG.getAllChoices()) {
+ // Reset state variables
+ choiceCounter = 0;
+ choices = icsCG.getAllChoices();
+ refChoices = copyChoices(choices);
+ // Clearing data structures
+ backtrackMap.clear();
+ conflictPairMap.clear();
+ readWriteFieldsMap.clear();
+ stateToEventMap.clear();
+ isEndOfExecution = false;
+ }
+ }
+
+ private IntChoiceFromSet 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);
+ }
+ return backtrackCG;
+ }
+
+ 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);
+ }
+// activeBacktrackCGs.addAll(cgMap.values());
+ isFirstResetDone = true;
+ } else {
+ // Check if we still have backtrack points for the current CG
+ int currStateId = icsCG.getStateId();
+ if (backtrackMap.containsKey(currStateId)) {
+ setBacktrackCG(currStateId);
+ } else {
+// activeBacktrackCGs.remove(icsCG);
+ // 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();
+ IntChoiceFromSet backtrackCG = setBacktrackCG(hiStateId);
+// activeBacktrackCGs.add(backtrackCG);
+ }
+ }
+ }
+ // Clear unused CGs
+ for(IntChoiceFromSet cg : cgList) {
+ if (!backtrackCGs.contains(cg)) {
+ cg.setDone();
+ }
+ }
+ cgList.clear();
+ }
+