Package org._3pq.jgrapht.graph

Examples of org._3pq.jgrapht.graph.SimpleGraph


    return jtCurrent;
  }

  private UndirectedGraph dupGraph (UndirectedGraph original)
  {
    UndirectedGraph copy = new SimpleGraph ();
    GraphHelper.addGraph (copy, original);
    return copy;
  }
View Full Code Here


  //xxx Insanely inefficient stub
  public boolean isConnected (Variable v1, Variable v2)
  {
    UndirectedGraph g = Graphs.mdlToGraph (this);
    ConnectivityInspector ins = new ConnectivityInspector (g);
    return g.containsVertex (v1) && g.containsVertex (v2) && ins.pathExists (v1, v2);
  }
View Full Code Here

      checkForNoCycle (parents, child, cpt);
    }
  }

  private void checkForNoCycle (VarSet parents, Variable child, CPT cpt) {
    ConnectivityInspector inspector = new ConnectivityInspector (graph);
    for (Iterator it = parents.iterator (); it.hasNext ();) {
      Variable rent = (Variable) it.next ();
      if (inspector.pathExists (child, rent)) {
        throw new IllegalArgumentException ("Error adding CPT: Would create directed cycle"+
                        "From: "+rent+" To:"+child+"\nCPT: "+cpt);
      }
    }
  }
View Full Code Here

    for (Iterator it = cliques.iterator(); it.hasNext();) {
      VarSet c = (VarSet) it.next();
      g.addVertex (c);
    }

    ConnectivityInspector inspector = new ConnectivityInspector (g);
    g.addGraphListener (inspector);
   
    // then add n - 1 edges
    int numCliques = cliques.size();
    int edgesAdded = 0;
    while (edgesAdded < numCliques - 1) {
      VarSet[] pair = (VarSet[]) pq.first();
      pq.remove(pair);

      if (!inspector.pathExists(pair[0], pair[1])) {
          g.addEdge(pair[0], pair[1]);
          edgesAdded++;
      }
    }
View Full Code Here

    }
    /*
     * find the id's participating in the cycle, and return the intersection
     * with set of id's which actually produce references.
     */
    CycleDetector cd = new CycleDetector(dg);
    Set<String> cycleIds = cd.findCycles();
    cycleIds.retainAll(nodeRefs.keySet());
    return cycleIds;
  }
View Full Code Here

  public Set<String> listCycles() {
    /*
     * convert nodeRefs datastructure to a directed graph
     */
    DirectedGraph dg = new DefaultDirectedGraph();
    DirectedEdgeFactory def = new EdgeFactories.DirectedEdgeFactory();
    /*
     * add the course structure as directed graph, where
     */
    Visitor v = new Convert2DGVisitor(dg);
    (new TreeVisitor(v, cetm.getRootNode(), true)).visitAll();
    /*
     * iterate over nodeRefs, add each not existing node id as vertex, for each
     * key - child relation add an edge to the directed graph.
     */
    Iterator<String> keys = nodeRefs.keySet().iterator();
    while(keys.hasNext()) {
      //a node
      String key = keys.next();
      if(!dg.containsVertex(key)) {
        dg.addVertex(key);
      }
      //and its children
      Set<String> children = nodeRefs.get(key);
      Iterator<String> childrenIt = children.iterator();
      while(childrenIt.hasNext()){
        String child = childrenIt.next();
        if(!dg.containsVertex(child)) {
          dg.addVertex(child);
        }
        //add edge, precondition: vertex key - child are already added to the graph
        Edge de = def.createEdge(key, child);
        dg.addEdge(de);
      }
    }
    /*
     * find the id's participating in the cycle, and return the intersection
View Full Code Here

        graph.addEdge(parentStack.get(0), node);
    }

    private JGraph createJGraph() {
        // create a visualization using JGraph, via an adapter
        JGraphModelAdapter m_jgAdapter = new JGraphModelAdapter(graph, JGraphModelAdapter.createDefaultVertexAttributes(), createDefaultEdgeAttributes());
        this.jgraph = new JGraph(m_jgAdapter);
        // layout setting
        JGraphUtils.applyOrderedTreeLayout(graph, m_jgAdapter, jgraph);
        // vertex color setting
        Iterator vertexIter = graph.vertexSet().iterator();
        while(vertexIter.hasNext()) {
            String vertex = (String) vertexIter.next();
            if(vertex.indexOf("QuantifiedExpr") > 0 || vertex.indexOf("FLWRExpr") > 0
                    || vertex.indexOf("PromoteJoinExpression") > 0) {
                DefaultGraphCell cell = m_jgAdapter.getVertexCell(vertex);
                AttributeMap attr = cell.getAttributes();
                GraphConstants.setBackground(attr, RED_NODE_COLOR);
                AttributeMap cellAttr = new AttributeMap();
                cellAttr.put(cell, attr);
                m_jgAdapter.edit(cellAttr, null, null, null);
            } else if(vertex.indexOf("DistinctSortExpr") > 0) {
                DefaultGraphCell cell = m_jgAdapter.getVertexCell(vertex);
                AttributeMap attr = cell.getAttributes();
                GraphConstants.setBackground(attr, GREEN_NODE_COLOR);
                AttributeMap cellAttr = new AttributeMap();
                cellAttr.put(cell, attr);
                m_jgAdapter.edit(cellAttr, null, null, null);
            } else if(vertex.indexOf("PathIndexAccessExpr") > 0) {
                DefaultGraphCell cell = m_jgAdapter.getVertexCell(vertex);
                AttributeMap attr = cell.getAttributes();
                GraphConstants.setBackground(attr, BLUE_NODE_COLOR);
                AttributeMap cellAttr = new AttributeMap();
                cellAttr.put(cell, attr);
                m_jgAdapter.edit(cellAttr, null, null, null);
            }
        }
        // mouseClicked event handling
        jgraph.addMouseListener(new MyMouseListener());
        return jgraph;
View Full Code Here

    // -------------------------------------

    public GraphConstructionVisitor(StaticContext statEnv) {
        // create a JGraphT graph
        this.graph = new DefaultDirectedGraph();
        this.statEnv = statEnv;
    }
View Full Code Here

        this.graph = new DefaultDirectedGraph();
        this.statEnv = statEnv;
    }

    private void reset() {
        this.graph = new DefaultDirectedGraph();
        parentStack.clear();
        sourceExprMap.clear();
        visitedVarNames.clear();
    }
View Full Code Here

   */
  public Set<String> listCycles() {
    /*
     * convert nodeRefs datastructure to a directed graph
     */
    DirectedGraph dg = new DefaultDirectedGraph();
    DirectedEdgeFactory def = new EdgeFactories.DirectedEdgeFactory();
    /*
     * add the course structure as directed graph, where
     */
    Visitor v = new Convert2DGVisitor(dg);
    (new TreeVisitor(v, cetm.getRootNode(), true)).visitAll();
    /*
     * iterate over nodeRefs, add each not existing node id as vertex, for each
     * key - child relation add an edge to the directed graph.
     */
    Iterator<String> keys = nodeRefs.keySet().iterator();
    while(keys.hasNext()) {
      //a node
      String key = keys.next();
      if(!dg.containsVertex(key)) {
        dg.addVertex(key);
      }
      //and its children
      Set<String> children = nodeRefs.get(key);
      Iterator<String> childrenIt = children.iterator();
      while(childrenIt.hasNext()){
        String child = childrenIt.next();
        if(!dg.containsVertex(child)) {
          dg.addVertex(child);
        }
        //add edge, precondition: vertex key - child are already added to the graph
        Edge de = def.createEdge(key, child);
        dg.addEdge(de);
      }
    }
    /*
     * find the id's participating in the cycle, and return the intersection
     * with set of id's which actually produce references.
View Full Code Here

TOP

Related Classes of org._3pq.jgrapht.graph.SimpleGraph

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.