本文整理匯總了Java中edu.uci.ics.jung.graph.util.Pair類的典型用法代碼示例。如果您正苦於以下問題:Java Pair類的具體用法?Java Pair怎麽用?Java Pair使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Pair類屬於edu.uci.ics.jung.graph.util包,在下文中一共展示了Pair類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addVertex
import edu.uci.ics.jung.graph.util.Pair; //導入依賴的package包/類
@Override
public boolean addVertex(V vertex) {
if(vertex == null) {
throw new IllegalArgumentException("vertex may not be null");
}
if (!containsVertex(vertex))
{
vertices.put(vertex, new Pair<Set<E>>(new TreeSet<E>(edge_comparator),
new TreeSet<E>(edge_comparator)));
return true;
}
else
{
return false;
}
}
示例2: 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;
}
示例3: findBiggestLinkStress
import edu.uci.ics.jung.graph.util.Pair; //導入依賴的package包/類
double findBiggestLinkStress(SubstrateNetwork sNetwork,
Collection<SubstrateLink> links) {
double maxNumber = 0.0, tmp = 0.0;
SubstrateLink maxLink = null;
for (SubstrateLink sl : links) {
Pair<SubstrateNode> endpoints = sNetwork.getEndpoints(sl);
if (maxLink == null
| (tmp = getStressLevel(sNetwork, endpoints.getFirst(), sl)) > maxNumber) {
maxNumber = tmp;
maxLink = sl;
}
if (maxLink == null
| (tmp = getStressLevel(sNetwork, endpoints.getSecond(), sl)) > maxNumber) {
maxNumber = tmp;
maxLink = sl;
}
}
return maxNumber;
}
示例4: occupyPathResources
import edu.uci.ics.jung.graph.util.Pair; //導入依賴的package包/類
public static LinkedList<ResourceDemandEntry> occupyPathResources(
List<AbstractDemand> demands, List<AbstractDemand> hiddenhopDemands,
List<SubstrateLink> path, SubstrateNetwork sNetwork) {
LinkedList<ResourceDemandEntry> resources =
new LinkedList<ResourceDemandEntry>();
int i = 1;
for (SubstrateLink e : path) {
resources.addAll(occupyResources(demands, e.get()));
if (i != path.size()) {
Pair<SubstrateNode> endpoints = sNetwork.getEndpoints(e);
Collection<ResourceDemandEntry> entry =
occupyHiddenHop(endpoints.getSecond(), hiddenhopDemands);
resources.addAll(entry);
}
++i;
}
return resources;
}
示例5: transform
import edu.uci.ics.jung.graph.util.Pair; //導入依賴的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();
}
}
示例6: 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 );
}
示例7: main
import edu.uci.ics.jung.graph.util.Pair; //導入依賴的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());
}
}
示例8: printEdge
import edu.uci.ics.jung.graph.util.Pair; //導入依賴的package包/類
/**
* private method to print an edge in the file
* @param edge
*/
private void printEdge(Edge edge)
{
if (network.getEdgeType(edge) == EdgeType.DIRECTED)
ps.print("edge: ("+ network.getSource(edge).getId() +","+ network.getDest(edge).getId()+")");
else
{
Pair<Vertex> endpoints = network.getEndpoints(edge);
ps.print("edge: ("+ endpoints.getFirst().getId() +","+ endpoints.getSecond().getId()+")");
}
if (edge.getLabel() != null)
ps.print(" label{"+edge.getLabel()+"}");
ps.print(" weight{"+edge.getWeight()+"}");
ps.print(" width{"+edge.getWidth()+"}");
if (edge.getColor() != null)
ps.print(" color{"+((double)edge.getColor().getRed()/256.d)
+","+((double)edge.getColor().getGreen()/256.d)+","+((double)edge.getColor().getBlue()/256.d)+"}");
if (edge.getVar1() != null)
ps.print(" var1{"+edge.getVar1()+"}");
if (edge.getVar2() != null)
ps.print(" var2{"+edge.getVar2()+"}");
if (edge.isExcluded())
ps.print(" hide");
ps.print("\n");
}
示例9: addSourceSubtreeRootedAt
import edu.uci.ics.jung.graph.util.Pair; //導入依賴的package包/類
private void addSourceSubtreeRootedAt(Node n, Tree.Node tn, int firstIndex, int lastIndex,
String[] sourceWords) {
int nextUncoveredIndex = firstIndex;
Tree.NodeSourceStartComparator cmp = new Tree.NodeSourceStartComparator();
List<Tree.Node> children = tn.children();
Collections.sort(children, cmp);
for (Tree.Node child : children) {
if (child.isLeaf()) {
continue;
}
int sourceStartIndex = child.sourceStartIndex();
int sourceEndIndex = child.sourceEndIndex();
if (sourceStartIndex > nextUncoveredIndex) {
insertSourceLeaf(n, sourceWords, nextUncoveredIndex, sourceStartIndex);
}
Node childNode = new Node(child.label(), true);
addEdge(new DerivationTreeEdge(true), new Pair<>(n, childNode), EdgeType.DIRECTED);
nextUncoveredIndex = sourceEndIndex;
addSourceSubtreeRootedAt(childNode, child, sourceStartIndex, sourceEndIndex, sourceWords);
}
if (nextUncoveredIndex < lastIndex) {
insertSourceLeaf(n, sourceWords, nextUncoveredIndex, lastIndex);
}
}
示例10: readJUNGGraph
import edu.uci.ics.jung.graph.util.Pair; //導入依賴的package包/類
public static <V, E> Network readJUNGGraph(DirectedOrderedSparseMultigraph<V, E> graph, int modularityFunction) {
StringBuilder stringBuilder = new StringBuilder();
ArrayList<Object> vertices = new ArrayList<>(graph.getVertices());
for (E edge : graph.getEdges()) {
Pair<V> endpoints = graph.getEndpoints(edge);
int firstVertex = vertices.indexOf(endpoints.getFirst());
int secondVertex = vertices.indexOf(endpoints.getSecond());
int smallerVertex, largerVertex;
if (firstVertex > secondVertex) {
smallerVertex = secondVertex;
largerVertex = firstVertex;
} else {
smallerVertex = firstVertex;
largerVertex = secondVertex;
}
stringBuilder.append(smallerVertex).append("\t").append(largerVertex).append("\n");
}
return readInputString(stringBuilder.toString(), modularityFunction);
}
示例11: getEdgeScore
import edu.uci.ics.jung.graph.util.Pair; //導入依賴的package包/類
public Double getEdgeScore(E e) {
Double score = scoreMap.get(e);
if (score != null) return score;
Pair<V> ends = g.getEndpoints(e);
Set<V> vmap = new HashSet<V>(g.getNeighbors(ends.getFirst()));
vmap.add(ends.getFirst());
Collection<V> v1Neighbors = g.getNeighbors(ends.getSecond());
int countCommon = 0;
if (vmap.contains(ends.getSecond())){
countCommon++;
}
for (V neighbor : v1Neighbors){
if (vmap.contains(neighbor)){
countCommon++;
}
}
Double structureSimilarity =
(double)countCommon/Math.sqrt(vmap.size()*(v1Neighbors.size()+1));
scoreMap.put(e, structureSimilarity);
return structureSimilarity;
}
示例12: toDirected
import edu.uci.ics.jung.graph.util.Pair; //導入依賴的package包/類
public static <V> DirectedGraph<V, WeightedEdge> toDirected(Graph<V, WeightedEdge> graph) {
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);
directedGraph.addEdge(new WeightedEdge(edge.getWeight()), endpoints.getFirst(), endpoints.getSecond());
directedGraph.addEdge(new WeightedEdge(edge.getWeight()), endpoints.getSecond(), endpoints.getFirst());
}
return directedGraph;
}
示例13: getShortestPath
import edu.uci.ics.jung.graph.util.Pair; //導入依賴的package包/類
public List<E> getShortestPath(V source, V sink){
List<Integer> nodes = this.floydWarshall.shortestPath(this.nodeIndex.get(source), this.nodeIndex.get(sink));
if(nodes == null){
return null;
}
else if(nodes.size() > 1){
List<E> ans = new ArrayList<E>();
for(int i = 1; i < nodes.size(); i++){
ans.add(this.edgesUsed.get(new Pair<V>(this.nodeIndex.inverse().get(nodes.get(i-1)), this.nodeIndex.inverse().get(nodes.get(i)))));
}
return ans;
}
else{
throw new RuntimeException();
}
}
示例14: loadGraphml
import edu.uci.ics.jung.graph.util.Pair; //導入依賴的package包/類
@Override
public void loadGraphml() throws Exception {
final G graph = factory.create();
MyGraphMLReader gmlr = loadGraphmlInGraph(urlPath, graph);
Collection<String> verteces = graph.getVertices();
for (String vertex :verteces){
if(!entireGraph.containsVertex(vertex)){
entireGraph.addVertex(vertex);
}
}
Collection<String> edges = graph.getEdges();
for (String edge : edges){
Pair<String> endpoints = graph.getEndpoints(edge);
if (!entireGraph.containsEdge(edge)){
entireGraph.addEdge(edge,endpoints);
}
}
graphMetadatas = gmlr.getGraphMetadata();
edgeMetadatas = gmlr.getEdgeMetadata();
vertexMetadatas = gmlr.getVertexMetadata();
notifyListeners(gmlr.getVertexMetadata(), gmlr.getEdgeMetadata(), graph);
}
示例15: 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;
}