Examples of UndirectedGraph


Examples of edu.uci.ics.jung.graph.UndirectedGraph

        }
    }

    static UndirectedGraph composeGraph(File inFile) throws Exception {
        UndirectedGraph graph = new UndirectedSparseGraph<AuthorNode, RefLink>();
        List<String> lines = IOUtils.readLines(new FileInputStream(inFile));
        for (String line : lines) {
           
            char[] spaceTest = new char[line.length()/2]     ;              
                     for (int i=0,j=0;i<line.length();i++) {
View Full Code Here

Examples of org._3pq.jgrapht.UndirectedGraph

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

Examples of org._3pq.jgrapht.UndirectedGraph

  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

Examples of org._3pq.jgrapht.UndirectedGraph

  }

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

Examples of org._3pq.jgrapht.UndirectedGraph

        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

Examples of org._3pq.jgrapht.UndirectedGraph

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

Examples of org._3pq.jgrapht.UndirectedGraph

       * 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

Examples of org._3pq.jgrapht.UndirectedGraph

    return jtCurrent;
  }

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

Examples of org.gephi.graph.api.UndirectedGraph

                    }
                    Progress.progress(progressTicket);
                    writer.append(EOL);
                }
            } else if (graph instanceof UndirectedGraph) {
                UndirectedGraph undirectedGraph = (UndirectedGraph) graph;
                Node[] nodes = graph.getNodes().toArray();
                for (Node n : nodes) {
                    if (cancel) {
                        break;
                    }
                    writeMatrixNode(n, true);
                    for (int j = 0; j < nodes.length; j++) {
                        Node m = nodes[j];
                        Edge e = undirectedGraph.getEdge(n, m);
                        e = e == null ? ((HierarchicalUndirectedGraph) undirectedGraph).getMetaEdge(n, m) : e;
                        writeEdge(e, j < nodes.length - 1);
                    }
                    Progress.progress(progressTicket);
                    writer.append(EOL);
View Full Code Here

Examples of org.gephi.graph.api.UndirectedGraph

 
  
   @Test
    public void testSpecial1UndirectedGraphClusteringCoefficient() {
        GraphModel graphModel=Lookup.getDefault().lookup(GraphController.class).getGraphModel();
        UndirectedGraph undirectedGraph=graphModel.getUndirectedGraph();
        Node node1=graphModel.factory().newNode("0");
        Node node2=graphModel.factory().newNode("1");
        Node node3=graphModel.factory().newNode("2");
        Node node4=graphModel.factory().newNode("3");
        Node node5=graphModel.factory().newNode("4");
        Node node6=graphModel.factory().newNode("5");
        Node node7=graphModel.factory().newNode("6");
        undirectedGraph.addNode(node1);
        undirectedGraph.addNode(node2);
        undirectedGraph.addNode(node3);
        undirectedGraph.addNode(node4);
        undirectedGraph.addNode(node5);
        undirectedGraph.addNode(node6);
        undirectedGraph.addNode(node7);
        Edge edge12=graphModel.factory().newEdge(node1, node2, false);
        Edge edge13=graphModel.factory().newEdge(node1, node3, false);
        Edge edge14=graphModel.factory().newEdge(node1, node4, false);
        Edge edge15=graphModel.factory().newEdge(node1, node5, false);
        Edge edge16=graphModel.factory().newEdge(node1, node6, false);
        Edge edge17=graphModel.factory().newEdge(node1, node7, false);
        Edge edge23=graphModel.factory().newEdge(node2, node3, false);
        Edge edge34=graphModel.factory().newEdge(node3, node4, false);
        Edge edge45=graphModel.factory().newEdge(node4, node5, false);
        Edge edge56=graphModel.factory().newEdge(node5, node6, false);
        Edge edge67=graphModel.factory().newEdge(node6, node7, false);
        Edge edge72=graphModel.factory().newEdge(node7, node2, false);
        undirectedGraph.addEdge(edge12);
        undirectedGraph.addEdge(edge13);
        undirectedGraph.addEdge(edge14);
        undirectedGraph.addEdge(edge15);
        undirectedGraph.addEdge(edge16);
        undirectedGraph.addEdge(edge17);
        undirectedGraph.addEdge(edge23);
        undirectedGraph.addEdge(edge34);
        undirectedGraph.addEdge(edge45);
        undirectedGraph.addEdge(edge56);
        undirectedGraph.addEdge(edge67);
        undirectedGraph.addEdge(edge72);
       
        Graph hgraph = graphModel.getGraph();
        ClusteringCoefficient cc = new ClusteringCoefficient();

        ArrayWrapper[] network = new ArrayWrapper[7];
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.