本文整理匯總了Java中edu.uci.ics.jung.graph.util.Pair.getSecond方法的典型用法代碼示例。如果您正苦於以下問題:Java Pair.getSecond方法的具體用法?Java Pair.getSecond怎麽用?Java Pair.getSecond使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類edu.uci.ics.jung.graph.util.Pair
的用法示例。
在下文中一共展示了Pair.getSecond方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: f
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
Collection<VirtualNode> f(Set<VirtualNode> vns, VirtualNetwork g) {
Collection<VirtualNode> result = new LinkedList<VirtualNode>();
for (VirtualLink vl : g.getEdges()) {
Pair<VirtualNode> endpoints = g.getEndpoints(vl);
VirtualNode n_i = endpoints.getFirst();
VirtualNode n_j = endpoints.getSecond();
if (Utils.contains(n_j, vns)) {
if (!Utils.contains(n_i, vns)) {
if (!Utils.contains(n_i, result)) {
result.add(n_i);
}
}
} else {
if (Utils.contains(n_i, vns)) {
if (!Utils.contains(n_j, result)) {
result.add(n_j);
}
}
}
}
return result;
}
示例2: transform
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
public Paint transform( Exit exit ) {
Layout<Room, Exit> layout = vv.getGraphLayout();
Pair<Room> pair = layout.getGraph().getEndpoints( exit );
Room begin = pair.getFirst();
Room end = pair.getSecond();
Point2D beginPoint = transformer.transform( layout.transform( begin ) );
Point2D endPoint = transformer.transform( layout.transform( end ) );
float xFirst = (float) beginPoint.getX();
float yFirst = (float) beginPoint.getY();
float xEnd = (float) endPoint.getX();
float yEnd = (float) endPoint.getY();
if (selfLoop.evaluate( Context.<Graph<Room, Exit>, Exit>getInstance( layout.getGraph(), exit ) )) {
xEnd += 50;
yEnd += 50;
}
return new GradientPaint( xFirst, yFirst, getColorFor( begin ), xEnd, yEnd, getColorFor( end ), true );
}
示例3: addEdge
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
/**
* @see edu.uci.ics.jung.graph.Hypergraph#addEdge(java.lang.Object, java.util.Collection)
*/
@Override
@SuppressWarnings("unchecked")
public boolean addEdge(E edge, Collection<? extends V> vertices, EdgeType edge_type)
{
if (edge == null || vertices == null)
throw new IllegalArgumentException("inputs may not be null");
if (vertices.size() != 2)
throw new IllegalArgumentException("'vertices' must contain " +
"exactly 2 distinct vertices");
this.validateEdgeType(edge_type);
Pair<V> endpoints;
if (vertices instanceof Pair)
endpoints = (Pair<V>)vertices;
else
endpoints = new Pair<V>(vertices);
V v1 = endpoints.getFirst();
V v2 = endpoints.getSecond();
if (v1.equals(v2))
throw new IllegalArgumentException("Input vertices must be distinct");
return addEdge(edge, v1, v2);
}
示例4: removeEdge
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
public boolean removeEdge(E edge)
{
if (!containsEdge(edge))
return false;
Pair<V> endpoints = getEndpoints(edge);
V v1 = endpoints.getFirst();
V v2 = endpoints.getSecond();
// remove edge from incident vertices' adjacency maps
if (getEdgeType(edge) == EdgeType.DIRECTED)
{
vertex_maps.get(v1)[OUTGOING].remove(v2);
vertex_maps.get(v2)[INCOMING].remove(v1);
directed_edges.remove(edge);
}
else
{
vertex_maps.get(v1)[INCIDENT].remove(v2);
vertex_maps.get(v2)[INCIDENT].remove(v1);
undirected_edges.remove(edge);
}
return true;
}
示例5: transform
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
public Paint transform(E e)
{
Layout<V, E> layout = vv.getGraphLayout();
Pair<V> p = layout.getGraph().getEndpoints(e);
V b = p.getFirst();
V f = p.getSecond();
Point2D pb = transformer.transform(layout.transform(b));
Point2D pf = transformer.transform(layout.transform(f));
float xB = (float) pb.getX();
float yB = (float) pb.getY();
float xF = (float) pf.getX();
float yF = (float) pf.getY();
if ((layout.getGraph().getEdgeType(e)) == EdgeType.UNDIRECTED) {
xF = (xF + xB) / 2;
yF = (yF + yB) / 2;
}
if(selfLoop.evaluate(Context.<Graph<V,E>,E>getInstance(layout.getGraph(), e))) {
yF += 50;
xF += 50;
}
return new GradientPaint(xB, yB, getColor1(e), xF, yF, getColor2(e), true);
}
示例6: getIndex
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
/**
* Returns the index for the specified edge.
* Calculates the indices for <code>e</code> and for all edges parallel
* to <code>e</code>.
*/
public int getIndex(Graph<V,E> graph, E e) {
if(predicate.evaluate(e)) {
return 0;
}
Integer index = edge_index.get(e);
if(index == null) {
Pair<V> endpoints = graph.getEndpoints(e);
V u = endpoints.getFirst();
V v = endpoints.getSecond();
if(u.equals(v)) {
index = getIndex(graph, e, v);
} else {
index = getIndex(graph, e, u, v);
}
}
return index.intValue();
}
示例7: addEdge
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
@Override
public boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edge_type)
{
validateEdgeType(edge_type);
Pair<V> new_endpoints = getValidatedEndpoints(edge, endpoints);
if (new_endpoints == null)
return false;
V v1 = endpoints.getFirst();
V v2 = endpoints.getSecond();
edges.put(edge, new_endpoints);
if (!containsVertex(v1))
this.addVertex(v1);
if (!containsVertex(v2))
this.addVertex(v2);
vertices.get(v1).add(edge);
vertices.get(v2).add(edge);
return true;
}
示例8: getValidatedEndpoints
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
protected Pair<V> getValidatedEndpoints(E edge, Pair<? extends V> endpoints)
{
if (edge == null)
throw new IllegalArgumentException("input edge may not be null");
if (endpoints == null)
throw new IllegalArgumentException("endpoints may not be null");
Pair<V> new_endpoints = new Pair<V>(endpoints.getFirst(), endpoints.getSecond());
if (containsEdge(edge))
{
Pair<V> existing_endpoints = getEndpoints(edge);
if (!existing_endpoints.equals(new_endpoints)) {
throw new IllegalArgumentException("edge " + edge +
" already exists in this graph with endpoints " + existing_endpoints +
" and cannot be added with endpoints " + endpoints);
} else {
return null;
}
}
return new_endpoints;
}
示例9: evolveGraph
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
private void evolveGraph() {
Collection<V> preexistingNodes = mGraph.getVertices();
V newVertex = factory.createNode();
mGraph.addVertex(newVertex);
// generate and store the new edges; don't add them to the graph
// yet because we don't want to bias the degree calculations
// (all new edges in a timestep should be added in parallel)
Set<Pair<V>> added_pairs = new HashSet<Pair<V>>(mNumEdgesToAttachPerStep*3);
for (int i = 0; i < mNumEdgesToAttachPerStep; i++) {
createRandomEdge(preexistingNodes, newVertex, added_pairs);
}
for (Pair<V> pair : added_pairs)
{
V v1 = pair.getFirst();
V v2 = pair.getSecond();
if (mGraph.getDefaultEdgeType() != EdgeType.UNDIRECTED ||
!mGraph.isNeighbor(v1, v2))
mGraph.addEdge(factory.createEdge(), pair);
}
// now that we're done attaching edges to this new vertex,
// add it to the index
vertex_index.add(newVertex);
index_vertex.put(newVertex, new Integer(vertex_index.size() - 1));
}
示例10: GraphEdgeConnection
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
/**
* Instantiates a new graph edge connection.
*/
public GraphEdgeConnection(NetworkModel networkModel, NetworkComponent networkComponent, GraphEdge graphEdge) {
this.graphEdge = graphEdge;
EdgeType edgeType = networkModel.getGraph().getEdgeType(this.graphEdge);
if (networkComponent.isDirected() && edgeType==EdgeType.DIRECTED) {
this.fixedDirected = true;
this.graphNode1 = networkModel.getGraph().getSource(this.graphEdge);
this.graphNode2 = networkModel.getGraph().getDest(this.graphEdge);
} else {
this.fixedDirected = false;
Pair<GraphNode> nodePair = networkModel.getGraph().getEndpoints(this.graphEdge);
this.graphNode1 = nodePair.getFirst();
this.graphNode2 = nodePair.getSecond();
}
HashSet<NetworkComponent> netComps = null;
netComps = networkModel.getNetworkComponents(this.graphNode1);
netComps.remove(networkComponent);
if (netComps.size()>0) {
this.externalNetworkComponent1 = netComps.iterator().next();
}
netComps = networkModel.getNetworkComponents(this.graphNode2);
netComps.remove(networkComponent);
if (netComps.size()>0) {
this.externalNetworkComponent2 = netComps.iterator().next();
}
}
示例11: getOtherEndOfExit
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
private Room getOtherEndOfExit( Exit exit, Room room ) {
Pair<Room> ends = this.graph.getEndpoints( exit );
if (ends.getFirst() == room) {
return ends.getSecond();
} else {
return ends.getFirst();
}
}
示例12: addEdge
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
@Override
public boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edgeType) {
this.validateEdgeType(edgeType);
Pair<V> new_endpoints = getValidatedEndpoints(edge, endpoints);
if (new_endpoints == null)
return false;
V v1 = new_endpoints.getFirst();
V v2 = new_endpoints.getSecond();
if (findEdge(v1, v2) != null)
return false;
edges.put(edge, new_endpoints);
if (!vertices.containsKey(v1))
this.addVertex(v1);
if (!vertices.containsKey(v2))
this.addVertex(v2);
// map v1 to <v2, edge> and vice versa
vertices.get(v1).put(v2, edge);
vertices.get(v2).put(v1, edge);
return true;
}
示例13: removeEdge
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
public boolean removeEdge(E edge) {
if (!containsEdge(edge))
return false;
Pair<V> endpoints = getEndpoints(edge);
V v1 = endpoints.getFirst();
V v2 = endpoints.getSecond();
// remove incident vertices from each others' adjacency maps
vertices.get(v1).remove(v2);
vertices.get(v2).remove(v1);
edges.remove(edge);
return true;
}
示例14: toDirected
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
public static <V> DirectedGraph<V, WeightedEdge> toDirected(Graph<V, WeightedEdge> graph, Map<String, Item> itemsMap) {
DirectedGraph<V, WeightedEdge> directedGraph = new DirectedSparseGraph<V, WeightedEdge>();
// Add all vertices first
Collection<V> vertices = graph.getVertices();
for(V vertex : vertices) {
directedGraph.addVertex(vertex);
}
// Add directed edges
for(WeightedEdge edge : graph.getEdges()) {
Pair<V> endpoints = graph.getEndpoints(edge);
V firstId = endpoints.getFirst();
V secondId = endpoints.getSecond();
Item firstItem = itemsMap.get(firstId);
Item secondItem = itemsMap.get(secondId);
if(firstItem.getPublicationTime() > secondItem.getPublicationTime()) {
directedGraph.addEdge(new WeightedEdge(edge.getWeight()), firstId, secondId);
}
else if(firstItem.getPublicationTime() < secondItem.getPublicationTime()) {
directedGraph.addEdge(new WeightedEdge(edge.getWeight()), secondId, firstId);
}
else {
// If items have the same publication date then do not add any edge
// TODO: Check whether adding a bidirectional edge gives better results
}
}
return directedGraph;
}
示例15: addEdge
import edu.uci.ics.jung.graph.util.Pair; //導入方法依賴的package包/類
@Override
public boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edgeType)
{
this.validateEdgeType(edgeType);
Pair<V> new_endpoints = getValidatedEndpoints(edge, endpoints);
if (new_endpoints == null)
return false;
V v1 = new_endpoints.getFirst();
V v2 = new_endpoints.getSecond();
if (findEdge(v1, v2) != null)
return false;
edges.put(edge, new_endpoints);
if (!vertices.containsKey(v1))
this.addVertex(v1);
if (!vertices.containsKey(v2))
this.addVertex(v2);
// map v1 to <v2, edge> and vice versa
vertices.get(v1).put(v2, edge);
vertices.get(v2).put(v1, edge);
return true;
}