Package statechum.DeterministicDirectedSparseGraph

Examples of statechum.DeterministicDirectedSparseGraph.DeterministicVertex


  public static final String PTA1 = "\nA-p->I-q->B"+"\nB-a->B1-a-#B2\nB1-b->B3-b->B4\n";
 
  @Test(expected = IllegalArgumentException.class)
  public final void testLearnerFailsWhenRedNotFound()
  {
    ComputeQuestions.computeQS_orig(new StatePair(null,new DeterministicVertex("non-existing")), new LearnerGraph(testConfig), new LearnerGraph(testConfig));
  }
View Full Code Here


    }
    long lastScore = -1;
    for(StatePair elem:pairs)
    {
      doneEdges = new HashSet<DirectedSparseEdge>();
      DeterministicVertex origBlue = DeterministicDirectedSparseGraph.findVertexNamed(elem.getQ(), g);
      DeterministicVertex origRed = DeterministicDirectedSparseGraph.findVertexNamed(elem.getR(), g);
      long currentScore = computeScore(g, new OrigStatePair(origBlue,origRed));// This one returns vertices from g, but elem may easily contain StringVertices and such, hence convert elem to Vertex-pair.
      PairScore elA = constructPairScore(elem.getQ().getStringId(),elem.getR().getStringId(),currentScore, testConfig);
      PairScore elB = constructPairScore(elem.getR().getStringId(),elem.getQ().getStringId(),currentScore, testConfig);
      Assert.assertTrue(elem.getR().getColour() == JUConstants.RED);
      Assert.assertTrue(elem.getQ().getColour() == JUConstants.BLUE);
View Full Code Here

    vertices = new ArrayList<DeterministicVertex>();
    generator  = new MersenneTwister(seed);
    boolGenerator = new Random(seed);
    synchronized(AbstractLearnerGraph.syncObj)
    {
      DeterministicVertex v=new DeterministicVertex(new VertexID(VertexID.VertKind.NEUTRAL,0));
      annotateVertex(v);
      machine.addVertex(v);
      vertices.add(v);// permits v to be chosen as a target, creating self-loops
      v.setUserDatum(JUConstants.INITIAL, true, UserData.SHARED);
    }
  }
View Full Code Here

      int currentSize = 0;
      do
      {
        while(i < numberOfVerticesToAdd)
        {
          DeterministicVertex v=new DeterministicVertex(new VertexID(VertexID.VertKind.NEUTRAL,i+1));
          annotateVertex(v);
          machine.addVertex(v);
          vertices.add(v);// permits v to be chosen as a target, creating self-loops
          this.labelmap.put(v, v);
          Set<DeterministicVertex> tried = new TreeSet<DeterministicVertex>();
          tried.add(v);
          DeterministicVertex random = null;
          do
          {
            random = selectRandom(tried);
            tried.add(random);
          }
View Full Code Here

  protected DeterministicVertex selectRandom(Set<DeterministicVertex> blocked)
  {
    Set<DeterministicVertex> available = new TreeSet<DeterministicVertex>();available.addAll(vertices);
    if (blocked != null) available.removeAll(blocked);
    if (available.isEmpty()) throw new IllegalArgumentException("no vertices to select from");
    DeterministicVertex availableArray[] = new DeterministicVertex[available.size()];available.toArray(availableArray);
    return availableArray[randomInt(availableArray.length)];
  }
View Full Code Here

    int i=0;
    for(i=0;i<attemptCounter && chosenInts.size() < x;++i)
      chosenInts.add(randomInt(size));
    if (i == attemptCounter)
      throw new IllegalArgumentException("random number generator failure");
    DeterministicVertex verticesGiven[]=new DeterministicVertex[size];argVertices.toArray(verticesGiven);
    for(Integer chosen:chosenInts)
      result.add(verticesGiven[chosen]);
    return result;
  }
View Full Code Here

    @SuppressWarnings("unchecked")
    Iterator<DirectedSparseEdge> inIt = ambassador.getInEdges().iterator();
    Set<DeterministicVertex> verticesToChooseFrom = new TreeSet<DeterministicVertex>();
    while(inIt.hasNext()){
      DirectedSparseEdge e = inIt.next();
      DeterministicVertex v = (DeterministicVertex) e.getSource();
      if(!visited.contains(v))
        verticesToChooseFrom.add(v);
    }
    if (!verticesToChooseFrom.isEmpty()) result.addAll(selectVertices(verticesToChooseFrom, x));
   
    @SuppressWarnings("unchecked")
    Iterator<DirectedSparseEdge> outIt = ambassador.getOutEdges().iterator();
    verticesToChooseFrom.clear();
    while(outIt.hasNext()){
      DirectedSparseEdge e = outIt.next();
      DeterministicVertex v = (DeterministicVertex) e.getDest();
      if(!visited.contains(v))
        verticesToChooseFrom.add(v);
    }
   
    if (!verticesToChooseFrom.isEmpty()) result.addAll(selectVertices(verticesToChooseFrom, y));
View Full Code Here

      Map<CmpVertex,DeterministicVertex> oldToNew = new HashMapWithSearch<CmpVertex,DeterministicVertex>(coregraph.getStateNumber());
      // add states
      for(Entry<CmpVertex,Map<CmpVertex,Set<Label>>> entry:flowgraph.entrySet())
      {
        CmpVertex source = entry.getKey();
        DeterministicVertex vert = new DeterministicVertex(source);
        if (coregraph.getInit() == source)
          vert.addUserDatum(JUConstants.INITIAL, true, UserData.SHARED);
        vert.setAccept(source.isAccept());
        vert.setColour(source.getColour());
        vert.setHighlight(source.isHighlight());
        result.addVertex(vert);
        oldToNew.put(source,vert);
      }
     
      // now add transitions
      for(Entry<CmpVertex,Map<CmpVertex,Set<Label>>> entry:flowgraph.entrySet())
      {
        DeterministicVertex source = oldToNew.get(entry.getKey());
        for(Entry<CmpVertex,Set<Label>> tgtEntry:entry.getValue().entrySet())
        {
          DeterministicVertex target = oldToNew.get(tgtEntry.getKey());
          DeterministicEdge e = new DeterministicEdge(source,target);
          e.addUserDatum(JUConstants.LABEL, tgtEntry.getValue(), UserData.CLONE);
          result.addEdge(e);
        }
      }
View Full Code Here

 
  @SuppressWarnings("unchecked")
  public static DirectedSparseGraph mergeAndDeterminize(Graph graphToMerge, StatePair pair, Configuration conf)
  {
      DirectedSparseGraph g = (DirectedSparseGraph)graphToMerge.copy();
      DeterministicVertex newBlue = DeterministicDirectedSparseGraph.findVertexNamed(pair.getQ(),g);
      DeterministicVertex newRed = DeterministicDirectedSparseGraph.findVertexNamed(pair.getR(),g);
      Map<CmpVertex,List<CmpVertex>> mergedVertices = conf.getTransitionMatrixImplType() == STATETREE.STATETREE_ARRAY?
          new ArrayMapWithSearch<CmpVertex,List<CmpVertex>>(g.numVertices()):
          new HashMapWithSearch<CmpVertex,List<CmpVertex>>(g.numVertices());
     
      // Special configuration is necessary to ensure that computePairCompatibilityScore_internal
      // builds mergedVertices using g's vertices rather than StringVertices or clones of g's vertices.
      Configuration VertexCloneConf = conf.copy();VertexCloneConf.setLearnerUseStrings(false);VertexCloneConf.setLearnerCloneGraph(false);
      LearnerGraph s=new LearnerGraph(g,VertexCloneConf);
      if (s.pairscores.computePairCompatibilityScore_internal(new StatePair(s.findVertex(pair.getQ()),s.findVertex(pair.getR())),mergedVertices) < 0)
        throw new IllegalArgumentException("elements of the pair are incompatible");

      // make a loop
      Set<Label> usedInputs = new HashSet<Label>();
      for(DirectedSparseEdge e:(Set<DirectedSparseEdge>)newBlue.getInEdges())
      {
        Vertex source = e.getSource();
        Collection<Label> existingLabels = (Collection<Label>)e.getUserDatum(JUConstants.LABEL);
        g.removeEdge(e);

        // It is possible that there is already an edge between g.getSource Blue and newRed
        Iterator<DirectedSparseEdge> sourceOutIt = source.getOutEdges().iterator();
        Edge fromSourceToNewRed = null;
        while(sourceOutIt.hasNext() && fromSourceToNewRed == null)
        {
          DirectedSparseEdge out = sourceOutIt.next();if (out.getDest() == newRed) fromSourceToNewRed = out;
        }
        if (fromSourceToNewRed == null)
        {
          fromSourceToNewRed = new DirectedSparseEdge(source,newRed);
          fromSourceToNewRed.setUserDatum(JUConstants.LABEL, existingLabels, UserData.CLONE);// no need to clone this one since I'll delete the edge in a bit
          g.addEdge(fromSourceToNewRed);
        }
        else
          // there is already a transition from source to newRed, hence all we have to do is merge the new labels into it.
          ((Collection<Label>)fromSourceToNewRed.getUserDatum(JUConstants.LABEL)).addAll( existingLabels );
         
      }

      // now the elements of mergedVertices are in terms of the copied graph.
      for(Vertex vert:(Set<Vertex>)g.getVertices())
        if (mergedVertices.containsKey(vert))
        {// there are some vertices to merge with this one.
          usedInputs.clear();usedInputs.addAll(s.transitionMatrix.get(vert).keySet());
          for(CmpVertex toMerge:mergedVertices.get(vert))
          {// for every input, I'll have a unique target state - this is a feature of PTA
           // For this reason, every if multiple branches of PTA get merged, there will be no loops or parallel edges.
          // As a consequence, it is safe to assume that each input/target state combination will lead to a new state.
            Set<Label> inputsFrom_toMerge = s.transitionMatrix.get(toMerge).keySet();
            for(Label input:inputsFrom_toMerge)
              if (!usedInputs.contains(input))
              {
                Set<Label> labels = new HashSet<Label>();
                                                                labels.add(input);
                DeterministicVertex targetVert = (DeterministicVertex)s.transitionMatrix.get(toMerge).get(input);
                DirectedSparseEdge newEdge = new DirectedSparseEdge(vert,targetVert);
                newEdge.addUserDatum(JUConstants.LABEL, labels, UserData.CLONE);
                g.removeEdges(targetVert.getInEdges());g.addEdge(newEdge);
              }
            usedInputs.addAll(inputsFrom_toMerge);
          }
        }
     
View Full Code Here

 
  /** Handling of depth using representatives where multiple equivalence classes are merged. */
  @Test
  public final void testEqClassRepresentatives5() throws IncompatibleStatesException
  {
    CmpVertex A = new StringVertex("A"), B = new StringVertex("B"), C=new DeterministicVertex("C"), D=new DeterministicVertex("D");
    B.setDepth(5);C.setDepth(45);D.setDepth(4);
    AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>
      eqClassA = buildClass(new AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>(0,testGraphString),
          new CmpVertex[]{A,B}),eqClassB = buildClass(new AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>(0,testGraphString),new CmpVertex[]{C,D});
    eqClassB.mergeWith(eqClassA);
    Assert.assertSame(D,eqClassB.getRepresentative());
View Full Code Here

TOP

Related Classes of statechum.DeterministicDirectedSparseGraph.DeterministicVertex

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.