Package statechum.analysis.learning

Examples of statechum.analysis.learning.StatePair


   * @return trimmed copy of the reference graph.
   */
  public static Map<CmpVertex,Set<Label>> identifyUncoveredTransitions(LearnerGraph pta,LearnerGraph reference)
  {
    Map<CmpVertex,Set<Label>> outcome = new TreeMap<CmpVertex,Set<Label>>();
    StatePair reference_pta = new StatePair(reference.getInit(),pta.getInit());
    LinkedList<StatePair> pairsToExplore = new LinkedList<StatePair>();pairsToExplore.add(reference_pta);
    for(Entry<CmpVertex,Map<Label,CmpVertex>> entry:reference.transitionMatrix.entrySet())
      outcome.put(entry.getKey(), new TreeSet<Label>(entry.getValue().keySet()));
    Set<CmpVertex> visitedInTree = new HashSet<CmpVertex>();
    while(!pairsToExplore.isEmpty())
    {
      reference_pta = pairsToExplore.pop();
      Map<Label,CmpVertex> transitions=pta.transitionMatrix.get(reference_pta.secondElem);
      outcome.get(reference_pta.firstElem).removeAll(transitions.keySet());
      for(Entry<Label,CmpVertex> target:transitions.entrySet())
        if (target.getValue().isAccept())
        {
          if (visitedInTree.contains(target.getValue()))
            throw new IllegalArgumentException("PTA is not a tree");
          visitedInTree.add(target.getValue());
          CmpVertex nextGraphState = reference.transitionMatrix.get(reference_pta.firstElem).get(target.getKey());
          if (nextGraphState == null)
            throw new IllegalArgumentException("coverage has more transitions than the original graph");
          pairsToExplore.add(new StatePair(nextGraphState, target.getValue()));
        }
    }
   
    return outcome;
  }
View Full Code Here


    List<StatePair> listOfPairs = new LinkedList<StatePair>();
    for(List<List<Label>> lotOfPaths:pathsToMerge)
    {
      CmpVertex firstVertex = graph.getVertex(lotOfPaths.get(0));
      for(List<Label> seq:lotOfPaths)
        listOfPairs.add(new StatePair(firstVertex,graph.getVertex(seq)));
    }
    return listOfPairs;
  }
View Full Code Here

      {
        CmpVertex v0=validStatesInGroup.iterator().next();
        for(CmpVertex v:validStatesInGroup)
        {
          if (v != v0)
            pairsList.add(new StatePair(v0,v));
          v0=v;
        }
      }
    }
    return pairsList;
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.ONLYOVERRIDE)
    {
      computedScore = scoreComputationOverride.overrideScoreComputation(new PairScore(blue,red,0, 0));compatibilityScore=computedScore;
      return new PairScore(blue,red,computedScore, compatibilityScore);
    }
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

      currentExplorationBoundary.add(pair);
    currentExplorationBoundary.offer(null);
   
    while(true) // we'll do a break at the end of the last wave
    {
      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;// definitely incompatible states, fail regardgless whether we should look for a single or all paths.
           
            if (currentExplorationDepth < coregraph.config.getKlimit())
            {
              StatePair nextStatePair = new StatePair(nextBlueState,redEntry.getValue());
              currentExplorationBoundary.offer(nextStatePair);
            }
            else
            {
              if (anyPath)
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

      {
        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

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.