+ // This method checks whether a choice is reachable in the VOD graph from a reference choice
+ // This is a BFS search
+ private boolean isReachableInVODGraph(int checkedChoice, int referenceChoice) {
+ // Record visited choices as we search in the graph
+ HashSet<Integer> visitedChoice = new HashSet<>();
+ visitedChoice.add(referenceChoice);
+ LinkedList<Integer> nodesToVisit = new LinkedList<>();
+ // If the state doesn't advance as the threads/sub-programs are executed (basically there is no new state),
+ // there is a chance that the graph doesn't have new nodes---thus this check will return a null.
+ if (vodGraphMap.containsKey(referenceChoice)) {
+ nodesToVisit.addAll(vodGraphMap.get(referenceChoice));
+ while(!nodesToVisit.isEmpty()) {
+ int currChoice = nodesToVisit.getFirst();
+ if (currChoice == checkedChoice) {
+ return true;
+ }
+ if (visitedChoice.contains(currChoice)) {
+ // If there is a loop then we don't find it
+ return false;
+ }
+ // Continue searching
+ visitedChoice.add(currChoice);
+ HashSet<Integer> currChoiceNextNodes = vodGraphMap.get(currChoice);
+ if (currChoiceNextNodes != null) {
+ // Add only if there is a mapping for next nodes
+ for (Integer nextNode : currChoiceNextNodes) {
+ nodesToVisit.addLast(nextNode);
+ }
+ }
+ }
+ }
+ return false;
+ }
+