Configuration gdConfig = a.config.copy();gdConfig.setGdFailOnDuplicateNames(false);gdConfig.setTransitionMatrixImplType(STATETREE.STATETREE_SLOWTREE);
init(a,b, threads,gdConfig);
identifyKeyPairs();
final List<PairScore> initialKeyPairs = new LinkedList<PairScore>();initialKeyPairs.addAll(frontWave);
final Map<VertID,VertID> oldVerticesToNew = new TreeMap<VertID,VertID>();
final LearnerGraphND outcome = new LearnerGraphND(a,gdConfig);outcome.setName(outcome.getName()+"_diff");
final LearnerGraphMutator<List<CmpVertex>,LearnerGraphNDCachedData> mutator =
new LearnerGraphMutator<List<CmpVertex>,LearnerGraphNDCachedData>(outcome,gdConfig,null);
final EdgeAnnotation transitionAnnotation = new EdgeAnnotation();
final Map<StatePair,TransitionChanges> pairToNumberOfChanges = new TreeMap<StatePair,TransitionChanges>();
for(Entry<CmpVertex,Map<Label,TARGET_A_TYPE>> entry:a.transitionMatrix.entrySet())
for(Entry<Label,TARGET_A_TYPE> transition:entry.getValue().entrySet())
for(CmpVertex target:a.getTargets(transition.getValue()))
{
TransitionChanges changes = pairToNumberOfChanges.get(new StatePair(entry.getKey(), target));
if (changes == null)
{
changes = new TransitionChanges();pairToNumberOfChanges.put(new StatePair(entry.getKey(), target),changes);
}
changes.orig++;// we populate our map with the existing transitions
}
makeSteps();
computeDifference(new PatchGraph() {
protected Label copyVertexWithPrefix(String prefix, Label origLabel)
{
Label result = null;
if (origLabel instanceof StringLabel)
result = new StringLabel(prefix+origLabel);
else
if (origLabel instanceof ErlangLabel)
{
ErlangLabel oErl = (ErlangLabel)origLabel;
result = new ErlangLabel(oErl.function,prefix+oErl.callName,
oErl.input, oErl.expectedOutput);
}
else
assert false;
return result;
}
@Override
public void addTransition(CmpVertex from, Label origLabel, CmpVertex to)
{
Label label = copyVertexWithPrefix("ADD_",origLabel);
mutator.addTransition(from, label, to);
TransitionChanges changes = pairToNumberOfChanges.get(new StatePair(from,to));
if (changes == null)
{
changes = new TransitionChanges();pairToNumberOfChanges.put(new StatePair(from,to),changes);
}
changes.added++;
}
@Override
public void removeTransition(CmpVertex from, Label origLabel, CmpVertex to)
{
Label label = copyVertexWithPrefix("REM_",origLabel);
mutator.removeTransition(from, origLabel, to);// remove the original transition
mutator.addTransition(from, label, to);// and add the renamed one
TransitionChanges changes = pairToNumberOfChanges.get(new StatePair(from,to));
if (changes == null)
{
changes = new TransitionChanges();pairToNumberOfChanges.put(new StatePair(from,to),changes);
}
changes.removed++;
}
@Override
public void setInitial(CmpVertex vertex)
{
mutator.setInitial(vertex);
}
@Override
public void addToCompatibility(@SuppressWarnings("unused") CmpVertex astate,
@SuppressWarnings("unused") CmpVertex bstate, @SuppressWarnings("unused") JUConstants.PAIRCOMPATIBILITY value) {
// does not do anything
}
@Override
public void addRelabelling(VertID astate, VertID bstate) {
renameVertex(astate, "["+bstate+"] ",oldVerticesToNew);
}
@Override
public void addVertex(CmpVertex vertex) {
mutator.addNewVertex(vertex);
}
@SuppressWarnings("unused")
@Override
public void removeFromCompatibility(CmpVertex astate, CmpVertex bstate, JUConstants.PAIRCOMPATIBILITY value) {
// does not do anything
}
});
for(Entry<StatePair,TransitionChanges> pc:pairToNumberOfChanges.entrySet())
{
CmpVertex from = pc.getKey().getQ(), to = pc.getKey().getR();
Map<Label,Map<String,Color>> lbl = transitionAnnotation.get(from.getStringId());
if (lbl == null)
{
lbl = new TreeMap<Label,Map<String,Color>>();transitionAnnotation.put(from.getStringId(), lbl);
}
for(Entry<Label,List<CmpVertex>> transition:outcome.transitionMatrix.get(from).entrySet())
for(CmpVertex target:outcome.getTargets(transition.getValue()))
if (to.equals(target))
{
Map<String,Color> targetToColour = lbl.get(transition.getKey());
if (targetToColour == null)
{// this is the first annotation for the specific target state