Package nz.ac.waikato.jdsl.graph.api

Examples of nz.ac.waikato.jdsl.graph.api.InspectableGraph


 
  public static void testBuildGraph()
  {
    ModelTestCase model = new ModelTestCase(new FSM());
    model.buildGraph();
    InspectableGraph graph = model.getGraph();
    // now check that the correct graph has been built.
    Assert.assertEquals(3, graph.numVertices());
    Assert.assertEquals(5, graph.numEdges());
    Vertex s0 = model.getVertex("0");
    Vertex s1 = model.getVertex("1");
    Vertex s2 = model.getVertex("2");
    Assert.assertNotNull(s0);
    Assert.assertNotNull(s1);
    Assert.assertNotNull(s2);
    Assert.assertEquals("0", s0.element());
    Assert.assertEquals("1", s1.element());
    Assert.assertEquals("2", s2.element());
    // we must iterate through the edges, because graph.aConnectingEdge
    // does not respect the direction of the edge!
    EdgeIterator iter = graph.edges();
    while (iter.hasNext()) {
      Edge e = iter.nextEdge();
      if (graph.origin(e) == s2 && graph.destination(e) == s0)
        Assert.assertEquals("action0", e.element());
      else if (graph.origin(e) == s2 && graph.destination(e) == s1)
        Assert.assertEquals("action1", e.element());
      else if (graph.origin(e) == s0 && graph.destination(e) == s2)
        Assert.assertEquals("action2", e.element());
      else
        Assert.assertEquals("actionNone", e.element());
    }
  }
View Full Code Here


    assertEquals(listen, new RandomTester(model).buildGraphBreadthFirst(1000,true));
    checkBuildGraph(model, listen, state0, state2);
  }

  private static void checkBuildGraph(Model model, GraphListener listen, Object state0, Object state2) {
    InspectableGraph graph = listen.getGraph();
    // now check that the correct graph has been built.
    assertEquals(3, graph.numVertices());
    assertEquals(5, graph.numEdges());

    Vertex s0 = listen.getVertex("0");
    Vertex s1 = listen.getVertex("1");
    Vertex s2 = listen.getVertex("2");
    assertNotNull(s0);
    assertNotNull(s1);
    assertNotNull(s2);
    assertEquals("0", s0.element());
    assertEquals("1", s1.element());
    assertEquals("2", s2.element());
    assertEquals(3, listen.getVertexMap().size());
    // we must iterate through the edges, because graph.aConnectingEdge
    // does not respect the direction of the edge!
    EdgeIterator iter = graph.edges();
    while (iter.hasNext()) {
      Edge e = iter.nextEdge();
      if (graph.origin(e) == s2 && graph.destination(e) == s0)
        assertEquals("action0", e.element());
      else if (graph.origin(e) == s2 && graph.destination(e) == s1)
        assertEquals("action1", e.element());
      else if (graph.origin(e) == s0 && graph.destination(e) == s2)
        assertEquals("action2", e.element());
      else
        assertEquals("actionNone", e.element());
    }
  }
View Full Code Here

    int[] worth = new int[model_.getNumActions()];
    for (int i = 0; i < worth.length; i++) {
      worth[i] = Integer.MIN_VALUE;
    }

    InspectableGraph fsmGraph = graph_.getGraph();
    EdgeIterator edges = fsmGraph.edges();

    // look ahead into the paths that we know about
    // TODO: iterate only over the nodes out of this state
    while (edges.hasNext()) {
      Edge e = edges.nextEdge();
      Object origin = fsmGraph.origin(e).element();
      Object dest = fsmGraph.destination(e).element();
      String actionName = (String) e.element();
      int actionNum = model_.getActionNumber(actionName);
      if (origin.equals(state)) {
        Transition tr = new Transition(origin, (String) e.element(), dest);
        Integer takenBefore = transitions_.getDetails().get(tr);
View Full Code Here

TOP

Related Classes of nz.ac.waikato.jdsl.graph.api.InspectableGraph

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.