當前位置: 首頁>>代碼示例>>Java>>正文


Java Graph類代碼示例

本文整理匯總了Java中edu.uci.ics.jung.graph.Graph的典型用法代碼示例。如果您正苦於以下問題:Java Graph類的具體用法?Java Graph怎麽用?Java Graph使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Graph類屬於edu.uci.ics.jung.graph包,在下文中一共展示了Graph類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testGetGraph

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
@Test
public void testGetGraph() {
	Topology topology = new Topology();
	topology.addEdge("1", "2", new Edge());
	topology.addEdge("2", "3", new Edge());
	Graph<String, Edge> graph = JUNGConverter.getGraph(topology);
	assertNotNull(graph);
}
 
開發者ID:fnss,項目名稱:fnss-java,代碼行數:9,代碼來源:JUNGConverterTest.java

示例2: testUnreachable

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
@Test
public void testUnreachable() {
	Graph<String, MyLink> g = new DirectedOrderedSparseMultigraph<String, MyLink>();

	String n1 = new String("S"); // S
	g.addVertex(n1);
	String n2 = new String("A"); // A
	g.addVertex(n2);
	String n3 = new String("B"); // B -- not connected
	g.addVertex(n3);

	g.addEdge(new MyLink(1, "S-A"), n1, n2, EdgeType.DIRECTED); // S - A

	Transformer<MyLink, Number> weightTrans = new Transformer<MyLink, Number>() {
		@Override
		public Number transform(MyLink link) {
			return link.getWeight();
		}
	};
	SuurballeTarjan<String, MyLink> testMain = new SuurballeTarjan<String, MyLink>(
			g, weightTrans);
	assertEquals(null, testMain.getDisjointPaths(n1, n3));
}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:24,代碼來源:SuurballeTarjanTest.java

示例3: testNoDisjointSolution

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
@Test
public void testNoDisjointSolution() {
	Graph<String, MyLink> g = new DirectedOrderedSparseMultigraph<String, MyLink>();

	String n1 = new String("A"); // A
	g.addVertex(n1);
	String n2 = new String("B"); // B
	g.addVertex(n2);

	g.addEdge(new MyLink(2, "A-B"), n1, n2, EdgeType.DIRECTED);

	Transformer<MyLink, Number> weightTrans = new Transformer<MyLink, Number>() {
		@Override
		public Number transform(MyLink link) {
			return link.getWeight();
		}
	};
	SuurballeTarjan<String, MyLink> testMain = new SuurballeTarjan<String, MyLink>(
			g, weightTrans);
	assertEquals("[[A-B]]", testMain.getDisjointPaths(n1, n2).toString());
}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:22,代碼來源:SuurballeTarjanTest.java

示例4: eppsteinExample

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
@Test
public void eppsteinExample() {
	KspTestScenario<String, MyLink> scenario = KspTestScenarios
			.getEppsteinScenario();
	Graph<String, MyLink> graph = scenario.getGraph();
	List<List<MyLink>> solutions = scenario.getSolutions();
	String s = scenario.getSource();
	String t = scenario.getTarget();

	Eppstein<String, MyLink> kspAlgo = new Eppstein<String, MyLink>(graph,
			weightTrans);
	int k = solutions.size();
	List<List<MyLink>> result = kspAlgo.getShortestPaths(s, t, k);

	for (int i = 0; i < k; i++)
		assertTrue(comparePaths(solutions.get(i), result.get(i)));
}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:18,代碼來源:KShortestPathTest.java

示例5: suurballeTarjanExample

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
@Test
public void suurballeTarjanExample() {
	KspTestScenario<String, MyLink> scenario = KspTestScenarios
			.getSuurballeTarjanScenario();
	Graph<String, MyLink> graph = scenario.getGraph();
	List<List<MyLink>> solutions = scenario.getSolutions();
	String s = scenario.getSource();
	String t = scenario.getTarget();

	KShortestPathAlgorithm<String, MyLink> kspAlgo = factory.create(graph,
			weightTrans);
	int k = solutions.size();
	List<List<MyLink>> result = kspAlgo.getShortestPaths(s, t, k);

	for (int i = 0; i < k; i++)
		assertTrue(comparePaths(solutions.get(i), result.get(i)));
}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:18,代碼來源:KShortestPathTest.java

示例6: generateVertexGrid

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
private Graph generateVertexGrid(DefaultSettableVertexLocationFunction vlf,
        Dimension d, int interval) {
    int count = d.width/interval * d.height/interval;
    Graph graph = new SparseGraph();
    Vertex[] v = new Vertex[count];
    for(int i=0; i<count; i++) {
        int x = interval*i;
        int y = x / d.width * interval;
        x %= d.width;
        
        Point2D location = new Point2D.Float(x, y);
        Vertex vertex = new SparseVertex();
        vlf.setLocation(vertex, location);
        v[i] = graph.addVertex(vertex);
    }
    return graph;
}
 
開發者ID:dev-cuttlefish,項目名稱:cuttlefish,代碼行數:18,代碼來源:LensDemo.java

示例7: validate

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
private void validate(V source, V target, List<E> path, Graph<V, E> graph)
		throws AssertionError {
	if (!graph.isSource(source, path.get(0)))
		throw new AssertionError("invalid source");

	Iterator<E> it = path.iterator();
	E e1 = it.next();

	while (it.hasNext()) {
		E e2 = it.next();

		if (!graph.isSource(graph.getDest(e1), e2))
			throw new AssertionError("invalid path");

		e1 = e2;
	}

	if (!graph.isDest(target, path.get(path.size() - 1)))
		throw new AssertionError("invalid destination");
}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:21,代碼來源:SuurballeTarjan.java

示例8: transfer2GlobalNetworkModel

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
/**
 * Transfer the components that have been removed back to the global NetworkModel.
 * @param networkComponent the NetworkComponent
 */
private void transfer2GlobalNetworkModel(NetworkComponent networkComponent) {
	
	NetworkModel sourceNetworkModel = this.extractedNetworkModel;
	NetworkModel destinNetworkModel = this.graphController.getNetworkModel();
	
	// --- Work on the graph ----------------------------------------------
	Graph<GraphNode, GraphEdge> sourceGraph = sourceNetworkModel.getGraph();
	Graph<GraphNode, GraphEdge> destinGraph = destinNetworkModel.getGraph();
	
	// --- Transfer the graph representation of the network component ----- 
	NetworkComponent netComp = sourceNetworkModel.getNetworkComponent(networkComponent.getId());
	HashSet<String> nodeIDs = sourceNetworkModel.extractGraphElementIDs(networkComponent, new GraphNode());
	HashSet<String> edgeIDs = sourceNetworkModel.extractGraphElementIDs(netComp, new GraphEdge("searchFor", "searchFor"));
	for (String edgeID: edgeIDs) {
		GraphEdge edge = (GraphEdge) sourceNetworkModel.getGraphElement(edgeID);
		GraphNode node1 = sourceGraph.getEndpoints(edge).getFirst();
		GraphNode node2 = sourceGraph.getEndpoints(edge).getSecond();
		destinGraph.addEdge(edge, node1, node2, sourceGraph.getEdgeType(edge));
	}
	
	// --- DistributionNode ? ---------------------------------------------
	if (netComp.getPrototypeClassName().equalsIgnoreCase(DistributionNode.class.getName())) {
		GraphNode node = (GraphNode) sourceNetworkModel.getGraphElement(nodeIDs.iterator().next());
		destinGraph.addVertex(node);
	}
	
	// --- Work on the network component ----------------------------------
	destinNetworkModel.addNetworkComponent(networkComponent);
	
	// --- Merge the old connections --------------------------------------
	Vector<GraphNodePairs> connections = this.nodeConnections.get(networkComponent); 
	for (int i = 0; i < connections.size(); i++) {
		GraphNodePairs conection = connections.get(i);
		destinNetworkModel.mergeNodes(conection);
	}
	
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:42,代碼來源:RemoveNetworkComponent.java

示例9: actionPerformed

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
public void actionPerformed(ActionEvent arg0)
{
    Object[] constructorArgs =
        { g_array[graph_index]};

    Class layoutC = (Class) jcb.getSelectedItem();
    Class lay = layoutC;
    try
    {
        Constructor constructor = lay
                .getConstructor(new Class[] {Graph.class});
        Object o = constructor.newInstance(constructorArgs);
        Layout l = (Layout) o;
        vv.stop();
        vv.setGraphLayout(l, false);
        vv.restart();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}
 
開發者ID:dev-cuttlefish,項目名稱:cuttlefish,代碼行數:23,代碼來源:ShowLayouts.java

示例10: transform

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
@Override
public Shape transform(Context<Graph<V, E>, E> context) {

	// --- Get the shape for this edge, returning either the --------------
	// --- shared instance or, in the case of self-loop edges, the --------
	// --- SimpleLoop shared instance.
	
	Graph<V,E> graph = context.graph;
   	E e = context.element;
       
       Pair<V> endpoints = graph.getEndpoints(e);
       if(endpoints != null) {
       	boolean isLoop = endpoints.getFirst().equals(endpoints.getSecond());
       	if (isLoop) {
       		return this.getLoop().transform(context);
       	}
       }
       // --- Return the edge shape ------------------------------------------
       if (e instanceof GraphEdge) {
       	return this.getGeneralPath((GraphEdge)e);
       } else {
       	return this.getLine();
       }
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:25,代碼來源:EdgeShapePolyline.java

示例11: main

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
public static void main(String[] args) {
	// create FNSS topology
	Topology topology = new Topology();
	topology.addEdge("1", "2", new Edge());
	topology.addEdge("2", "3", new Edge());
	
	// convert to JGraphT
	Graph<String, Edge> graph = JUNGConverter.getGraph(topology);
	
	// Find shortest paths
	String source = "3";
	String destination = "1";
	DijkstraShortestPath<String, Edge> shortestPath = 
			new DijkstraShortestPath<String, Edge>(graph);
	List<Edge> path = shortestPath.getPath(source, destination);

	// Print results
	System.out.println("Shortest path from " + source + " to " + destination + ":");
	for (Edge e : path) {
		Pair<String> endpoints = graph.getEndpoints(e);
		System.out.println(endpoints.getFirst() + " -> " + endpoints.getSecond());
	}
}
 
開發者ID:fnss,項目名稱:fnss-java,代碼行數:24,代碼來源:ExampleJUNG.java

示例12: MinimumSpanningForest

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
/**
 * Creates a minimum spanning forest from the supplied graph, populating the
 * supplied Forest, which must be empty. 
 * If the supplied root is null, or not present in the Graph,
 * then an arbitrary Graph vertex will be selected as the root.
 * If the Minimum Spanning Tree does not include all vertices of the
 * Graph, then a leftover vertex is selected as a root, and another
 * tree is created
 * @param graph the Graph to find MST in
 * @param forest the Forest to populate. Must be empty
 * @param root first Tree root, may be null
 */
public MinimumSpanningForest(Graph<V, E> graph, Forest<V,E> forest, 
        Collection<V> roots) {
    
    if(forest.getVertexCount() != 0) {
        throw new IllegalArgumentException("Supplied Forest must be empty");
    }
    this.graph = graph;
    this.forest = forest;
    Set<E> unfinishedEdges = new HashSet<E>(graph.getEdges());
    if(roots != null && !roots.isEmpty()) {
    	V root = roots.iterator().next();
    	System.out.println(root);
    	roots.remove(root);
    	this.forest.addVertex(root);
    }
    updateForest(forest.getVertices(), unfinishedEdges, roots);
}
 
開發者ID:dev-cuttlefish,項目名稱:cuttlefish,代碼行數:30,代碼來源:MinimumSpanningForest.java

示例13: addToGraph

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
@Override
  public HashSet<GraphElement> addToGraph(NetworkModel networkModel) {
  	
  	Graph<GraphNode, GraphEdge> graph = networkModel.getGraph();
	
// Create nodes and edge
entry = new GraphNode();
entry.setId(networkModel.nextNodeID());
graph.addVertex(entry);

exit = new GraphNode();
exit.setId(networkModel.nextNodeID());
graph.addVertex(exit);

GraphEdge e = new GraphEdge(getId(), getType());
graph.addEdge(e, entry, exit, EdgeType.DIRECTED);
	
// Create a HashSet containing the nodes and edge ant return it
HashSet<GraphElement> elements = new HashSet<GraphElement>();
elements.add(e);
elements.add(entry);
elements.add(exit);
return elements;
  }
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:25,代碼來源:DirectedSimpleGraphElement.java

示例14: getGraph

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
/**
 * Convert FNSS topology to JUNG graph.
 * 
 * @param topology FNSS Topology object
 * @return A JUNG graph
 */
public static Graph<String, Edge> getGraph(Topology topology) {
	Graph<String, Edge> graph = null;
	EdgeType edgeType = null;
	if (topology.isDirected()) {
		graph = new DirectedSparseGraph<String, Edge>();
		edgeType = EdgeType.DIRECTED;
	} else {
		graph = new UndirectedSparseGraph<String, Edge>();
		edgeType = EdgeType.UNDIRECTED;
	}
	for(String node : topology.getAllNodes()) {
		graph.addVertex(node);
	}
	for(Pair<String, String> edge : topology.getAllEdges()) {
		graph.addEdge(topology.getEdge(edge), edge.getU(), edge.getV(), edgeType);
	}
	return graph;
}
 
開發者ID:fnss,項目名稱:fnss-java,代碼行數:25,代碼來源:JUNGConverter.java

示例15: createGraph

import edu.uci.ics.jung.graph.Graph; //導入依賴的package包/類
@Override
public Graph<String, String> createGraph() {
	Tree<String, String> graph = new DelegateTree<String, String>();
	if (clusterModel.getRootNode() == null) {
		return graph;
	}

	HierarchicalClusterNode root = clusterModel.getRootNode();
	graph.addVertex("Root");
	vertexMap.put("Root", root);

	for (HierarchicalClusterNode subNode : clusterModel.getRootNode().getSubNodes()) {
		createGraph(graph, "Root", subNode);
	}
	return graph;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:17,代碼來源:ClusterModelGraphCreator.java


注:本文中的edu.uci.ics.jung.graph.Graph類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。