本文整理匯總了Java中edu.uci.ics.jung.graph.Graph.addEdge方法的典型用法代碼示例。如果您正苦於以下問題:Java Graph.addEdge方法的具體用法?Java Graph.addEdge怎麽用?Java Graph.addEdge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類edu.uci.ics.jung.graph.Graph
的用法示例。
在下文中一共展示了Graph.addEdge方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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;
}
示例4: 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);
}
}
示例5: 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);
}
示例6: 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);
}
示例7: createGraph
import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
private void createGraph(Graph<String, String> graph, String parentName, HierarchicalClusterNode node) {
String childName = vertexFactory.create();
vertexMap.put(childName, node);
graph.addEdge(edgeFactory.create(), parentName, childName);
for (HierarchicalClusterNode subNode : node.getSubNodes()) {
createGraph(graph, childName, subNode);
}
}
示例8: 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());
}
示例9: 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");
}
}
示例10: getGraphCopy
import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
/**
* Copy graph and graph elements.
* @param netModel the net model
*/
private Graph<GraphNode, GraphEdge> getGraphCopy() {
Graph<GraphNode, GraphEdge> copyGraph = new SparseGraph<GraphNode, GraphEdge>();
// --- Copy all nodes and remind the relation between ID and new instance -------
Collection<GraphNode> nodesCollection = this.getGraph().getVertices();
GraphNode[] nodes = nodesCollection.toArray(new GraphNode[nodesCollection.size()]);
HashMap<String, GraphNode> graphNodeCopies = new HashMap<String, GraphNode>();
for (int i = 0; i < nodes.length; i++) {
GraphNode node = nodes[i];
GraphNode nodeCopy = node.getCopy(this);
graphNodeCopies.put(node.getId(), nodeCopy);
copyGraph.addVertex(nodeCopy);
}
// --- Copy the edges -----------------------------------------------------------
Collection<GraphEdge> edgesCollection = this.getGraph().getEdges();
GraphEdge[] edges = edgesCollection.toArray(new GraphEdge[edgesCollection.size()]);
for (int i = 0; i < edges.length; i++) {
GraphEdge edge = edges[i];
EdgeType edgeType = this.getGraph().getEdgeType(edge);
GraphNode first = this.getGraph().getEndpoints(edge).getFirst();
GraphNode second = this.getGraph().getEndpoints(edge).getSecond();
GraphNode copyFirst = graphNodeCopies.get(first.getId());
GraphNode copySecond = graphNodeCopies.get(second.getId());
GraphEdge copyEdge = edge.getCopy(this);
copyGraph.addEdge(copyEdge, copyFirst, copySecond, edgeType);
}
return copyGraph;
}
示例11: 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;
}
示例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>();
// --- 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;
}
示例13: 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");
}
示例14: getSuurballeTarjanScenario
import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
/**
* @return The example from the Suurballe-Tarjan paper.
*/
public static KspTestScenario<String, MyLink> getSuurballeTarjanScenario() {
Graph<String, MyLink> graph = new DirectedOrderedSparseMultigraph<String, MyLink>();
String s = new String("S"); // S
graph.addVertex(s);
String a = new String("A"); // A
graph.addVertex(a);
String d = new String("D"); // D
graph.addVertex(d);
String c = new String("C"); // C
graph.addVertex(c);
String f = new String("F"); // F
graph.addVertex(f);
String b = new String("B"); // B
graph.addVertex(b);
String g = new String("G"); // G
graph.addVertex(g);
String e = new String("E"); // E
graph.addVertex(e);
graph.addEdge(new MyLink(3, "S-A"), s, a, EdgeType.DIRECTED); // S - A
graph.addEdge(new MyLink(2, "S-B"), s, b, EdgeType.DIRECTED); // S - B
graph.addEdge(new MyLink(8, "S-D"), s, d, EdgeType.DIRECTED); // S - D
graph.addEdge(new MyLink(1, "A-C"), a, c, EdgeType.DIRECTED); // A - C
graph.addEdge(new MyLink(4, "A-D"), a, d, EdgeType.DIRECTED); // A - D
graph.addEdge(new MyLink(1, "D-F"), d, f, EdgeType.DIRECTED); // D - F
graph.addEdge(new MyLink(5, "C-F"), c, f, EdgeType.DIRECTED); // C - F
graph.addEdge(new MyLink(5, "B-E"), b, e, EdgeType.DIRECTED); // B - E
graph.addEdge(new MyLink(2, "E-G"), e, g, EdgeType.DIRECTED); // E - G
graph.addEdge(new MyLink(7, "G-F"), g, f, EdgeType.DIRECTED); // G - F
List<MyLink> path = new ArrayList<MyLink>();
path.add(graph.findEdge(s, a));
path.add(graph.findEdge(a, d));
path.add(graph.findEdge(d, f));
List<MyLink> path2 = new ArrayList<MyLink>();
path2.add(graph.findEdge(s, d));
path2.add(graph.findEdge(d, f));
List<MyLink> path3 = new ArrayList<MyLink>();
path3.add(graph.findEdge(s, a));
path3.add(graph.findEdge(a, c));
path3.add(graph.findEdge(c, f));
List<MyLink> path4 = new ArrayList<MyLink>();
path4.add(graph.findEdge(s, b));
path4.add(graph.findEdge(b, e));
path4.add(graph.findEdge(e, g));
path4.add(graph.findEdge(g, f));
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, f);
}
示例15: getIncreasingHopScenario
import edu.uci.ics.jung.graph.Graph; //導入方法依賴的package包/類
/**
* @return Solutions have increasing hop count, but longest hop path is the
* shortest. Other solutions have equal length of 10 and are sorted
* by increasing hops.
*/
public static KspTestScenario<String, MyLink> getIncreasingHopScenario() {
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);
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 e = new String("E");
graph.addVertex(e);
String f = new String("F");
graph.addVertex(f);
graph.addEdge(new MyLink(10, "S-T"), s, t, EdgeType.DIRECTED); // 1 hop
graph.addEdge(new MyLink(5, "S-A"), s, a, EdgeType.DIRECTED); // 2 hops
graph.addEdge(new MyLink(5, "A-T"), a, t, EdgeType.DIRECTED); // l=10
graph.addEdge(new MyLink(3, "S-B"), s, b, EdgeType.DIRECTED); // 3 hops
graph.addEdge(new MyLink(3, "B-C"), b, c, EdgeType.DIRECTED); // l=10
graph.addEdge(new MyLink(4, "C-T"), c, t, EdgeType.DIRECTED);
graph.addEdge(new MyLink(2, "S-D"), s, d, EdgeType.DIRECTED); // 4 hops
graph.addEdge(new MyLink(2, "D-E"), d, e, EdgeType.DIRECTED); // l=8
graph.addEdge(new MyLink(2, "E-F"), e, f, EdgeType.DIRECTED);
graph.addEdge(new MyLink(2, "F-T"), f, t, EdgeType.DIRECTED);
List<MyLink> path = new ArrayList<MyLink>();
path.add(graph.findEdge(s, t));
List<MyLink> path2 = new ArrayList<MyLink>();
path2.add(graph.findEdge(s, a));
path2.add(graph.findEdge(a, t));
List<MyLink> path3 = new ArrayList<MyLink>();
path3.add(graph.findEdge(s, b));
path3.add(graph.findEdge(b, c));
path3.add(graph.findEdge(c, t));
List<MyLink> path4 = new ArrayList<MyLink>();
path4.add(graph.findEdge(s, d));
path4.add(graph.findEdge(d, e));
path4.add(graph.findEdge(e, f));
path4.add(graph.findEdge(f, t));
List<List<MyLink>> temp = new LinkedList<List<MyLink>>();
temp.add(path4);
temp.add(path);
temp.add(path2);
temp.add(path3);
return new KspTestScenario<String, MyLink>(graph, temp, s, t);
}