List<StatePair> pairsToMerge = new LinkedList<StatePair>();
for(Entry<CmpVertex,Map<Label,CmpVertex>> entry:merged.transitionMatrix.entrySet())
for(Entry<Label,CmpVertex> transition:entry.getValue().entrySet())
if (merged.transitionMatrix.get(transition.getValue()).containsKey(transition.getKey()))
{// we have a potential loop
PairScore p = new PairScore(entry.getKey(),transition.getValue(),0,0);
ArrayList<PairScore> pairOfInterest = new ArrayList<PairScore>(1);pairOfInterest.add(p);
List<PairScore> correctPairs = new ArrayList<PairScore>(1), wrongPairs = new ArrayList<PairScore>(1);
SplitSetOfPairsIntoRightAndWrong(graph, referenceGraph, pairOfInterest, correctPairs, wrongPairs);
verticesToMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
long genScore = graph.pairscores.computePairCompatibilityScore_general(p, null, verticesToMerge);
LearnerGraph mergedForThisPair = MergeStates.mergeCollectionOfVertices(graph, null, verticesToMerge);
long value = MarkovUniversalLearner.computeInconsistency(mergedForThisPair, directionForwardOrInverse, m, checker,false);
boolean decidedToMerge= (value == 0 && genScore >= genScoreThreshold);
if (decidedToMerge)
{
pairsToMerge.add(p);
++nrOfMergers;
}
if ( !wrongPairs.isEmpty() && decidedToMerge)
//(wrongPairs.isEmpty() && value > 0 || genScore < genScoreThreshold) || (!wrongPairs.isEmpty() && value == 0 && genScore >= genScoreThreshold))
{
System.out.println( p.toString()+(wrongPairs.isEmpty()?"valid, ":"invalid:")+value+ "(score "+genScore+")");
System.out.println( "R: " + graph.transitionMatrix.get(p.getR())+" B: "+graph.transitionMatrix.get(p.getQ()));
}
}
//System.out.println("mergers identified: "+nrOfMergers);
/*
long genScore = graph.pairscores.computePairCompatibilityScore_general(null, pairsToMerge, verticesToMerge);