本文整理汇总了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);
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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");
}
}
示例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");
}
}
示例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);
}
示例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);
}
示例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());
}
示例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");
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}