Package statechum.analysis.learning

Examples of statechum.analysis.learning.StatePair


      {
        CmpVertex prevVertex = null;
        for(CmpVertex v:vertices)
        {
          if (prevVertex != null)
            pairsList.add(new StatePair(prevVertex,v));
          prevVertex = v;
        }
      }
      for(Collection<CmpVertex> vertices:labelFromStates.values())
      {
        CmpVertex prevVertex = null;
        for(CmpVertex v:vertices)
        {
          if (prevVertex != null)
            pairsList.add(new StatePair(prevVertex,v));
          prevVertex = v;
        }
      }
      /*
      LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> verticesToMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
View Full Code Here


    CmpVertex newA = Transform322.addToGraph(fsm, fsmToAdd,oldToNew);

    Assert.assertNull(checkM(fsmSrc,fsmSrc.init, fsm,fsm.init));
    Assert.assertNull(checkM(fsmToAdd,fsmToAdd.init,fsm,newA));
   
    StatePair whatToMerge = new StatePair(fsm.init,newA);
    LinkedList<Collection<CmpVertex>> collectionOfVerticesToMerge = new LinkedList<Collection<CmpVertex>>();
    Assert.assertTrue(0 < fsm.pairscores.computePairCompatibilityScore_general(whatToMerge,collectionOfVerticesToMerge));
    LearnerGraph result = MergeStates.mergeAndDeterminize_general(fsm, whatToMerge,collectionOfVerticesToMerge);
    Assert.assertNull(checkM(fsmSrc,fsmSrc.init,result,result.init));
View Full Code Here

    return result;   
  }
 
  public PairScore obtainPair(CmpVertex blue, CmpVertex red, ScoreComputationCallback scoreComputationOverride)
  {
    long computedScore = -1, compatibilityScore =-1;StatePair pairToComputeFrom = new StatePair(blue,red);
    if (coregraph.config.getLearnerScoreMode() == Configuration.ScoreMode.COMPATIBILITY)
    {
      computedScore = computePairCompatibilityScore(pairToComputeFrom);compatibilityScore=computedScore;
    }
    else   
View Full Code Here

    Queue<Boolean> currentRedFromPta = new LinkedList<Boolean>();// FIFO queue containing true if the red node comes from a branch of a PTA which has been previously already merged into the machine
    currentExplorationBoundary.add(origPair);currentRedFromPta.add(false);
   
    while(!currentExplorationBoundary.isEmpty())
    {
      StatePair currentPair = currentExplorationBoundary.remove();Boolean redFromPta = currentRedFromPta.remove();
      boolean RedAndBlueToBeMerged = false;// this one is set to true if states in the current pair have to be merged.
      // This will be so for all state pairs where a blue node can
      // make moves which the red one cannot match. The term "merged" does not refer to whether
      // two nodes are actually merged - they have to be anyway, however if there are sequences of
      // nodes with identical moves, PTA nodes do not contribute to anything - we only need
      // to consider those which branch. mergedVertices is only updated when we find a blue vertex which
      // can accept input a red node cannot accept.

      if (!AbstractLearnerGraph.checkCompatible(currentPair.getQ(),currentPair.getR(),coregraph.pairCompatibility))
        return -1;// incompatible states
      if (!redFromPta.booleanValue())
        ++score;
      Map<Label,CmpVertex> targetBlue = coregraph.transitionMatrix.get(currentPair.getQ());

      for(Entry<Label,CmpVertex> blueEntry:targetBlue.entrySet())
      {
        CmpVertex nextRedState = coregraph.transitionMatrix.get(currentPair.getR()).get(blueEntry.getKey());
        if (nextRedState != null)
        {// both states can make a transition - this would be the case of "non-determinism" for Merge&Determinize
          boolean newRedFromPta = redFromPta;
         
          // PTA does not have loops, but the original automaton has
          // and one of those loops is not on the transition diagram, namely the one related to B=A
          if (nextRedState == origPair.getQ())
          {
            nextRedState = origPair.getR(); // emulates the new loop
            newRedFromPta = coregraph.config.getLearnerScoreMode() != Configuration.ScoreMode.COMPATIBILITY; // and since the original score computation algorithm cannot do this, we pretend to be unable to do this either
            // The problem is that since we effectively merge the
            // states at this point, a loop introduced by merging
            // adjacent states may suck many PTA states into it,
            // so that two transitions which would not normally be
            // near each other will be merged. For this reason, it
            // is possible that our score computation will deliver
            // a higher value that the conventional matching
            // (where in the considered situation we'll be
            // matching PTA with itself and PTA may be sparse).
          }

          if (coregraph.config.getScoreCompatibilityScoreComputationBugEmulation())
            redFromPta = newRedFromPta;
          StatePair nextStatePair = new StatePair(blueEntry.getValue(),nextRedState);
          currentExplorationBoundary.offer(nextStatePair);currentRedFromPta.offer(newRedFromPta);
        }
        else
        {// the current red state cannot make a transition, perhaps PTA states associated with it can
          nextRedState = findNextRed(mergedVertices,currentPair.getR(),blueEntry.getKey());
          if (nextRedState != null)
          {// both states can make a transition - this would be the case of "non-determinism" for Merge&Determinize
           // The red state is the one originally from a previously-merged PTA branch, so here we are merging PTA with itself.

            // Since we are merging PTA with itself and PTA does not have loops, we cannot reenter the original blue state. Moreover,
            // since we called findNextRed, we are looking at transitions from the PTA states. For this reason, we cannot enter the
            // blue state since PTA does not have loops.
            assert nextRedState != origPair.getQ() : "inconsistent PTA";
           
            StatePair nextStatePair = new StatePair(blueEntry.getValue(),nextRedState);
            currentExplorationBoundary.offer(nextStatePair);currentRedFromPta.offer(coregraph.config.getLearnerScoreMode() != Configuration.ScoreMode.COMPATIBILITY);// from now on, no increments to the score
          }
          else
          {
            // If the blue can make a move, but the red one cannot, it means that the blue vertex has
View Full Code Here

              int firstEqNumber = firstEquivalenceClass.getNumber();*/
              int i=1;
              while(i<targets.size()) // here we benefit from the ability to iterate over a collection that may be updated as we iterate through it.
              {
                CmpVertex target = targets.get(i);
                if (!mergePair(new StatePair(firstVertex,target), stateToEquivalenceClass,mergingDetails))
                {
                  AMEquivalenceClass<CmpVertex,LearnerGraphCachedData> firstEquivalenceClass = stateToEquivalenceClass.get(firstVertex);
                  if (setOfEquivalenceClassesOnStack.get(firstEquivalenceClass) == null)
                  {// if a merge added something and the equivalence class is not already on the stack, add it.
                    currentExplorationBoundary.offer(firstEquivalenceClass);// this may cause elements to be added to the collection of transitions in the considered equivalence classes and possibly even to the component of it denoted by targets.
View Full Code Here

    Queue<StatePair> currentExplorationBoundary = new LinkedList<StatePair>();// FIFO queue
    currentExplorationBoundary.add(pair);currentExplorationBoundary.offer(null);
   
    while(!foundKTail)
    {
      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);currentExplorationDepth++;
      }
      else
      {
        Map<Label,CmpVertex> targetRed = coregraph.transitionMatrix.get(currentPair.getR()),
          targetBlue = coregraph.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,coregraph.pairCompatibility))
              return -1;// incompatible states
           
            if (coregraph.config.getLearnerScoreMode() == Configuration.ScoreMode.KTAILS &&
                currentExplorationDepth >= coregraph.config.getKlimit())
            {
              foundKTail = true;
              break;// we found a path of the "currentExplorationDepth" length and using the KTAILS method, hence stop the loop.
            }

            ++score;
 
            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.
        }
      }
View Full Code Here

    {
      CmpVertex prevVertex = null;
      for(CmpVertex v:vertices)
      {
        if (prevVertex != null)
          pairsList.add(new StatePair(prevVertex,v));
        prevVertex = v;
      }
    }
    return pairsList;
  }
View Full Code Here

  {
    List<StatePair> pairs = new LinkedList<StatePair>();
    LearnerGraph sourcePta = new LearnerGraph(pta,pta.config);
    List<CmpVertex> whatToMerge = constructPairsToMergeWithOutgoing(sourcePta,unique);
    for(CmpVertex vert:whatToMerge)
      pairs.add(new StatePair(sourcePta.getInit(),vert));
    List<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> verticesToMerge = new ArrayList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
   
    if (sourcePta.pairscores.computePairCompatibilityScore_general(null, pairs, verticesToMerge) < 0)
      throw new IllegalArgumentException("failed to merge states corresponding to a unique outgoing transition "+unique);
    LearnerGraph outcome = MergeStates.mergeCollectionOfVertices(sourcePta, null, verticesToMerge);
View Full Code Here

    return new PairScore(aV,bV, score,score);
  }

  static protected void checkLess(String a, String b, int abS, String c, String d, int cdS, Configuration config)
  {
    StatePair p = constructPairScore(a,b,abS,config),
        q=constructPairScore(c,d,cdS,config);
    assertFalse(p.equals(q));
    assertTrue(p.compareTo(q)<0);
    assertTrue(q.compareTo(p)>0);
    assertFalse(p.hashCode() == q.hashCode());
    assertEquals(0,p.compareTo(p));
    assertEquals(0,q.compareTo(q));
  }
View Full Code Here

  }

  @Test
  public void testPairScoreEquality()
  {
    StatePair p = constructPairScore("a","b",4,testConfig), q=constructPairScore("a","b",4,testConfig);
    assertTrue(p.equals(p));
    assertTrue(p.equals(q));
    assertFalse(p.equals(null));
    assertFalse(p.equals("test"));
    assertFalse(p.equals(constructPairScore("a","c",4,testConfig)));
    assertFalse(p.equals(constructPairScore("a","b",6,testConfig)));
    assertFalse(p.equals(constructPairScore("b","b",4,testConfig)));
  }
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.StatePair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.