/** Creates a new instance of SimpleGraphView */
 public InteractiveGraphView3() {
   // Graph<V, E> where V is the type of the vertices and E is the type of the edges
   g = new SparseMultigraph<Integer, String>();
   // Add some vertices and edges
   g.addVertex((Integer) 1);
   g.addVertex((Integer) 2);
   g.addVertex((Integer) 3);
   g.addEdge("Edge-A", 1, 2);
   g.addEdge("Edge-B", 2, 3);
 }
  /**
   * Converts the prefuse graph data into the jung graph data.
   *
   * @param vg the prefuse visual graph
   * @return graph the jung graph data
   */
  public static edu.uci.ics.jung.graph.Graph<String, String> convertJungGraph(VisualGraph vg) {

    edu.uci.ics.jung.graph.Graph<String, String> graph =
        new UndirectedSparseGraph<String, String>();

    if (vg != null) {
      Iterator<?> nodeIter = vg.nodes();
      while (nodeIter.hasNext()) {
        VisualItem node = (VisualItem) nodeIter.next();
        String nodeId = node.getString("id");
        // System.out.println("node id == " + nodeId);
        graph.addVertex(nodeId);
      }

      Iterator<?> edgeIter = vg.edges();
      while (edgeIter.hasNext()) {
        VisualItem edge = (VisualItem) edgeIter.next();
        String node1 = edge.getString("node1");
        String node2 = edge.getString("node2");
        String edgeId = node1 + node2;
        // System.out.println("edge id == " + edgeId);
        graph.addEdge(edgeId, node1, node2, EdgeType.UNDIRECTED);
      }
    }
    return graph;
  }
 public FSMBuildVisualizer() {
   super("Model Visualizer");
   graph = new DirectedSparseMultigraph<>();
   graph.addVertex(current);
   //    Layout<FSMTransition, String> layout = new CircleLayout<FSMTransition, String>(graph);
   layout = new KKLayout<>(graph);
   layout.setSize(new Dimension(800, 600)); // sets the initial size of the space
   vv = new VisualizationViewer<>(layout);
   vv.setPreferredSize(new Dimension(800, 600)); // Sets the viewing area size
   vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
   vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
   vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
   VertexLabelAsShapeRenderer<String, StepCounter> vlasr =
       new VertexLabelAsShapeRenderer<>(vv.getRenderContext());
   //    vv.getRenderContext().setVertexShapeTransformer(vlasr);
   vv.getRenderContext().setVertexShapeTransformer(new EllipseVertexTransformer());
   //    vv.getRenderContext().setVertexLabelRenderer(new
   // TransitionVertextLabelRenderer(Color.GREEN));
   DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
   vv.addKeyListener(gm.getModeKeyListener());
   gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);
   vv.setGraphMouse(gm);
   getContentPane().add(vv);
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   setSize(1024, 768);
   pack();
   setVisible(true);
 }
 /**
  * create some vertices
  *
  * @param count how many to create
  * @return the Vertices in an array
  */
 private Vertex[] createVertices(int count) {
   Vertex[] v = new Vertex[count];
   for (int i = 0; i < count; i++) {
     v[i] = graph.addVertex(new DirectedSparseVertex());
   }
   return v;
 }
  private void insertTestData() {
    // TODO Auto-generated method stub
    trafficDataset.addValue(20, "rx", "1");
    trafficDataset.addValue(40, "rx", "2");
    trafficDataset.addValue(10, "rx", "3");
    trafficDataset.addValue(60, "rx", "4");
    trafficDataset.addValue(10, "rx", "5");
    trafficDataset.addValue(20, "rx", "6");
    trafficDataset.addValue(20, "rx", "7");
    trafficDataset.addValue(70, "rx", "8");
    trafficDataset.addValue(25, "rx", "9");
    trafficDataset.addValue(15, "rx", "10");
    trafficDataset.addValue(10, "rx", "11");
    trafficDataset.addValue(20, "rx", "12");

    trafficDataset.addValue(10, "tx", "1");
    trafficDataset.addValue(20, "tx", "2");
    trafficDataset.addValue(30, "tx", "3");
    trafficDataset.addValue(20, "tx", "4");
    trafficDataset.addValue(10, "tx", "5");
    trafficDataset.addValue(20, "tx", "6");
    trafficDataset.addValue(50, "tx", "7");
    trafficDataset.addValue(30, "tx", "8");
    trafficDataset.addValue(35, "tx", "9");
    trafficDataset.addValue(25, "tx", "10");
    trafficDataset.addValue(5, "tx", "11");
    trafficDataset.addValue(20, "tx", "12");

    trafficChart.setTitle("IP : 124.15.65.76");

    nodeTrafficTableModel.addNodeTraffic(new NodeTraffic("148.35.124.7", 80, 66357, 343654, 1));
    nodeTrafficTableModel.addNodeTraffic(new NodeTraffic("253.27.64.32", 80, 5757, 3446, 1));
    nodeTrafficTableModel.addNodeTraffic(new NodeTraffic("124.15.65.76", 22, 345, 7778, 1));
    nodeTrafficTableModel.addNodeTraffic(new NodeTraffic("125.76.43.221", 80, 453, 3456, 1));
    nodeTrafficTableModel.addNodeTraffic(new NodeTraffic("57.78.3.11", 80, 765, 26754, 1));
    nodeTrafficTableModel.addNodeTraffic(new NodeTraffic("86.34.25.22", 22, 45347, 345346, 1));

    graph.addVertex("Internet");
    for (int i = 1; i <= 6; i++) {
      graph.addVertex("Node" + 1);
      graph.addEdge("rx:node" + i, "Internet", "Node" + i, EdgeType.DIRECTED);
      graph.addEdge("tx:node" + i, "Node" + i, "Internet", EdgeType.DIRECTED);
    }
  }
  public Graph<String, String> createGraph() {
    graph = new UndirectedSparseGraph<String, String>();

    Attribute id = exampleSet.getAttributes().getId();
    if (id != null) {
      for (Example example : exampleSet) {
        graph.addVertex(example.getValueAsString(id));
      }
      addEdges();
    }
    return graph;
  }
  public LicenseVisualizer(LicenseModel lModel) {
    this.setLicenseModel(lModel);
    this.setLicenseGraph(new SparseMultigraph<String, Edge>());

    licenseGraph.addVertex(lModel.getLicenseIdentifier());

    for (String right : lModel.getRights()) {
      licenseGraph.addVertex(right);
      licenseGraph.addEdge(new Edge("hasRight"), lModel.getLicenseIdentifier(), right);
    }

    for (String obligation : lModel.getObligations()) {
      licenseGraph.addVertex(obligation);
      licenseGraph.addEdge(new Edge("hasObligation"), lModel.getLicenseIdentifier(), obligation);
    }

    for (String additionalCondition : lModel.getAdditionalConditions()) {
      licenseGraph.addVertex(additionalCondition);
      licenseGraph.addEdge(
          new Edge("hasAdditionalCondition"), lModel.getLicenseIdentifier(), additionalCondition);
    }
  }
 @Override
 public void addNode(V n) {
   super.addNode(n);
   if (n instanceof NodeView || n instanceof TextView) {
     graph.addVertex(n);
   }
   //		else if (n instanceof YConnectionView) {
   //			YConnectionView a = (YConnectionView) n;
   //
   //			// FIXME does the cast work?
   //			for (YNodeView nv : a.getNodeViews()) {
   //				if (nv.equals(n))
   //			}
   //			graph.addEdge((E) a, (V) nv, (V) a.getDst());
   //		}
 }
 private void addEdge(String step) {
   String edge = current + "->" + step;
   if (!edges.containsKey(edge)) {
     //      System.out.println("EDGE+" + edge);
     if (!vertices.contains(step)) {
       //        System.out.println("VERTEX+" + t);
       graph.addVertex(step);
       vertices.add(step);
     }
     StepCounter counter = new StepCounter();
     edges.put(edge, counter);
     graph.addEdge(counter, current, step);
     vv.repaint();
   } else {
     edges.get(edge).increment();
   }
   layout.reset();
 }
Exemple #10
0
  public void init(Functionality.Graph g, int _layout_width, int _layout_height) {
    myGraph = g;
    layout_width = _layout_width;
    layout_height = _layout_height;
    qt = new UndirectedSparseGraph();

    Iterator<Functionality.Node> nodeIterator = g.getNodes().iterator();
    while (nodeIterator.hasNext()) {
      qt.addVertex(nodeIterator.next());
    }

    Iterator<Functionality.Edge> edgeIterator = g.getEdges().iterator();
    while (edgeIterator.hasNext()) {
      Functionality.Edge currEdge = edgeIterator.next();
      qt.addEdge(currEdge, currEdge.getNode1(), currEdge.getNode2());
    }

    vv = null;
    layout = null;
  }
  /** @see edu.uci.ics.jung.algorithms.generators.GraphGenerator#create() */
  @SuppressWarnings("unchecked")
  public Graph<V, E> create() {
    int vertex_count = row_count * col_count;
    Graph<V, E> graph = graph_factory.create();
    v_array = new ArrayList<V>(vertex_count);
    for (int i = 0; i < vertex_count; i++) {
      V v = vertex_factory.create();
      graph.addVertex(v);
      v_array.add(i, v);
    }

    int start = is_toroidal ? 0 : 1;
    int end_row = is_toroidal ? row_count : row_count - 1;
    int end_col = is_toroidal ? col_count : col_count - 1;

    // fill in edges
    // down
    for (int i = 0; i < end_row; i++)
      for (int j = 0; j < col_count; j++)
        graph.addEdge(edge_factory.create(), getVertex(i, j), getVertex(i + 1, j));
    // right
    for (int i = 0; i < row_count; i++)
      for (int j = 0; j < end_col; j++)
        graph.addEdge(edge_factory.create(), getVertex(i, j), getVertex(i, j + 1));

    // if the graph is directed, fill in the edges going the other direction...
    if (graph.getDefaultEdgeType() == EdgeType.DIRECTED) {
      // up
      for (int i = start; i < row_count; i++)
        for (int j = 0; j < col_count; j++)
          graph.addEdge(edge_factory.create(), getVertex(i, j), getVertex(i - 1, j));
      // left
      for (int i = 0; i < row_count; i++)
        for (int j = start; j < col_count; j++)
          graph.addEdge(edge_factory.create(), getVertex(i, j), getVertex(i, j - 1));
    }

    return graph;
  }
  // method for flow graph visualization
  public static void visualizeGraph(int[][] matrix, int N, int k) {
    Graph<Integer, String> graph = new DirectedSparseGraph<Integer, String>();

    for (int i = 0; i < matrix.length; i++) {
      graph.addVertex((Integer) i);
    }

    for (int i = 0; i < matrix.length; i++) {
      for (int j = 0; j < matrix[i].length; j++) {
        // only select edge that has flow bigger than 0
        if (matrix[i][j] > 0) {
          graph.addEdge(i + "->" + j, i, j, EdgeType.DIRECTED);
        }
      }
    }

    Layout<Integer, String> layout = new CircleLayout<Integer, String>(graph);
    layout.setSize(new Dimension(800, 800));

    BasicVisualizationServer<Integer, String> vv =
        new BasicVisualizationServer<Integer, String>(layout);
    Transformer<Integer, Paint> vertexPaint =
        new Transformer<Integer, Paint>() {
          public Paint transform(Integer i) {
            return Color.YELLOW;
          }
        };

    vv.setPreferredSize(new Dimension(800, 800));
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Integer>());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);

    JFrame frame = new JFrame("Network Visualization - N = " + N + ", k = " + k);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);
    frame.pack();
    frame.setVisible(true);
  }
Exemple #13
0
  public void testMixedSaveLoadSave() throws IOException {
    Graph<Number, Number> graph1 = new SparseMultigraph<Number, Number>();
    for (int i = 0; i < 5; i++) {
      graph1.addVertex(i);
    }
    int j = 0;

    List<Number> id = new ArrayList<Number>(graph1.getVertices());
    GreekLabels<Number> gl = new GreekLabels<Number>(id);
    Number[] edges = {0, 1, 2, 3, 4, 5};

    graph1.addEdge(j++, 0, 1, EdgeType.DIRECTED);
    graph1.addEdge(j++, 0, 2, EdgeType.DIRECTED);
    graph1.addEdge(j++, 1, 2, EdgeType.DIRECTED);
    graph1.addEdge(j++, 1, 3);
    graph1.addEdge(j++, 1, 4);
    graph1.addEdge(j++, 4, 3);

    Map<Number, Number> nr = new HashMap<Number, Number>();
    for (int i = 0; i < edges.length; i++) {
      nr.put(edges[i], new Float(Math.random()));
    }

    assertEquals(graph1.getEdgeCount(), 6);

    //        System.err.println(" mixed graph1 = "+graph1);
    //        for(Number edge : graph1.getEdges()) {
    //        	System.err.println("edge "+edge+" is directed? "+graph1.getEdgeType(edge));
    //        }
    //        for(Number v : graph1.getVertices()) {
    //        	System.err.println(v+" outedges are "+graph1.getOutEdges(v));
    //        	System.err.println(v+" inedges are "+graph1.getInEdges(v));
    //        	System.err.println(v+" incidentedges are "+graph1.getIncidentEdges(v));
    //        }

    String testFilename = "mtest.net";
    String testFilename2 = testFilename + "2";

    // assign arbitrary locations to each vertex
    Map<Number, Point2D> locations = new HashMap<Number, Point2D>();
    for (Number v : graph1.getVertices()) {
      locations.put(v, new Point2D.Double(v.intValue() * v.intValue(), 1 << v.intValue()));
    }
    Function<Number, Point2D> vld = Functions.forMap(locations);

    PajekNetWriter<Number, Number> pnw = new PajekNetWriter<Number, Number>();
    pnw.save(graph1, testFilename, gl, Functions.forMap(nr), vld);

    Graph<Number, Number> graph2 = pnr.load(testFilename, graphFactory);
    Function<Number, String> pl = pnr.getVertexLabeller();
    List<Number> id2 = new ArrayList<Number>(graph2.getVertices());
    Function<Number, Point2D> vld2 = pnr.getVertexLocationTransformer();

    assertEquals(graph1.getVertexCount(), graph2.getVertexCount());
    assertEquals(graph1.getEdgeCount(), graph2.getEdgeCount());

    // test vertex labels and locations
    for (int i = 0; i < graph1.getVertexCount(); i++) {
      Number v1 = id.get(i);
      Number v2 = id2.get(i);
      assertEquals(gl.apply(v1), pl.apply(v2));
      assertEquals(vld.apply(v1), vld2.apply(v2));
    }

    // test edge weights
    Function<Number, Number> nr2 = pnr.getEdgeWeightTransformer();
    for (Number e2 : graph2.getEdges()) {
      Pair<Number> endpoints = graph2.getEndpoints(e2);
      Number v1_2 = endpoints.getFirst();
      Number v2_2 = endpoints.getSecond();
      Number v1_1 = id.get(id2.indexOf(v1_2));
      Number v2_1 = id.get(id2.indexOf(v2_2));
      Number e1 = graph1.findEdge(v1_1, v2_1);
      assertNotNull(e1);
      assertEquals(nr.get(e1).floatValue(), nr2.apply(e2).floatValue(), 0.0001);
    }

    pnw.save(graph2, testFilename2, pl, nr2, vld2);

    compareIndexedGraphs(graph1, graph2);

    pnr.setVertexLabeller(null);
    Graph<Number, Number> graph3 = pnr.load(testFilename2, graphFactory);

    compareIndexedGraphs(graph2, graph3);

    File file1 = new File(testFilename);
    File file2 = new File(testFilename2);

    Assert.assertTrue(file1.length() == file2.length());
    file1.delete();
    file2.delete();
  }
Exemple #14
0
  public void testDirectedSaveLoadSave() throws IOException {
    Graph<Number, Number> graph1 = directedGraphFactory.get();
    for (int i = 0; i < 5; i++) {
      graph1.addVertex(i);
    }
    //        GraphUtils.addVertices(graph1, 5);
    List<Number> id = new ArrayList<Number>(graph1.getVertices()); // Indexer.getIndexer(graph1);
    GreekLabels<Number> gl = new GreekLabels<Number>(id);
    int j = 0;
    graph1.addEdge(j++, 0, 1);
    graph1.addEdge(j++, 0, 2);
    graph1.addEdge(j++, 1, 2);
    graph1.addEdge(j++, 1, 3);
    graph1.addEdge(j++, 1, 4);
    graph1.addEdge(j++, 4, 3);

    //        System.err.println("graph1 = "+graph1);
    //        for(Number edge : graph1.getEdges()) {
    //        	System.err.println("edge "+edge+" is directed? "+graph1.getEdgeType(edge));
    //        }
    //        for(Number v : graph1.getVertices()) {
    //        	System.err.println(v+" outedges are "+graph1.getOutEdges(v));
    //        	System.err.println(v+" inedges are "+graph1.getInEdges(v));
    //        	System.err.println(v+" incidentedges are "+graph1.getIncidentEdges(v));
    //        }

    assertEquals(graph1.getEdgeCount(), 6);

    String testFilename = "dtest.net";
    String testFilename2 = testFilename + "2";

    PajekNetWriter<Number, Number> pnw = new PajekNetWriter<Number, Number>();
    pnw.save(graph1, testFilename, gl, null, null);

    Graph<Number, Number> graph2 = pnr.load(testFilename, directedGraphFactory);

    //        System.err.println("graph2 = "+graph2);
    //        for(Number edge : graph2.getEdges()) {
    //        	System.err.println("edge "+edge+" is directed? "+graph2.getEdgeType(edge));
    //        }
    //        for(Number v : graph2.getVertices()) {
    //        	System.err.println(v+" outedges are "+graph2.getOutEdges(v));
    //        	System.err.println(v+" inedges are "+graph2.getInEdges(v));
    //        	System.err.println(v+" incidentedges are "+graph2.getIncidentEdges(v));
    //       }

    assertEquals(graph1.getVertexCount(), graph2.getVertexCount());
    assertEquals(graph1.getEdgeCount(), graph2.getEdgeCount());

    pnw.save(graph2, testFilename2, pnr.getVertexLabeller(), null, null);

    compareIndexedGraphs(graph1, graph2);

    Graph<Number, Number> graph3 = pnr.load(testFilename2, graphFactory);

    //        System.err.println("graph3 = "+graph3);
    //        for(Number edge : graph3.getEdges()) {
    //        	System.err.println("edge "+edge+" is directed? "+graph3.getEdgeType(edge));
    //        }
    //        for(Number v : graph3.getVertices()) {
    //        	System.err.println(v+" outedges are "+graph3.getOutEdges(v));
    //        	System.err.println(v+" inedges are "+graph3.getInEdges(v));
    //        	System.err.println(v+" incidentedges are "+graph3.getIncidentEdges(v));
    //        }

    compareIndexedGraphs(graph2, graph3);

    File file1 = new File(testFilename);
    File file2 = new File(testFilename2);

    Assert.assertTrue(file1.length() == file2.length());
    file1.delete();
    file2.delete();
  }