RedStatesFound.clear();coregraph.pairsAndScores.clear();
currentExplorationBoundary.addAll(reds);
if (coregraph.additionalExplorationRoot != null) currentExplorationBoundary.addAll(coregraph.additionalExplorationRoot);
while(!currentExplorationBoundary.isEmpty())
{
CmpVertex currentRed = currentExplorationBoundary.remove();
Collection<Entry<Label,CmpVertex>> surrounding = decisionProcedure == null?null:decisionProcedure.getSurroundingTransitions(currentRed);
if (surrounding == null) surrounding = coregraph.transitionMatrix.get(currentRed).entrySet();
for(Entry<Label,CmpVertex> BlueEntry:surrounding)
if (BlueEntry.getValue().getColour() == null ||
BlueEntry.getValue().getColour() == JUConstants.BLUE)
{// the next vertex is not marked red, hence it has to become blue
CmpVertex currentBlueState = BlueEntry.getValue();
int numberOfCompatiblePairs = 0;
for(CmpVertex oldRed:reds)
{
PairScore pair = obtainPair(currentBlueState,oldRed,decisionProcedure);
if (pair.getScore() >= coregraph.config.getGeneralisationThreshold())
{
coregraph.pairsAndScores.add(pair);
++numberOfCompatiblePairs;
if (GlobalConfiguration.getConfiguration().isAssertEnabled() && coregraph.config.getDebugMode()) PathRoutines.checkPTAConsistency(coregraph, currentBlueState);
}
}
if (numberOfCompatiblePairs == 0)
RedStatesFound.add(currentBlueState);
// This node is current a blue node and remains blue until I decide which of the currently potentially red nodes become red.
currentBlueState.setColour(JUConstants.BLUE);
}
}
// Now that we have a collection of all potentially red vertices, pick one to make red and then then check if others can remain blue.
CmpVertex newRedNode = null;
if (!RedStatesFound.isEmpty())
{
if (RedStatesFound.size() > 1 && decisionProcedure != null)
newRedNode = decisionProcedure.selectRedNode(coregraph, reds, RedStatesFound);
else
newRedNode = RedStatesFound.iterator().next();
// mark this blue node as red and rebuild a collection of blue and potentially red states.
newRedNode.setColour(JUConstants.RED);
reds.add(newRedNode);
}
else
if (!coregraph.pairsAndScores.isEmpty() && decisionProcedure != null)
{// the pairs chosen so far might all be the wrong ones, hence we could attempt to avoid the disaster if we can do something clever and whoever registered a decision procedure is given a chance to do it.
newRedNode = decisionProcedure.resolvePotentialDeadEnd(coregraph, reds, coregraph.pairsAndScores);
if (newRedNode != null)
{
newRedNode.setColour(JUConstants.RED);
reds.add(newRedNode);RedStatesFound.add(newRedNode);
}
}
}
while(!RedStatesFound.isEmpty());