/** Depth search */
  private void depthSearch() {

    GraphIterator<Object, DefaultEdge> iterator_depthFirst =
        new DepthFirstIteratorEdge<>(graph, VIRTUAL_TOPNODE, 0);

    while (iterator_depthFirst.hasNext()) {
      iterator_depthFirst.next();
    }

    depthResult =
        ((DepthFirstIteratorEdge<Object, DefaultEdge>) iterator_depthFirst).getDepthResults();

    length = ((DepthFirstIteratorEdge<Object, DefaultEdge>) iterator_depthFirst).getCounter() - 1;
  }
  /** Breadth First Search */
  private void breadthSearch() {

    GraphIterator<Object, DefaultEdge> iterator_breathFirst =
        new BreadthFirstIterator_<>(
            graph, VIRTUAL_TOPNODE, 4, length, depthResult, SIGNATURE_METHOD);
    // System.out.println("BREATH FIRST");
    while (iterator_breathFirst.hasNext()) {
      iterator_breathFirst.next();
    }

    BreadthFirstIterator_<Object, DefaultEdge> breadth_iterator =
        (BreadthFirstIterator_<Object, DefaultEdge>) iterator_breathFirst;

    signatures = breadth_iterator.getResultTuple();

    orderSignatures.put(currentOrder, signatures);
  }
Example #3
0
  /**
   * Initialize a created SDFAdpaterDemo with the given Graph to display
   *
   * @param graphIn The graph to display
   */
  public void init(DirectedAcyclicGraph graphIn) {

    DirectedAcyclicGraph graph = (DirectedAcyclicGraph) graphIn.clone();
    // create a JGraphT graph
    model = new DAGListenableGraph();

    // create a visualization using JGraph, via an adapter
    jgAdapter = new JGraphModelAdapter<DAGVertex, DAGEdge>(model);

    JGraph jgraph = new JGraph(jgAdapter);

    adjustDisplaySettings(jgraph);
    getContentPane().add(jgraph);
    resize(DEFAULT_SIZE);
    System.out.println(" graph has " + graph.vertexSet().size() + " vertice, including broadcast");
    for (DAGVertex vertex : graph.vertexSet()) {
      model.addVertex(vertex);
    }

    for (DAGEdge edge : graph.edgeSet()) {
      DAGEdge newEdge = model.addEdge(graph.getEdgeSource(edge), graph.getEdgeTarget(edge));
      for (String propertyKey : edge.getPropertyBean().keys()) {
        Object property = edge.getPropertyBean().getValue(propertyKey);
        newEdge.getPropertyBean().setValue(propertyKey, property);
      }
    }

    CycleDetector<DAGVertex, DAGEdge> detector = new CycleDetector<DAGVertex, DAGEdge>(model);
    GraphIterator<DAGVertex, DAGEdge> order;
    if (detector.detectCycles()) {
      order = new DAGIterator(model);
    } else {
      order = new TopologicalOrderIterator<DAGVertex, DAGEdge>(model);
    }

    Vector<DAGVertex> vertices = new Vector<DAGVertex>();
    int x = 0;
    int y = 100;
    int ymax = y;
    DAGVertex previousVertex = null;
    while (order.hasNext()) {
      DAGVertex nextVertex = order.next();
      vertices.add(nextVertex);
      if (previousVertex != null
          && model.getEdge(nextVertex, previousVertex) == null
          && model.getEdge(previousVertex, nextVertex) == null) {
        y += 50;
        this.positionVertexAt(nextVertex, x, y);
        if (y > ymax) {
          ymax = y;
        }
      } else {
        y = 100;
        x += 200;
        this.positionVertexAt(nextVertex, x, 100);
        previousVertex = nextVertex;
      }
    }

    JFrame frame = new JFrame();
    jgraph.setPreferredSize(new Dimension(x + 200, ymax + 300));
    frame.setContentPane(new ScrollPane());
    frame.getContentPane().add(this);
    frame.setTitle("DAG Transformation");
    if (adapters.size() == 1) {
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } else {
      frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
    }
    frame.pack();
    frame.setVisible(true);
  }