Package edu.uci.ics.jung.graph

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


    }
  } 
 
  /** Makes a copy of the graph given to it and merges states in the pair supplied. */
  public static DirectedSparseGraph mergeAndDeterminize(Graph model, OrigStatePair pair){
    Graph original = (Graph)model.copy();
    Vertex q = DeterministicDirectedSparseGraph.findVertex(JUConstants.LABEL, pair.getQ().getUserDatum(JUConstants.LABEL),original);
    Vertex qDash = DeterministicDirectedSparseGraph.findVertex(JUConstants.LABEL, pair.getR().getUserDatum(JUConstants.LABEL),original);
   
    DirectedSparseGraph temp = merge((DirectedSparseGraph)original, new OrigStatePair(q,qDash));
    OrigStatePair mergable = findMergablePair(temp);
View Full Code Here


    }
  } 
 
  /** Makes a copy of the graph given to it and merges states in the pair supplied. */
  public static DirectedSparseGraph mergeAndDeterminize(Graph model, OrigStatePair pair){
    Graph original = (Graph)model.copy();
    Vertex q = DeterministicDirectedSparseGraph.findVertex(JUConstants.LABEL, pair.getQ().getUserDatum(JUConstants.LABEL),original);
    Vertex qDash = DeterministicDirectedSparseGraph.findVertex(JUConstants.LABEL, pair.getR().getUserDatum(JUConstants.LABEL),original);
   
    DirectedSparseGraph temp = merge((DirectedSparseGraph)original, new OrigStatePair(q,qDash));
    OrigStatePair mergable = findMergablePair(temp);
View Full Code Here

   * @return Graph
   * @throws IOException
   */
  public static Graph getGraph() throws IOException {

    Graph g = new DirectedSparseGraph();
    DirectedSparseVertex v1 = new DirectedSparseVertex();
    DirectedSparseVertex v2 = new DirectedSparseVertex();
    DirectedSparseVertex v3 = new DirectedSparseVertex();
    DirectedSparseVertex v4 = new DirectedSparseVertex();
    v1.setUserDatum("ID", "123", UserData.SHARED);
    v1.setUserDatum("Name","v1Name",UserData.SHARED);
    v1.setUserDatum("Description", "Node 1 Description", UserData.SHARED);
    v1.setUserDatum("Deepness", 2,UserData.SHARED);
    v2.setUserDatum("ID", "456", UserData.SHARED);
    v2.setUserDatum("Name","v2Name",UserData.SHARED);
    v2.setUserDatum("Description", "Node 2 Description", UserData.SHARED);
    v2.setUserDatum("Deepness", 2,UserData.SHARED);
    v3.setUserDatum("ID", "789", UserData.SHARED);
    v3.setUserDatum("Name","v3Name",UserData.SHARED);
    v3.setUserDatum("Description", "Node 3 Description", UserData.SHARED);
    v3.setUserDatum("Deepness", 2,UserData.SHARED);
    v4.setUserDatum("ID", "444", UserData.SHARED);
    v4.setUserDatum("Name","v4Name",UserData.SHARED);
    v4.setUserDatum("Description", "Node 4 Description", UserData.SHARED);
    v4.setUserDatum("Deepness", 1,UserData.SHARED);
    g.addVertex(v1);
    g.addVertex(v2);
    g.addVertex(v3);
    g.addVertex(v4);
    Edge e12 = new DirectedSparseEdge(v1, v2);
    e12.setUserDatum("ID", "12", UserData.SHARED);
    e12.setUserDatum("Name", "myEdge12", UserData.SHARED);
    e12.setUserDatum("Description", "myEdge 12 description", UserData.SHARED);
    e12.setUserDatum("Deepness", 2, UserData.SHARED);
    g.addEdge(e12);
    Edge e23 = new DirectedSparseEdge(v2, v3);
    e23.setUserDatum("ID", "23", UserData.SHARED);
    e23.setUserDatum("Name", "myEdge23", UserData.SHARED);
    e23.setUserDatum("Description", "myEdge 23 description", UserData.SHARED);
    e23.setUserDatum("Deepness", 1, UserData.SHARED);
    g.addEdge(e23);
    Edge e13 = new DirectedSparseEdge(v1, v3);
    e13.setUserDatum("ID", "13", UserData.SHARED);
    e13.setUserDatum("Name", "myEdge13", UserData.SHARED);
    e13.setUserDatum("Description", "myEdge 13 description", UserData.SHARED);
    e13.setUserDatum("Deepness", 1, UserData.SHARED);
    g.addEdge(e13);
    Edge e34= new DirectedSparseEdge(v3,v4);
    e34.setUserDatum("ID", "34", UserData.SHARED);
    e34.setUserDatum("Name", "myEdge34", UserData.SHARED);
    e34.setUserDatum("Description", "myEdge 34 description", UserData.SHARED);
    e34.setUserDatum("Deepness", 1, UserData.SHARED);
    g.addEdge(e34);
    return g;
  }
View Full Code Here

        return new FRLayout(g);
    }

    public void drawGraph() {
        try {
            final Graph g = cm.getGraph();
            final AggregateLayout<Node, String> layout = new AggregateLayout<Node, String>(layoutFactory(cm.getLayout(), g));


            if (vv == null) {
                //springlayout and 2, FRlayout
View Full Code Here

   * @see org.wymiwyg.rwcf.Handler#handle(org.wymiwyg.wrhapi.Request,
   *      org.wymiwyg.rwcf.Response, org.wymiwyg.rwcf.HandlerChain)
   */
  public void handle(Request request, Response response, HandlerChain chain)
      throws HandlerException {
    Graph g = getGraph();

    GraphDraw gd = new GraphDraw(g);
    gd.setSize((int) (Math.log(g.numVertices()) * 180), (int) (Math.log(g
        .numVertices()) * 180.0));
    //gd.setGraphLayout(new FRLayout(g));
    //gd.setGraphLayout(new SpringLayout(g));
    //gd.setGraphLayout(new CircleLayout(g));
    gd.setGraphLayout(new ISOMLayout(g));
    //gd.setLayout(SpringLayout.)
    gd.addNotify();
    gd.setSize((int) (Math.log(g.numVertices()) * 180), (int) (Math.log(g
        .numVertices()) * 180.0));
    gd.validate();
    PipedOutputStream out = new PipedOutputStream();
    PipedInputStream pipedIn;
    try {
View Full Code Here

    }.start();
  }

  private Graph getGraph() {
    //PajekNetFile file = new PajekNetFile();
    Graph g = new DirectedSparseGraph(); //file.load(new
    // InputStreamReader(Test.class.getResourceAsStream("simple.net")));
    ResIterator topicsIter = model.listSubjectsWithProperty(RDF.type,
        KNOBOT.Topic);
    Map vertexTopic = new HashMap();
    while (topicsIter.hasNext()) {
      Resource element = topicsIter.nextResource();
      Vertex vertex = (Vertex) g.addVertex(new DirectedSparseVertex());
      vertexTopic.put(element, vertex);
      vertex.addUserDatum("label", element.getURI(), UserData.SHARED);
    }
    Iterator vertexIter = vertexTopic.keySet().iterator();
    Map allTopicsAndItems = new HashMap();
    allTopicsAndItems.putAll(vertexTopic);
    while (vertexIter.hasNext()) {
      Resource currentSource = (Resource) vertexIter.next();
      ResIterator relationIter = model.listSubjectsWithProperty(
          KNOBOT.source, currentSource);
      while (relationIter.hasNext()) {
        Resource currentRelations = (Resource) relationIter
            .nextResource();
        float relevance = currentRelations.getProperty(KNOBOT.strength)
            .getFloat();
        if (relevance < 0.001) {
          continue;
        }
        Resource target = currentRelations.getProperty(KNOBOT.target)
            .getResource();
        Vertex targetVertex = (Vertex) vertexTopic.get(target);
        if (targetVertex != null) {
          DirectedEdge e = (DirectedEdge) g
              .addEdge(new DirectedSparseEdge(
                  (Vertex) vertexTopic.get(currentSource),
                  targetVertex));
        } else {
          //is an item

          Vertex vertex;
          vertex = (Vertex) allTopicsAndItems.get(target);
          if (vertex == null) {
            vertex = (Vertex) g
                .addVertex(new DirectedSparseVertex());
            vertex.addUserDatum("label", target.getURI(),
                UserData.SHARED);
            allTopicsAndItems.put(target, vertex);
          }
          DirectedEdge e = (DirectedEdge) g
              .addEdge(new DirectedSparseEdge(
                  (Vertex) vertexTopic.get(currentSource),
                  vertex));
        }
      }

      //new SpringLayout(g);
    }

    /*
     * Vertex v1 = (Vertex) g.addVertex(new DirectedSparseVertex());
     * v1.addUserDatum("label","v1",UserData.SHARED); Vertex v2 = (Vertex)
     * g.addVertex(new DirectedSparseVertex());
     * v2.addUserDatum("label","http://www.example.org/v2",UserData.SHARED);
     */
    StringLabeller sl = StringLabeller.getLabeller(g);
    char c = 0;
    for (Iterator iter = g.getVertices().iterator(); iter.hasNext();) {
      Vertex v = (Vertex) iter.next();
      try {
        sl.setLabel(v, v.getUserDatum("label").toString());
      } catch (UniqueLabelException ex) {
        log.error(ex);
View Full Code Here

   
    public Graph collapse(Graph inGraph, Graph clusterGraph) {
       
        if(clusterGraph.getVertexCount() < 2) return inGraph;

        Graph graph = inGraph;
        try {
            graph = createGraph();
        } catch(Exception ex) {
            ex.printStackTrace();
        }
        Collection cluster = clusterGraph.getVertices();
       
        // add all vertices in the delegate, unless the vertex is in the
        // cluster.
        for(Object v : inGraph.getVertices()) {
            if(cluster.contains(v) == false) {
                graph.addVertex(v);
            }
        }
        // add the clusterGraph as a vertex
        graph.addVertex(clusterGraph);
       
        //add all edges from the inGraph, unless both endpoints of
        // the edge are in the cluster
        for(Object e : (Collection<?>)inGraph.getEdges()) {
            Pair endpoints = inGraph.getEndpoints(e);
            // don't add edges whose endpoints are both in the cluster
            if(cluster.containsAll(endpoints) == false) {

                if(cluster.contains(endpoints.getFirst())) {
                  graph.addEdge(e, clusterGraph, endpoints.getSecond(), inGraph.getEdgeType(e));

                } else if(cluster.contains(endpoints.getSecond())) {
                  graph.addEdge(e, endpoints.getFirst(), clusterGraph, inGraph.getEdgeType(e));

                } else {
                  graph.addEdge(e,endpoints.getFirst(), endpoints.getSecond(), inGraph.getEdgeType(e));
                }
            }
        }
        return graph;
    }
View Full Code Here

        }
        return graph;
    }
   
    public Graph expand(Graph inGraph, Graph clusterGraph) {
        Graph graph = inGraph;
        try {
            graph = createGraph();
        } catch(Exception ex) {
            ex.printStackTrace();
        }
        Collection cluster = clusterGraph.getVertices();
        logger.fine("cluster to expand is "+cluster);

        // put all clusterGraph vertices and edges into the new Graph
        for(Object v : cluster) {
            graph.addVertex(v);
            for(Object edge : clusterGraph.getIncidentEdges(v)) {
                Pair endpoints = clusterGraph.getEndpoints(edge);
                graph.addEdge(edge, endpoints.getFirst(), endpoints.getSecond(), clusterGraph.getEdgeType(edge));
            }
        }
        // add all the vertices from the current graph except for
        // the cluster we are expanding
        for(Object v : inGraph.getVertices()) {
            if(v.equals(clusterGraph) == false) {
                graph.addVertex(v);
            }
        }

        // now that all vertices have been added, add the edges,
        // ensuring that no edge contains a vertex that has not
        // already been added
        for(Object v : inGraph.getVertices()) {
            if(v.equals(clusterGraph) == false) {
                for(Object edge : inGraph.getIncidentEdges(v)) {
                    Pair endpoints = inGraph.getEndpoints(edge);
                    Object v1 = endpoints.getFirst();
                    Object v2 = endpoints.getSecond();
                     if(cluster.containsAll(endpoints) == false) {
                        if(clusterGraph.equals(v1)) {
                            // i need a new v1
                            Object originalV1 = originalGraph.getEndpoints(edge).getFirst();
                            Object newV1 = findVertex(graph, originalV1);
                            assert newV1 != null : "newV1 for "+originalV1+" was not found!";
                            graph.addEdge(edge, newV1, v2, inGraph.getEdgeType(edge));
                        } else if(clusterGraph.equals(v2)) {
                            // i need a new v2
                            Object originalV2 = originalGraph.getEndpoints(edge).getSecond();
                            Object newV2 = findVertex(graph, originalV2);
                            assert newV2 != null : "newV2 for "+originalV2+" was not found!";
                            graph.addEdge(edge, v1, newV2, inGraph.getEdgeType(edge));
                        } else {
                          graph.addEdge(edge, v1, v2, inGraph.getEdgeType(edge));
                        }
                    }
                }
            }
        }
View Full Code Here

        if(vertices.contains(vertex)) {
            return vertex;
        }
        for(Object v : vertices) {
            if(v instanceof Graph) {
                Graph g = (Graph)v;
                if(contains(g, vertex)) {
                    return v;
                }
            }
        }
View Full Code Here

      }
      return contained;
    }
   
    public Graph getClusterGraph(Graph inGraph, Collection picked) {
        Graph clusterGraph;
        try {
            clusterGraph = createGraph();
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }
        for(Object v : picked) {
          clusterGraph.addVertex(v);
            Collection edges = inGraph.getIncidentEdges(v);
            for(Object edge : edges) {
                Pair endpoints = inGraph.getEndpoints(edge);
                Object v1 = endpoints.getFirst();
                Object v2 = endpoints.getSecond();
                if(picked.containsAll(endpoints)) {
                    clusterGraph.addEdge(edge, v1, v2, inGraph.getEdgeType(edge));
                }
            }
        }
        return clusterGraph;
    }
View Full Code Here

TOP

Related Classes of edu.uci.ics.jung.graph.Graph

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.