Package org._3pq.jgrapht.graph

Examples of org._3pq.jgrapht.graph.SimpleGraph


   */
  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


       * add edge from parent to child. This directed edge represents the visibility accessability inheritance direction.
       */
      INode parent = tmp.getParent();
      if(parent!=null) {
        dg.addVertex(parent.getIdent());
        Edge toParent = def.createEdge( parent.getIdent(),key);
        dg.addEdge(toParent);
      }
    }
View Full Code Here

        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

    tree.add (root);

    for (Iterator it1 = new BreadthFirstIterator (g, root); it1.hasNext();) {
      Object v1 = it1.next ();
      for (Iterator it2 = g.edgesOf (v1).iterator (); it2.hasNext ();) {
        Edge edge = (Edge) it2.next ();
        Object v2 = edge.oppositeVertex (v1);
          if (tree.getParent (v1) != v2) {
            tree.addNode (v1, v2);
            assert tree.getParent (v2) == v1;
          }
        }
View Full Code Here

   * @param fg
   * @return a Graph
   */
  public static UndirectedGraph mdlToGraph (FactorGraph fg)
  {
    UndirectedGraph g = new SimpleGraph ();

    for (Iterator it = fg.variablesIterator (); it.hasNext ();) {
      Variable var = (Variable) it.next ();
      g.addVertex (var);
    }

    for (Iterator it = fg.factorsIterator (); it.hasNext ();) {
      Factor factor = (Factor) it.next ();
      VarSet varSet = factor.varSet ();
      int nv = varSet.size ();
      for (int i = 0; i < nv; i++) {
        for (int j = i + 1; j < nv; j++) {
          g.addEdge (varSet.get (i), varSet.get (j));
        }
      }
    }

    return g;
View Full Code Here

  public void testMdlToGraph ()
  {
    List models = TestInference.createTestModels ();
    for (Iterator mdlIt = models.iterator (); mdlIt.hasNext ();) {
      UndirectedModel mdl = (UndirectedModel) mdlIt.next ();
      UndirectedGraph g = Graphs.mdlToGraph (mdl);
      Set vertices = g.vertexSet ();

      // check the number of vertices
      assertEquals (mdl.numVariables (), vertices.size ());

      // check the number of edges
      int numEdgePtls = 0;
      for (Iterator factorIt = mdl.factors ().iterator (); factorIt.hasNext ();) {
        Factor factor =  (Factor) factorIt.next ();
        if (factor.varSet ().size() == 2) numEdgePtls++;
      }
      assertEquals (numEdgePtls, g.edgeSet ().size ());

      // check that the neighbors of each vertex contain at least some of what they're supposed to
      Iterator it = vertices.iterator ();
      while (it.hasNext ()) {
        Variable var = (Variable) it.next ();
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

        for (Iterator it = goodEdges.iterator (); it.hasNext ();) {
          Factor factor = (Factor) it.next ();
          touchFactor (factor);
        }

        UndirectedGraph g = new SimpleGraph ();
        for (Iterator it = fullGraph.variablesIterator (); it.hasNext ();) {
          Variable var = (Variable) it.next ();
          g.addVertex (var);
        }

        for (Iterator it = goodEdges.iterator (); it.hasNext ();) {
          Factor factor = (Factor) it.next ();
          g.addVertex (factor);
          for (Iterator vit = factor.varSet ().iterator (); vit.hasNext ();) {
            Variable var = (Variable) vit.next ();
            g.addEdge (factor, var);
          }
        }

        Tree tree = graphToTree (g);
        if (reportSpanningTrees) {
View Full Code Here

  /**
   * Adds edges to graph until it is triangulated.
   */
  private void triangulate(final UndirectedGraph mdl)
  {
    UndirectedGraph mdl2 = dupGraph (mdl);
    ArrayList vars = new ArrayList(mdl.vertexSet());
    Alphabet varMap = makeVertexMap(vars);
    cliques = new ArrayList();

    // debug
    if (logger.isLoggable (Level.FINER)) {
      logger.finer ("Triangulating model: "+mdl);
      String ret = "";
      for (int i = 0; i < vars.size(); i++) {
        Variable next = (Variable) vars.get(i);
        ret += next.toString() + "\n"; // " (" + mdl.getIndex(next) + ")\n  ";
      }
      logger.finer(ret);
    }

    while (!vars.isEmpty()) {
      Variable v = (Variable) pickVertexToRemove (mdl2, vars);
      logger.finer("Triangulating vertex " + v);

      VarSet varSet = new BitVarSet (v.getUniverse (), GraphHelper.neighborListOf (mdl2, v));
      varSet.add(v);
      if (!findSuperClique(cliques, varSet)) {
        cliques.add(varSet);
        if (logger.isLoggable (Level.FINER)) {
          logger.finer ("  Elim clique " + varSet + " size " + varSet.size () + " weight " + varSet.weight ());
        }
      }

      // must remove V from graph first, because adding the edges
//  will change the rating of other vertices

      connectNeighbors (mdl2, v);
      vars.remove(v);
      mdl2.removeVertex (v);
    }

    if (logger.isLoggable(Level.FINE)) {
      logger.fine("Triangulation done. Cliques are: ");
      int totSize = 0, totWeight = 0, maxSize = 0, maxWeight = 0;
View Full Code Here

       * Essentially, this means that we triangulate factor graphs by converting to an MRF first.
       * I could have chosen to trianglualte the FactorGraph directly, but I didn't for historical reasons
       *  (I already had a version of triangulate() for MRFs, not bipartite factor graphs.)
       * Note that the call to mdlToGraph() is perfectly valid for FactorGraphs that are also DirectedModels,
       *  and has the effect of moralizing in that case.  */
      UndirectedGraph g = Graphs.mdlToGraph (mdl);
      triangulate (g);
      jtCurrent = buildJtStructure();
      mdl.setInferenceCache(JunctionTreeInferencer.class, jtCurrent);
    }

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.