示例#1
0
  /**
   * Constructs a new JGraph model adapter for the specified JGraphT graph.
   *
   * @param jGraphTGraph the JGraphT graph for which JGraph model adapter to be created. <code>null
   *     </code> is NOT permitted.
   * @param defaultVertexAttributes a default map of JGraph attributes to format vertices. <code>
   *     null</code> is NOT permitted.
   * @param defaultEdgeAttributes a default map of JGraph attributes to format edges. <code>null
   *     </code> is NOT permitted.
   * @param cellFactory a {@link CellFactory} to be used to create the JGraph cells. <code>null
   *     </code> is NOT permitted.
   * @throws IllegalArgumentException
   */
  public JGraphModelAdapter(
      Graph<V, E> jGraphTGraph,
      AttributeMap defaultVertexAttributes,
      AttributeMap defaultEdgeAttributes,
      CellFactory<V, E> cellFactory) {
    super();

    if ((jGraphTGraph == null)
        || (defaultVertexAttributes == null)
        || (defaultEdgeAttributes == null)
        || (cellFactory == null)) {
      throw new IllegalArgumentException("null is NOT permitted");
    }

    jtGraph = new ShieldedGraph(jGraphTGraph);
    setDefaultVertexAttributes(defaultVertexAttributes);
    setDefaultEdgeAttributes(defaultEdgeAttributes);
    this.cellFactory = cellFactory;

    if (jGraphTGraph instanceof ListenableGraph<?, ?>) {
      ListenableGraph<V, E> g = (ListenableGraph<V, E>) jGraphTGraph;
      g.addGraphListener(new JGraphTListener());
    }

    for (Iterator<V> i = jGraphTGraph.vertexSet().iterator(); i.hasNext(); ) {
      handleJGraphTAddedVertex(i.next());
    }

    for (Iterator<E> i = jGraphTGraph.edgeSet().iterator(); i.hasNext(); ) {
      handleJGraphTAddedEdge(i.next());
    }

    this.addGraphModelListener(new JGraphListener());
  }
示例#2
0
    E addEdge(V jtSource, V jtTarget) {
      E jtEdge = graph.getEdgeFactory().createEdge(jtSource, jtTarget);
      jtElementsBeingAdded.add(jtEdge);

      boolean added = graph.addEdge(jtSource, jtTarget, jtEdge);
      jtElementsBeingAdded.remove(jtEdge);

      return added ? jtEdge : null;
    }
示例#3
0
  private void calcStats() {
    //        Graph resultGraph = getAlgorithmRunner().getResultGraph();
    IGesRunner runner = (IGesRunner) getAlgorithmRunner();

    if (runner.getTopGraphs().isEmpty()) {
      throw new IllegalArgumentException(
          "No patterns were recorded. Please adjust the number of " + "patterns to store.");
    }

    Graph resultGraph = runner.getTopGraphs().get(runner.getIndex()).getGraph();

    if (getAlgorithmRunner().getDataModel() instanceof DataSet) {

      // resultGraph may be the output of a PC search.
      // Such graphs sometimes contain doubly directed edges.

      // /We converte such edges to directed edges here.
      // For the time being an orientation is arbitrarily selected.
      Set<Edge> allEdges = resultGraph.getEdges();

      for (Edge edge : allEdges) {
        if (edge.getEndpoint1() == Endpoint.ARROW && edge.getEndpoint2() == Endpoint.ARROW) {
          // Option 1 orient it from node1 to node2
          resultGraph.setEndpoint(edge.getNode1(), edge.getNode2(), Endpoint.ARROW);

          // Option 2 remove such edges:
          resultGraph.removeEdge(edge);
        }
      }

      Pattern pattern = new Pattern(resultGraph);
      PatternToDag ptd = new PatternToDag(pattern);
      Graph dag = ptd.patternToDagMeekRules();

      DataSet dataSet = (DataSet) getAlgorithmRunner().getDataModel();
      String report;

      if (dataSet.isContinuous()) {
        report = reportIfContinuous(dag, dataSet);
      } else if (dataSet.isDiscrete()) {
        report = reportIfDiscrete(dag, dataSet);
      } else {
        throw new IllegalArgumentException("");
      }

      JScrollPane dagWorkbenchScroll = dagWorkbenchScroll(dag);
      modelStatsText.setLineWrap(true);
      modelStatsText.setWrapStyleWord(true);
      modelStatsText.setText(report);

      removeStatsTabs();
      tabbedPane.addTab("DAG in pattern", dagWorkbenchScroll);
      tabbedPane.addTab("DAG Model Statistics", modelStatsText);
    }
  }
示例#4
0
  private void uncorrelationExogenousVariables() {
    Graph graph = getWorkbench().getGraph();

    Set<Edge> edges = graph.getEdges();

    for (Edge edge : edges) {
      if (Edges.isBidirectedEdge(edge)) {
        try {
          graph.removeEdge(edge);
        } catch (Exception e) {
          // Ignore.
        }
      }
    }
  }
示例#5
0
  protected void fileOpen() {
    JFileChooser chooser = null;
    if (currentFile == null) {
      chooser = new JFileChooser(startDirectory);
    } else {
      chooser = new JFileChooser(currentFile);
    }

    int returnVal = chooser.showOpenDialog(gw);
    if (returnVal == JFileChooser.APPROVE_OPTION) {

      graph.clear();
      currentFile = chooser.getSelectedFile();
      graph.loadAll(currentFile);
      gp.update(gp.getGraphics());
    }
  }
示例#6
0
 public void init() {
   //		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   for (Iterator<Arc> itr = graph.findArcs().iterator(); itr.hasNext(); ) {
     arcListModel.addElement(itr.next());
   }
   panel = new DrawViewPanel();
   this.getContentPane().add(panel);
 }
示例#7
0
 protected void fileNew() {
   if (currentFile != null) {
     if (!currentFile.isDirectory()) {
       currentFile = currentFile.getParentFile();
     }
   }
   graph.clear();
   gp.update(gp.getGraphics());
 }
示例#8
0
  public static void main(String[] args) {

    if (args.length != 1) {
      System.out.println("Usage: java Msp <filename>");
      System.exit(2);
    }
    Graph g = new Graph();
    loadFile(g, args[0]);

    // Calculate locations of nodes
    g.prepareNodes();
    // Perform kruskal algorithm
    g.kruskal();

    // Show results in JFrame
    MainWindow f = new MainWindow(g);
    f.setSize(800, 600);
    f.setVisible(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
示例#9
0
 protected void fileSave() {
   if (currentFile == null) {
     fileSaveAs();
   } else {
     if (currentFile.isDirectory()) {
       fileSaveAs();
     } else {
       graph.saveAll(currentFile);
       gp.update(gp.getGraphics());
     }
   }
 }
示例#10
0
  private void correlateExogenousVariables() {
    Graph graph = getWorkbench().getGraph();

    if (graph instanceof Dag) {
      JOptionPane.showMessageDialog(
          JOptionUtils.centeringComp(), "Cannot add bidirected edges to DAG's.");
      return;
    }

    List<Node> nodes = graph.getNodes();

    List<Node> exoNodes = new LinkedList<Node>();

    for (int i = 0; i < nodes.size(); i++) {
      Node node = nodes.get(i);
      if (graph.isExogenous(node)) {
        exoNodes.add(node);
      }
    }

    for (int i = 0; i < exoNodes.size(); i++) {

      loop:
      for (int j = i + 1; j < exoNodes.size(); j++) {
        Node node1 = exoNodes.get(i);
        Node node2 = exoNodes.get(j);
        List<Edge> edges = graph.getEdges(node1, node2);

        for (int k = 0; k < edges.size(); k++) {
          Edge edge = edges.get(k);
          if (Edges.isBidirectedEdge(edge)) {
            continue loop;
          }
        }

        graph.addBidirectedEdge(node1, node2);
      }
    }
  }
示例#11
0
 public static void loadFile(Graph g, String fileName) {
   System.out.println("Reading date from " + fileName);
   try {
     BufferedReader input = new BufferedReader(new FileReader(fileName));
     try {
       String line = null;
       int index = 0;
       System.out.println("Graph...");
       while ((line = input.readLine()) != null) {
         if (line.trim().equals("#EDGES")) break;
         String[] arr = line.split(" ");
         System.out.println("Graph Line " + index + ":  " + line);
         Vertex n = null;
         Vertex node = null;
         for (int j = 0; j < arr.length; j++) {
           n = new Vertex(arr[j]);
           node = g.findNode(n);
           if (node == null) g.addNode(n, index);
         }
         index++;
       }
       System.out.println("Edges...");
       while ((line = input.readLine()) != null) {
         String[] arr = line.split(" ");
         System.out.println("[" + arr[0] + " - " + arr[1] + "] - Cost: " + arr[2]);
         Vertex n = new Vertex(arr[0]);
         Vertex left = g.findNode(n);
         n = new Vertex(arr[1]);
         Vertex right = g.findNode(n);
         g.addEdge(left, right, Integer.parseInt(arr[2]));
       }
     } finally {
       input.close();
     }
   } catch (Exception e) {
   }
 }
示例#12
0
 protected void fileSaveSimple() {
   JFileChooser chooser = null;
   if (currentFile == null) {
     chooser = new JFileChooser(startDirectory);
   } else {
     chooser = new JFileChooser(currentFile);
     if (!currentFile.isDirectory()) {
       chooser.setSelectedFile(currentFile);
     }
   }
   int returnVal = chooser.showSaveDialog(gw);
   if (returnVal == JFileChooser.APPROVE_OPTION) {
     currentFile = chooser.getSelectedFile();
     graph.saveSimple(currentFile);
   }
 }
示例#13
0
  public GraphViewer(Graph g, int options) {
    graph = g;
    graph.addListener(this);
    nodeListModel = new DefaultListModel<Node>();
    setViewOptions(options);
    layouter = new GraphLayouter(graph, new Point2D.Double());
    layouter.makeLayout();
    if (hasOption(VIEW_3D | VIEW_WF)) {
      layouterWF3D = new GraphLayouter3D(graph);
      layouterWF3D.makeLayout();
    }
    //		addNodes();
    //		layouter.makeLayout();
    //		layouterWF3D.makeLayout();

    init();
    //		remove adding nodes, read them from file instead
    //		addNodes();

  }
示例#14
0
 V getEdgeSource(E e) {
   return graph.getEdgeSource(e);
 }
示例#15
0
 void removeVertex(V jtVertex) {
   jtElementsBeingRemoved.add(jtVertex);
   graph.removeVertex(jtVertex);
   jtElementsBeingRemoved.remove(jtVertex);
 }
示例#16
0
 void removeEdge(E jtEdge) {
   jtElementsBeingRemoved.add(jtEdge);
   graph.removeEdge(jtEdge);
   jtElementsBeingRemoved.remove(jtEdge);
 }
示例#17
0
 boolean removeAllEdges(Collection<E> edges) {
   return graph.removeAllEdges(edges);
 }
示例#18
0
 Set<E> edgesOf(V vertex) {
   return graph.edgesOf(vertex);
 }
示例#19
0
 void addVertex(V jtVertex) {
   jtElementsBeingAdded.add(jtVertex);
   graph.addVertex(jtVertex);
   jtElementsBeingAdded.remove(jtVertex);
 }
示例#20
0
 V getEdgeTarget(E e) {
   return graph.getEdgeTarget(e);
 }
示例#21
0
 protected void editSelectAll() {
   gp.getSelection().addNodes(graph.getNodes());
   gp.getSelection().addEdges(graph.getEdges());
   gp.repaint();
 }