当前位置: 首页>>代码示例>>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;未经允许,请勿转载。