// We are checking which of these two has happened in the code below.
// The computation below is expensive on large graphs but only needs to be done once.
LinkedHashSet<CmpVertex> removedStates = new LinkedHashSet<CmpVertex>();removedStates.addAll(original.transitionMatrix.keySet());
removedStates.removeAll(outcome.transitionMatrix.keySet());removedStates.remove(pair.getQ());removedStates.remove(pair.getR());
Assert.assertEquals(1,removedStates.size());// if it were a phantom vertex, there would only be one of them.
CmpVertex tentativePhantom = removedStates.iterator().next();
Set<Label> alphabetUsedOnPhantom = new TreeSet<Label>();alphabetUsedOnPhantom.addAll(original.pathroutines.computeAlphabet());
for(Entry<Label,CmpVertex> transition:original.transitionMatrix.get(tentativePhantom).entrySet())
{
Assert.assertSame(tentativePhantom,transition.getValue());alphabetUsedOnPhantom.remove(transition.getKey());
}
Assert.assertEquals(0, alphabetUsedOnPhantom.size());
extraPhantomVertices = 1;// now certain it was indeed a phantom vertex added when the PTA was initially built.
}
Assert.assertEquals(score+extraPhantomVertices,original.getStateNumber()-outcome.getStateNumber());
}
ScoreMode origScore = original.config.getLearnerScoreMode();original.config.setLearnerScoreMode(ScoreMode.COMPATIBILITY);
long compatibilityScore = original.pairscores.computePairCompatibilityScore(pair);
original.config.setLearnerScoreMode(origScore);
Assert.assertEquals(compatibilityScore+1+extraPhantomVertices,original.getStateNumber()-outcome.getStateNumber());
return outcome;
}
@Override
public Stack<PairScore> ChooseStatePairs(LearnerGraph graph)
{
Stack<PairScore> outcome = graph.pairscores.chooseStatePairs(new PairScoreComputation.RedNodeSelectionProcedure(){
@Override
public CmpVertex selectRedNode(LearnerGraph coregraph, @SuppressWarnings("unused") Collection<CmpVertex> reds, Collection<CmpVertex> tentativeRedNodes)
{
CmpVertex redVertex = null;
if (listOfPairsToWrite != null)
{
redVertex = tentativeRedNodes.iterator().next();
listOfPairsToWrite.add(new PairOfPaths(coregraph, new PairScore(null, redVertex, 0, 0)));
}