Package edu.uci.ics.jung.graph.impl

Examples of edu.uci.ics.jung.graph.impl.DirectedSparseGraph


 
  @Test(expected = IllegalArgumentException.class)
  public final void testMerge_fail1a()
  {
    DirectedSparseGraph g=FsmParser.buildLearnerGraph(largeGraph1_invalid5,"testMerge_fail1",config,getLabelConverter()).pathroutines.getGraph();
    CmpVertex
      a = DeterministicDirectedSparseGraph.findVertexNamed(VertexID.parseID("A"), g),
      b = DeterministicDirectedSparseGraph.findVertexNamed(VertexID.parseID("B"), g);
    StatePair pair = new StatePair(b,a);// A is red
    MergeStates.mergeAndDeterminize(g, pair,testConfig);
View Full Code Here


   * @param graphName the name to give to the constructed graph
   */
  public final void testChooseStatePairs(String fsm, String [] initialReds, String [][] expectedReds, List<PairScore> expectedPairs, String graphName)
  {
    final LearnerGraph fsmAsLearnerGraph = FsmParser.buildLearnerGraph(fsm, graphName,config,getLabelConverter());
    final DirectedSparseGraph gB = fsmAsLearnerGraph.pathroutines.getGraph();
    for(PairScore pair:expectedPairs)
    {
      Assert.assertNotNull("vertex "+pair.getQ()+" is missing in the graph",fsmAsLearnerGraph.findVertex(pair.getQ()));
      Assert.assertNotNull("vertex "+pair.getR()+" is missing in the graph",fsmAsLearnerGraph.findVertex(pair.getR()));
    }
    //Visualiser.updateFrame(new LearnerGraph(gB,Configuration.getDefaultConfiguration()), null);Visualiser.waitForKey();
    // check how the reference pair selection function performs
    Configuration conf = testConfig.copy();conf.setLearnerUseStrings(false);conf.setLearnerCloneGraph(false);
    testChooseStatePairsInternal(gB,new LearnerGraph(gB, conf), initialReds, expectedReds, expectedPairs, new InterfaceChooserToTest() {
      public @Override Stack<StatePair> choosePairs() {// Here I need to convert the old type of pairs to the new one.
        Stack<OrigStatePair> pairs = chooseStatePairs(gB, new HashSet<List<Label>>(), new HashSet<List<Label>>());
        Stack<StatePair> result = new Stack<StatePair>();
        for(OrigStatePair pair:pairs) result.add(new StatePair((CmpVertex)pair.getQ(),(CmpVertex)pair.getR()));
        return result;
      }
    });

    final DirectedSparseGraph gA = FsmParser.buildLearnerGraph(fsm, graphName,config,getLabelConverter()).pathroutines.getGraph();
    // check how the revised pair selection function performs
    final LearnerGraph s = new LearnerGraph(gA, testConfig);
    testChooseStatePairsInternal(gA,s, initialReds, expectedReds, expectedPairs, new InterfaceChooserToTest() {
      public @Override Stack<? extends StatePair> choosePairs() {
        return s.pairscores.chooseStatePairs(null);
View Full Code Here

    {
      Set<String> possibleReds = new HashSet<String>();possibleReds.addAll(Arrays.asList(expectedReds[i]));
      expectedRedsAsSet.add(possibleReds);
    }
    Set<String> finalReds = new HashSet<String>();
    DirectedSparseGraph grf = l.pathroutines.getGraph();
    for(Vertex red:DeterministicDirectedSparseGraph.findVertices(JUConstants.COLOUR, JUConstants.RED, grf))
        finalReds.add(((VertID)red.getUserDatum(JUConstants.LABEL)).getStringId());
    Assert.assertTrue("expected red states, any of: "+expectedRedsAsSet+" actual : "+finalReds,expectedRedsAsSet.contains(finalReds));
    for(PairScore ps:expectedPairs)
    {
View Full Code Here

      int k1,int k2,int k3,
      String graphName)
  {
    //buildRubyTests(fsm,expectedComputedScore,graphName);
   
    DirectedSparseGraph g = FsmParser.buildLearnerGraph(fsm, graphName,config,getLabelConverter()).pathroutines.getGraph();
    OrigStatePair pairOrig = new OrigStatePair(
        DeterministicDirectedSparseGraph.findVertex(JUConstants.LABEL, VertexID.parseID("B"), g),
        DeterministicDirectedSparseGraph.findVertex(JUConstants.LABEL, VertexID.parseID("A"), g));
   
    LearnerGraph s = new LearnerGraph(g, testConfig);
View Full Code Here

          gr.config.setLearnerCloneGraph(false);
          graphsOrig.add( gr );
            graphs.add(((AbstractLearnerGraph) arg).pathroutines.getGraph());
            layoutOptions.put(graphNumber,gr.getLayoutOptions());
        } else if (arg instanceof DirectedSparseGraph) {
          DirectedSparseGraph gr = (DirectedSparseGraph) arg;
          graphsOrig.add(null);graphs.add(gr);
          LayoutOptions options = (LayoutOptions)gr.getUserDatum(JUConstants.LAYOUTOPTIONS);
          if (options == null)
            options = new LayoutOptions();
            layoutOptions.put(graphNumber,options);
        } else {
            System.err.println("Visualiser notified with unknown object " + arg);
View Full Code Here

                   
                  @Override
                  public void actionPerformed(@SuppressWarnings("unused") ActionEvent ev) {
                    GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData> gd =
                      new GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData>();
                    DirectedSparseGraph gr = gd.showGD(
                        ourGraph,otherGr,
                        ExperimentRunner.getCpuNumber());
                    Visualiser.updateFrame(gr, null);
                  }
           
View Full Code Here

  public static DirectedSparseGraph buildGraph(String fsm,String name)
  {
    final Map<String,DeterministicVertex> existingVertices = new HashMap<String,DeterministicVertex>();
    final Map<StatePair,DeterministicEdge> existingEdges = new HashMap<StatePair,DeterministicEdge>();
   
    final DirectedSparseGraph g = new DirectedSparseGraph();
    g.setUserDatum(JUConstants.TITLE, name,UserData.SHARED);

    new TestFSMParser.fsmParser(fsm).parse(new TestFSMParser.TransitionReceiver()
    {
      public void put(String from, String to, String label, boolean accept) {
        DeterministicVertex fromVertex = existingVertices.get(from), toVertex = existingVertices.get(to);
       
        if (fromVertex == null)
        {
          fromVertex = new DeterministicDirectedSparseGraph.DeterministicVertex(from);
          if (existingVertices.isEmpty())
            fromVertex.addUserDatum(JUConstants.INITIAL, true, UserData.SHARED);
          fromVertex.addUserDatum(JUConstants.ACCEPTED, true, UserData.SHARED);
          existingVertices.put(from, fromVertex);
          g.addVertex(fromVertex);
        }
        else
          if (!Boolean.valueOf(fromVertex.getUserDatum(JUConstants.ACCEPTED).toString()))
            throw new IllegalArgumentException("conflicting acceptance assignment on vertex "+from);

        if (from.equals(to))
        {
          if (!accept) throw new IllegalArgumentException("conflicting acceptance assignment on vertex "+to);
          toVertex = fromVertex;
        }
        else
          if (toVertex == null)
          {
            toVertex = new DeterministicDirectedSparseGraph.DeterministicVertex(to);
            toVertex.removeUserDatum(JUConstants.ACCEPTED); // in case we've got a reject loop in the same state
            toVertex.addUserDatum(JUConstants.ACCEPTED, accept, UserData.SHARED);
            existingVertices.put(to, toVertex);
            g.addVertex(toVertex);
          }
          else
            if (DeterministicDirectedSparseGraph.isAccept(toVertex) != accept)
              throw new IllegalArgumentException("conflicting acceptance assignment on vertex "+to);
       
        StatePair pair = new StatePair(fromVertex,toVertex);
        DeterministicEdge edge = existingEdges.get(pair);
        if (edge == null)
        {
          edge = new DeterministicDirectedSparseGraph.DeterministicEdge(fromVertex,toVertex);
          edge.addUserDatum(JUConstants.LABEL, new HashSet<String>(), UserData.CLONE);
          g.addEdge(edge);existingEdges.put(pair,edge);
        }
       
        Set<String> labels = (Set<String>)edge.getUserDatum(JUConstants.LABEL);
        labels.add(label);
      }
View Full Code Here

   * @param g graph to check
   * @param fsm the string representation of the machine which the graph should be isomorphic to
   */
  public void checkEq(DirectedSparseGraph g, String fsm)
  {
    DirectedSparseGraph expectedGraph = buildGraph(fsm,"expected graph");
    final LearnerGraph graph = new LearnerGraph(g,Configuration.getDefaultConfiguration());
    final LearnerGraph expected = new LearnerGraph(expectedGraph,Configuration.getDefaultConfiguration());
   
    assertEquals("incorrect data",true,expected.equals(graph));
  }
View Full Code Here

  }

  @Test
  public void testCheckEq()
  {
    DirectedSparseGraph g=buildGraph("P-a->Q_State-b->P-c->P","testCheckEq");
    checkEq(g,"P-c->P<-b-Q_State<-a-P");
  }
View Full Code Here

 
  /** Verifies the equivalence of a supplied graph to the supplied machine. */
  public static void checkM(DirectedSparseGraph g,String fsm,Configuration conf)
  {
    final LearnerGraph graph = new LearnerGraph(g,conf);
    final DirectedSparseGraph expectedGraph = buildGraph(fsm,"expected graph");
    final LearnerGraph expected = new LearnerGraph(expectedGraph,conf);
    WMethod.checkM(graph,expected);
  }
View Full Code Here

TOP

Related Classes of edu.uci.ics.jung.graph.impl.DirectedSparseGraph

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.