Package statechum

Examples of statechum.Label


        // which is used by the merging algorithm and dumping the results.
        CmpVertex v = pair.getR();
        Iterator<Label> seqIt = seq.iterator();
        while(seqIt.hasNext() && v != null)
        {
          Label input = seqIt.next();
          System.out.print(v.toString()+" "+original.transitionMatrix.get(v).keySet()+" input "+input+" ");
          List<CmpVertex> extra = mergedVertices.get(v);
          if (extra != null)
            for(CmpVertex ev:extra)
              System.out.print(" "+ev.toString()+" : "+original.transitionMatrix.get(ev).keySet());
          System.out.println();
          CmpVertex newV = original.transitionMatrix.get(v).get(input);
          if (newV != null) v=newV;
          else v=original.pairscores.findNextRed(mergedVertices,v,input);
        }
        System.out.println("final state is "+v);

        v=pair.getR();
        seqIt = seq.iterator();
        while(seqIt.hasNext() && v != null)
        {
          Label input = seqIt.next();
          System.out.println(v.toString()+" "+mergeResult.transitionMatrix.get(v).keySet()+" input "+input+" ");
          v = mergeResult.transitionMatrix.get(v).get(input);
        }
        System.out.println("final state is "+v);
       
View Full Code Here


    {
      rowsProcessed.add(entry.getKey());
      for(Entry<CmpVertex,PAIRCOMPATIBILITY> associations:entry.getValue().entrySet())
        if (!rowsProcessed.contains(associations.getKey()))
        {
          Label label = AbstractLearnerGraph.generateNewLabel(associationPrefix+associations.getValue().name(),config,converter);
          if (alphabet.contains(label))
            throw new IllegalArgumentException("cannot use label "+label);

          result.addTransition(result.transitionMatrix.get(entry.getKey()), label, associations.getKey());
          result.addTransition(result.transitionMatrix.get(associations.getKey()), label, entry.getKey());
View Full Code Here

  private List<CmpVertex> selectVerticesFromSet(int x, Map<Label, List<CmpVertex>> set) {
    List<CmpVertex> result = new ArrayList<CmpVertex>();
    List<CmpVertex> verticesToChooseFrom = new LinkedList<CmpVertex>();
    Iterator<Label> inIt = set.keySet().iterator();
    while(inIt.hasNext()){
      Label e = inIt.next();
      List<CmpVertex> verticesToBeAdded = new ArrayList<CmpVertex>();
      verticesToBeAdded.addAll(set.get(e));
      verticesToBeAdded.removeAll(visited);
      verticesToChooseFrom.addAll(verticesToBeAdded);
    }
View Full Code Here

  @Test
  public void testConstructPairsToMergeWithOutgoing1()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("M1-c->C1 / M1-a->A1-b->M2-c->C2-a->A3-b->M4-c->C4-a->A4 / M2-a->A2-b->M3-c->C3-d-#D / M2-b->B","testCconstructPairsToMergeWithOutgoing1",mainConfiguration, converter);
    Set<CmpVertex> actual = new TreeSet<CmpVertex>(), expectedTargets = new TreeSet<CmpVertex>(), actualTargets = new TreeSet<CmpVertex>();
    Label unique = AbstractLearnerGraph.generateNewLabel("c", mainConfiguration,converter);
    actual.addAll(PairQualityLearner.constructPairsToMergeWithOutgoing(graph, unique));
    Assert.assertEquals(4,actual.size());
    expectedTargets.addAll(Arrays.asList(new CmpVertex[]{graph.findVertex("C1"),graph.findVertex("C2"),graph.findVertex("C3"),graph.findVertex("C4")}));
    for(CmpVertex v:actual)
    {
View Full Code Here

  @Test
  public void testConstructPairsToMergeWithOutgoing2()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("M1-c-#C1 / M1-a->A1-b->M2-c->C2-a->A3-b->M4-c->C4-a->A4 / M2-a->A2-b->M3-c->C3-d-#D / M2-b->B","testCconstructPairsToMergeWithOutgoing2",mainConfiguration, converter);
    Set<CmpVertex> actual = new TreeSet<CmpVertex>(), expectedTargets = new TreeSet<CmpVertex>(), actualTargets = new TreeSet<CmpVertex>();
    Label unique = AbstractLearnerGraph.generateNewLabel("c", mainConfiguration,converter);
    actual.addAll(PairQualityLearner.constructPairsToMergeWithOutgoing(graph, unique));
    Assert.assertEquals(3,actual.size());
    expectedTargets.addAll(Arrays.asList(new CmpVertex[]{graph.findVertex("C2"),graph.findVertex("C3"),graph.findVertex("C4")}));
    for(CmpVertex v:actual)
    {
View Full Code Here

  @Test
  public void testConstructPairsToMergeWithOutgoing3()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("M1-c->C1 / M1-a->A1-b->M2-c->C2-a->A3-b->M4-c->C4-a->A4 / M2-a->A2-b->M3-c-#D / M2-b->B","testConstructPairsToMergeWithOutgoing3",mainConfiguration, converter);
    Set<CmpVertex> actual = new TreeSet<CmpVertex>(), expectedTargets = new TreeSet<CmpVertex>(), actualTargets = new TreeSet<CmpVertex>();
    Label unique = AbstractLearnerGraph.generateNewLabel("c", mainConfiguration,converter);
    actual.addAll(PairQualityLearner.constructPairsToMergeWithOutgoing(graph, unique));
    Assert.assertEquals(3,actual.size());
    expectedTargets.addAll(Arrays.asList(new CmpVertex[]{graph.findVertex("C1"),graph.findVertex("C2"),graph.findVertex("C4")}));
    for(CmpVertex v:actual)
    {
View Full Code Here

  private List<CmpVertex> selectVerticesFromSet(int x, Map<Label, List<CmpVertex>> set) {
    List<CmpVertex> result = new ArrayList<CmpVertex>();
    List<CmpVertex> verticesToChooseFrom = new LinkedList<CmpVertex>();
    Iterator<Label> inIt = set.keySet().iterator();
    while(inIt.hasNext()){
      Label e = inIt.next();
      List<CmpVertex> verticesToBeAdded = new ArrayList<CmpVertex>();
      verticesToBeAdded.addAll(set.get(e));
      verticesToBeAdded.removeAll(visited);
      verticesToChooseFrom.addAll(verticesToBeAdded);
    }
View Full Code Here

  {
    if (vFrom.length == 0 || tTable.length == 0) throw new IllegalArgumentException("array is zero-sized");
    int alphabetSize = tTable[vFrom[0]].length;
    if (alphabetSize == 0) throw new IllegalArgumentException("alphabet is zero-sized");
    CmpVertex stateName[] = new CmpVertex[tTable.length];for(int i=0;i < tTable.length;++i) stateName[i]=new StringVertex("S"+i);
    Label inputName[] = new Label[alphabetSize];for(int i=0;i < alphabetSize;++i) inputName[i]=new StringLabel("i"+i);
    LearnerGraph fsm = new LearnerGraph(config);fsm.initEmpty();
    fsm.setInit(stateName[vFrom[0]]);
    Set<CmpVertex> statesUsed = new HashSet<CmpVertex>();
    for(int i=0;i<vFrom.length;++i)
    {
View Full Code Here

      Map<Label,CmpVertex> graphTargets = graph.transitionMatrix.get(statePair.firstElem),
        maxTargets = statePair.secondElem == null? emptyTargets:from.transitionMatrix.get(statePair.secondElem);
      CmpVertex currentRepresentative = pairsToGraphStates.get(statePair);assert currentRepresentative != null;
      for(Entry<Label,CmpVertex> labelstate:graphTargets.entrySet())
      {
        Label label = labelstate.getKey();
        CmpVertex graphState = labelstate.getValue();// the original one
        CmpVertex maxState = maxTargets.get(label);

        if (maxState == null)
        {// this is the case where a transition in a tentative graph is not matched by any in a maximal automaton
          if (!maxIsPartial)
            throw new IllegalArgumentException("In state pair "+statePair+" transition labelled by "+label+" is not matched in a maximal automaton");
        }
       
        StatePair nextPair = new StatePair(graphState,maxState);
        // Now that we're making a step to a state pair where (graphState,maxState) pair has not been seen before,
        // it is quite possible that we have to clone the corresponding state in a tentative graph so as to ensure
        // that each state from a tentative graph is paired with no more than a single state in a maximal automaton
        // (this corresponds to a construction of a cross-product of states).
        // A state of a tentative state can be unpaired if the maximal automaton is partial,
        // i.e. it contains a number of counter-examples rather than all possible sequences. This is another
        // thing to check for in this method - if taking of an LTL-derived graph this should be deemed an error.
        boolean shouldDescend = true;
        CmpVertex nextGraphVertex = pairsToGraphStates.get(nextPair);// get a state representing the next pair of states
        if (nextGraphVertex == null)
        {// not seen this pair already hence might have to clone.
          if (!encounteredGraph.contains(graphState))
          {// since we did not see this pair before, the first encountered
           // vertex (graphState) is now a representative of the pair nextPair
            nextGraphVertex = AbstractLearnerGraph.cloneCmpVertex(graphState, config);encounteredGraph.add(graphState);
            pairsToGraphStates.put(nextPair,nextGraphVertex);
            result.transitionMatrix.put(nextGraphVertex, result.createNewRow());
            shouldDescend = nextGraphVertex.isAccept();
          }
          else
          {// graphState already paired with one of the states in maximal automaton hence clone the state
            boolean accept = graphState.isAccept() && (maxState == null || maxState.isAccept());// do not descend if the next state is reject or the next state in a maximal automaton is reject
           
            if (graphState.isAccept() != accept)
            {// tentative automaton reaches an accept state but the maximal automaton gets into reject-state
              if (!override)
                throw new IllegalArgumentException("incompatible labelling: maximal automaton chops off some paths in a tentative automaton");
              graphModified=true;
            }
            nextGraphVertex = AbstractLearnerGraph.generateNewCmpVertex(result.nextID(accept), config);
            if (GlobalConfiguration.getConfiguration().isAssertEnabled() && result.findVertex(nextGraphVertex) != null) throw new IllegalArgumentException("duplicate vertex with ID "+nextGraphVertex.getStringId()+" in graph "+result);
            DeterministicDirectedSparseGraph.copyVertexData(graphState, nextGraphVertex);nextGraphVertex.setAccept(accept);
            result.transitionMatrix.put(nextGraphVertex,result.createNewRow());
           
            pairsToGraphStates.put(nextPair, nextGraphVertex);
            if (!accept) shouldDescend = false;
          }
        }
        else // already seen the next pair hence no need to descend
          shouldDescend = false;
       
        result.transitionMatrix.get(currentRepresentative).put(label,nextGraphVertex);

        if (shouldDescend)
        // need to explore all transitions from the new state pair.
          currentExplorationBoundary.offer(nextPair);
       
      }
     
      for(Entry<Label,CmpVertex> labelstate:maxTargets.entrySet())
      {
        Label label = labelstate.getKey();
        if (!graphTargets.containsKey(label) && !labelstate.getValue().isAccept())
        {// a transition in a maximal automaton is not matched but leads to a reject-state hence direct to a reject-state adding it if necessary
          CmpVertex newVert = pairsToGraphStates.get(new StatePair(null,labelstate.getValue()));
          if (newVert == null)
          {
View Full Code Here

      Map<Label,CmpVertex> targetsBig = big.transitionMatrix.get(statePair.firstElem);
      Map<Label,CmpVertex> targetsSmall = small.transitionMatrix.get(statePair.secondElem);
         
      for(Entry<Label,CmpVertex> labelstate:targetsSmall.entrySet())
      {
        Label label = labelstate.getKey();
        if (!targetsBig.containsKey(label))
          throw new IllegalArgumentException("small graph is not contained in the large one, from "+statePair+
              " unmatched transition "+label+" to (nothing_in_big,"+labelstate.getValue()+")");
        ++matchedTransitionCounter;
        CmpVertex nextSmall = labelstate.getValue();
View Full Code Here

TOP

Related Classes of statechum.Label

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.