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


Java Graph.addVertex方法代碼示例

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


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

示例1: getUnreachabilitiyScenario

import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
/**
 * @return There is only one shortest path! We have to prevent endless
 *         looping!
 */
public static KspTestScenario<String, MyLink> getUnreachabilitiyScenario() {
	Graph<String, MyLink> graph = new DirectedOrderedSparseMultigraph<String, MyLink>();

	String s = new String("S"); // the source
	graph.addVertex(s);
	String v = new String("V"); // the unreachable vertex!
	graph.addVertex(v);
	String w = new String("W"); // the intermediate vertex
	graph.addVertex(w);
	String t = new String("T"); // the target
	graph.addVertex(t);

	graph.addEdge(new MyLink(1, "S-V"), s, v, EdgeType.DIRECTED); // dead-end
	graph.addEdge(new MyLink(1, "S-W"), s, w, EdgeType.DIRECTED);
	graph.addEdge(new MyLink(1, "W-T"), w, t, EdgeType.DIRECTED);

	List<MyLink> path = new ArrayList<MyLink>();
	path.add(graph.findEdge(s, w));
	path.add(graph.findEdge(w, t));

	List<List<MyLink>> temp = new LinkedList<List<MyLink>>();
	temp.add(path);

	return new KspTestScenario<String, MyLink>(graph, temp, s, t);
}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:30,代碼來源:KspTestScenarios.java

示例2: 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

示例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: reverseEdges

import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
/**
 * This method reverse the path "path" in the graph "graph" and returns it.
 * 
 * @param graph
 *            the input graph which will not be changed.
 * @param path
 *            the path to reverse
 * @return a new graph with the reversed path
 */
private Graph<V, E> reverseEdges(Graph<V, E> graph, List<E> path) {
	if (graph == null || path == null)
		throw new IllegalArgumentException();
	Graph<V, E> clone = new DirectedOrderedSparseMultigraph<V, E>();

	for (V v : graph.getVertices())
		clone.addVertex(v);
	for (E e : graph.getEdges())
		clone.addEdge(e, graph.getEndpoints(e));

	for (E link : path) {
		V src = clone.getSource(link);
		V dst = clone.getDest(link);
		clone.removeEdge(link);
		clone.addEdge(link, dst, src, EdgeType.DIRECTED);
	}
	return clone;
}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:28,代碼來源:SuurballeTarjan.java

示例5: 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

示例6: renderElement

import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
@Override
public void renderElement(JPanel jp, Object elem) {
    if (elem instanceof ViwnNode) {
        ViwnNode vn = (ViwnNode) elem;

        // one node visualisation
        Graph<ViwnNode, ViwnEdge> g = new DirectedSparseGraph<>();
        g.addVertex(vn);
        VisualizationViewer<ViwnNode, ViwnEdge> vv = new VisualizationViewer<>(new StaticLayout<>(g));
        vv.getRenderer().setVertexRenderer(new ViwnVertexRenderer(vv.getRenderer().getVertexRenderer()));

        vv.getRenderContext().setVertexShapeTransformer((ViwnNode v) -> v.getShape());

        vv.getRenderContext().setVertexFillPaintTransformer(new ViwnVertexFillColor(vv.getPickedVertexState(), null));
        vv.setVertexToolTipTransformer(new ViwnVertexToolTipTransformer());
        vv.setPreferredSize(new Dimension(110, 50));
        Point2D q = vv.getGraphLayout().transform(vn);
        Point2D lvc = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter());
        vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).translate(lvc.getX() - q.getX(), lvc.getY() - q.getY());
        jp.add(vv, "vfill br");
    }
}
 
開發者ID:CLARIN-PL,項目名稱:WordnetLoom,代碼行數:23,代碼來源:ViwnLockerViewUI.java

示例7: addToGraph

import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
@Override
  public HashSet<GraphElement> addToGraph(NetworkModel networkModel) {
  	
  	Graph<GraphNode, GraphEdge> graph = networkModel.getGraph();
// check if n is set
if (n != null) {
    // Create a HashSet for the nodes and edges
    HashSet<GraphElement> elements = new HashSet<GraphElement>();
	
    // Creating nodes
    for (int i = 0; i < n; i++) {
		// Create the node and add to the vector
		GraphNode node = new GraphNode();
		node.setId(networkModel.nextNodeID());
		graph.addVertex(node);
		nodes.add(node);
		elements.add(node);
    }
	
    // Creating edges
    int edgeCount = 0;
    for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
		    // Creating edge
		    GraphEdge edge = new GraphEdge(getId() + "_" + edgeCount, getType());
		    // Adding to the graph
		    graph.addEdge(edge, nodes.get(i), nodes.get(j), EdgeType.UNDIRECTED);
		    elements.add(edge);
		    edgeCount++;
		}
    }
    return elements;
} else {
    throw new GraphElementPrototypeException("Number of connection points (n) is null");
}
  }
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:37,代碼來源:Mesh3GraphElement.java

示例8: getLoopScenario

import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
/**
 * @return There is only one shortest path! We have to prevent endless
 *         looping!
 */
public static KspTestScenario<String, MyLink> getLoopScenario() {
	Graph<String, MyLink> graph = new DirectedOrderedSparseMultigraph<String, MyLink>();

	String s = new String("S"); // the source
	graph.addVertex(s);
	String a = new String("A"); // the intermediate vertex 1
	graph.addVertex(a);
	String b = new String("B"); // the intermediate vertex 2
	graph.addVertex(b);
	String t = new String("T"); // the target
	graph.addVertex(t);

	graph.addEdge(new MyLink(1, "S-A"), s, a, EdgeType.DIRECTED);
	graph.addEdge(new MyLink(1, "A-B"), a, b, EdgeType.DIRECTED);
	graph.addEdge(new MyLink(1, "B-A"), b, a, EdgeType.DIRECTED); // loop!
	graph.addEdge(new MyLink(1, "B-T"), b, t, EdgeType.DIRECTED);

	List<MyLink> path = new ArrayList<MyLink>();
	path.add(graph.findEdge(s, a));
	path.add(graph.findEdge(a, b));
	path.add(graph.findEdge(b, t));

	List<List<MyLink>> temp = new LinkedList<List<MyLink>>();
	temp.add(path);

	return new KspTestScenario<String, MyLink>(graph, temp, s, t);
}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:32,代碼來源:KspTestScenarios.java

示例9: getSelfLoopUnreachableScenario

import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
/**
 * @return Self-loop at start and unreachable target.
 */
public static KspTestScenario<String, MyLink> getSelfLoopUnreachableScenario() {
	Graph<String, MyLink> graph = new DirectedOrderedSparseMultigraph<String, MyLink>();

	String s = new String("S"); // the source
	graph.addVertex(s);
	String t = new String("T");
	graph.addVertex(t);

	graph.addEdge(new MyLink(20, "S-S"), s, s, EdgeType.DIRECTED); // loop

	List<List<MyLink>> temp = new LinkedList<List<MyLink>>();

	return new KspTestScenario<String, MyLink>(graph, temp, s, t);
}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:18,代碼來源:KspTestScenarios.java

示例10: testTargetRemoval

import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
@Test
public void testTargetRemoval() {
	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
	g.addVertex(n3);
	String n4 = new String("C"); // C
	g.addVertex(n4);
	String n5 = new String("D"); // D
	g.addVertex(n5);

	g.addEdge(new MyLink(3, "S-A"), n1, n2, EdgeType.DIRECTED); // S - A
	g.addEdge(new MyLink(1, "A-C"), n2, n4, EdgeType.DIRECTED); // A - C
	g.addEdge(new MyLink(3, "S-B"), n1, n3, EdgeType.DIRECTED); // S - B
	g.addEdge(new MyLink(3, "B-C"), n3, n4, EdgeType.DIRECTED); // B - C
	g.addEdge(new MyLink(3, "C-D"), n4, n5, EdgeType.DIRECTED); // C - D

	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("[[S-A, A-C, C-D]]", testMain.getDisjointPaths(n1, n5)
			.toString());
}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:33,代碼來源:SuurballeTarjanTest.java

示例11: addToGraph

import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
@Override
public HashSet<GraphElement> addToGraph(NetworkModel networkModel) {
   	
   	Graph<GraphNode, GraphEdge> graph = networkModel.getGraph();
	// check if n is set
	if (n != null) {
		// Create a HashSet for the nodes and edges
		HashSet<GraphElement> elements = new HashSet<GraphElement>();

		// Create central node and add to the graph
		GraphNode centralNode = new GraphNode();
		centralNode.setId(networkModel.nextNodeID());
		graph.addVertex(centralNode);
		elements.add(centralNode);

		// Creating outer nodes and edges
		for (int i = 0; i < n; i++) {
			// Create the node and add to the vector
			GraphNode node = new GraphNode();
			node.setId(networkModel.nextNodeID());
			outerNodes.add(node);
			elements.add(node);

			// Creating edge
			GraphEdge edge = new GraphEdge(getId() + "_" + i, getType());

			// Adding to the graph
			graph.addVertex(node);
			graph.addEdge(edge, centralNode, node, EdgeType.UNDIRECTED);
			elements.add(edge);
		}
		return elements;

	}
	throw new GraphElementPrototypeException("Number of connection points (n) is null");
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:37,代碼來源:Star3GraphElement.java

示例12: addToGraph

import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
@Override
public HashSet<GraphElement> addToGraph(NetworkModel networkModel) {
   	
   	Graph<GraphNode, GraphEdge> graph = networkModel.getGraph();
	HashSet<GraphElement> elements = new HashSet<GraphElement>();

	distributionNode = new GraphNode();
	distributionNode.setId(networkModel.nextNodeID());
	graph.addVertex(distributionNode);
    elements.add(distributionNode);
	return elements;
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:13,代碼來源:DistributionNode.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
GraphNode entry = new GraphNode();
entry.setId(networkModel.nextNodeID());
graph.addVertex(entry);

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

GraphEdge e = new GraphEdge(getId(), getType());
graph.addEdge(e, entry, exit, EdgeType.UNDIRECTED);
	
// Add the nodes to this GraphElementPrototypes node list
nodes.add(entry);
nodes.add(exit);
	
// 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,代碼行數:29,代碼來源:SimpleGraphElement.java

示例14: addToGraph

import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
@Override
public HashSet<GraphElement> addToGraph(NetworkModel networkModel) {
   	
   	Graph<GraphNode, GraphEdge> graph = networkModel.getGraph();
	HashSet<GraphElement> elements = new HashSet<GraphElement>();
	
	// --- Add central Node -------------------------------------
	this.centralGraphNode = new GraphNode();
	this.centralGraphNode.setId(networkModel.nextNodeID());
	graph.addVertex(this.centralGraphNode);
	elements.add(this.centralGraphNode);
	
	// --- Add Edges --------------------------------------------
	int counter = 0;
	for (GraphNode outerNode : outerNodes) {
		// --- Add Edge -----------------------------------------
		GraphEdge edge = new GraphEdge(id + "_" + counter++, getType());
		graph.addEdge(edge, this.centralGraphNode, outerNode, EdgeType.UNDIRECTED);
		elements.add(edge);
	}
	
	// --- Set position of central GraphNode --------------------
	Rectangle2D rectangle = GraphGlobals.getGraphSpreadDimension(this.outerNodes);
	this.centralGraphNode.setPosition(new Point2D.Double(rectangle.getCenterX(), rectangle.getCenterY()));

	elements.addAll(this.outerNodes);
	return elements;
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:29,代碼來源:ClusterGraphElement.java

示例15: getDecisionOnLastHopScenario

import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
/**
 * @return An example in which all candidate paths have equal length in the
 *         first step.
 */
public static KspTestScenario<String, MyLink> getDecisionOnLastHopScenario() {
	Graph<String, MyLink> graph = new DirectedOrderedSparseMultigraph<String, MyLink>();

	String s = new String("S"); // the source
	graph.addVertex(s);
	String a = new String("A");
	graph.addVertex(a);
	String b = new String("B");
	graph.addVertex(b);
	String c = new String("C");
	graph.addVertex(c);
	String d = new String("D");
	graph.addVertex(d);
	String t = new String("T"); // the target
	graph.addVertex(t);

	graph.addEdge(new MyLink(1, "S-B"), s, b, EdgeType.DIRECTED); // S - B
	graph.addEdge(new MyLink(1, "S-C"), s, c, EdgeType.DIRECTED); // S - C
	graph.addEdge(new MyLink(1, "S-D"), s, d, EdgeType.DIRECTED); // S - D
	graph.addEdge(new MyLink(1, "S-A"), s, a, EdgeType.DIRECTED); // S - A

	graph.addEdge(new MyLink(2, "B-T"), b, t, EdgeType.DIRECTED); // B - T
	graph.addEdge(new MyLink(3, "C-T"), c, t, EdgeType.DIRECTED); // C - T
	graph.addEdge(new MyLink(1, "A-T"), a, t, EdgeType.DIRECTED); // A - T
	graph.addEdge(new MyLink(4, "D-T"), d, t, EdgeType.DIRECTED); // D - T

	List<MyLink> path = new ArrayList<MyLink>();
	path.add(graph.findEdge(s, a));
	path.add(graph.findEdge(a, t));

	List<MyLink> path2 = new ArrayList<MyLink>();
	path2.add(graph.findEdge(s, b));
	path2.add(graph.findEdge(b, t));

	List<MyLink> path3 = new ArrayList<MyLink>();
	path3.add(graph.findEdge(s, c));
	path3.add(graph.findEdge(c, t));

	List<MyLink> path4 = new ArrayList<MyLink>();
	path4.add(graph.findEdge(s, d));
	path4.add(graph.findEdge(d, t));

	List<List<MyLink>> temp = new LinkedList<List<MyLink>>();
	temp.add(path);
	temp.add(path2);
	temp.add(path3);
	temp.add(path4);

	return new KspTestScenario<String, MyLink>(graph, temp, s, t);
}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:55,代碼來源:KspTestScenarios.java


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