Queue<StatePair> currentExplorationBoundary = new LinkedList<StatePair>();// FIFO queue
currentExplorationBoundary.add(pair);currentExplorationBoundary.offer(null);
while(!currentExplorationBoundary.isEmpty())
{
StatePair currentPair = currentExplorationBoundary.remove();
if (currentPair == null)
{// we got to the end of a wave
if (currentExplorationBoundary.isEmpty())
break;// we are at the end of the last wave, stop looping.
// mark the end of a wave.
currentExplorationBoundary.offer(null);
}
else
{
Map<Label,CmpVertex> targetRed = graph.transitionMatrix.get(currentPair.getR()),
targetBlue = graph.transitionMatrix.get(currentPair.getQ());
for(Entry<Label,CmpVertex> redEntry:targetRed.entrySet())
{
CmpVertex nextBlueState = targetBlue.get(redEntry.getKey());
if (nextBlueState != null)
{// both states can make a transition
if (!AbstractLearnerGraph.checkCompatible(redEntry.getValue(),nextBlueState,graph.pairCompatibility))
return -1;// incompatible states
List<Label> outgoing_form_blue_node = new ArrayList<Label>(graph.transitionMatrix.get(currentPair.getQ()).keySet());
List<Label> outgoing_form_red_node = new ArrayList<Label>(graph.transitionMatrix.get(currentPair.getR()).keySet());
List<Label> exoutgoing_form_blue_node = new ArrayList<Label>(extension_model.transitionMatrix.get(currentPair.getQ()).keySet());
List<Label> exoutgoing_form_red_node = new ArrayList<Label>(extension_model.transitionMatrix.get(currentPair.getR()).keySet());
Set<Label> all_outgoing = new HashSet<Label>() ;
all_outgoing.addAll(exoutgoing_form_blue_node);
all_outgoing.addAll(exoutgoing_form_red_node);
for(Label out_red:outgoing_form_red_node)
{
Boolean target_from_red_acceptance = graph.getTransitionMatrix().get(currentPair.getR()).get(out_red).isAccept();
if(outgoing_form_blue_node.contains(out_red))
{
Boolean target_form_blue_acceptance = graph.getTransitionMatrix().get(currentPair.getQ()).get(out_red).isAccept();
assert target_from_red_acceptance!=null; assert target_form_blue_acceptance!=null;
if(target_form_blue_acceptance == target_from_red_acceptance )
matchscore++;
else
return -1;
}
else if(exoutgoing_form_blue_node.contains(out_red) && target_from_red_acceptance.booleanValue())
{
Boolean extensiontarget_form_blue_acceptance = extension_model.getTransitionMatrix().get(currentPair.getQ()).get(out_red).isAccept();
if(extensiontarget_form_blue_acceptance == true && target_from_red_acceptance==true )
matchscore++;
}
else
{
return -1;
}
}
for(Label out_blue:outgoing_form_blue_node)
{
Boolean target_form_blue_acceptance = graph.getTransitionMatrix().get(currentPair.getQ()).get(out_blue).isAccept();
if(exoutgoing_form_red_node.contains(out_blue) && target_form_blue_acceptance.booleanValue())
{
Boolean extensiontarget_form_red_acceptance = extension_model.getTransitionMatrix().get(currentPair.getR()).get(out_blue).isAccept();
if(extensiontarget_form_red_acceptance == true && target_form_blue_acceptance ==true )
matchscore++;
}
else
{
return -1;
}
}
StatePair nextStatePair = new StatePair(nextBlueState,redEntry.getValue());
currentExplorationBoundary.offer(nextStatePair);
}
// if the red can make a move, but the blue one cannot, ignore this case.
}