本文整理汇总了Java中org.jgrapht.Graphs.getOppositeVertex方法的典型用法代码示例。如果您正苦于以下问题:Java Graphs.getOppositeVertex方法的具体用法?Java Graphs.getOppositeVertex怎么用?Java Graphs.getOppositeVertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgrapht.Graphs
的用法示例。
在下文中一共展示了Graphs.getOppositeVertex方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPath
import org.jgrapht.Graphs; //导入方法依赖的package包/类
@Override
public RoutingPath getPath(Device from, Device to) {
List<Channel> path = DijkstraShortestPath.findPathBetween(
getGraph(), from, to);
if (path == null) {
return null;
}
List<Device> nodes = new ArrayList<Device>();
Device v = from;
nodes.add(from);
for (Channel e : path) {
v = Graphs.getOppositeVertex(getGraph(), e, v);
nodes.add(v);
}
return new RoutingPath(nodes, path);
}
示例2: getPath
import org.jgrapht.Graphs; //导入方法依赖的package包/类
@Override
public RoutingPath getPath(Device from, Device to) {
List<Channel> path = DijkstraShortestPath.findPathBetween(getGraph(),
from, to);
if (path == null) {
return null;
}
List<Device> nodes = new ArrayList<Device>();
Device v = from;
nodes.add(from);
for (Channel e : path) {
v = Graphs.getOppositeVertex(getGraph(), e, v);
nodes.add(v);
}
return new RoutingPath(nodes, path);
}
示例3: getSubGraph
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Extract a subgraph limited to the provided set of glyphs.
*
* @param set the provided set of glyphs
* @param graph the global graph to extract from
* @param checkEdges true if glyph edges may point outside the provided set.
* @return the graph limited to glyph set and related edges
*/
public static SimpleGraph<Glyph, GlyphLink> getSubGraph (Set<Glyph> set,
SimpleGraph<Glyph, GlyphLink> graph,
boolean checkEdges)
{
// Which edges should be extracted for this set?
Set<GlyphLink> setEdges = new LinkedHashSet<GlyphLink>();
for (Glyph glyph : set) {
Set<GlyphLink> glyphEdges = graph.edgesOf(glyph);
if (!checkEdges) {
setEdges.addAll(glyphEdges); // Take all edges
} else {
// Keep only the edges that link within the set
for (GlyphLink link : glyphEdges) {
Glyph opposite = Graphs.getOppositeVertex(graph, link, glyph);
if (set.contains(opposite)) {
setEdges.add(link);
}
}
}
}
SimpleGraph<Glyph, GlyphLink> subGraph = new SimpleGraph<Glyph, GlyphLink>(GlyphLink.class);
Graphs.addAllVertices(subGraph, set);
Graphs.addAllEdges(subGraph, graph, setEdges);
return subGraph;
}
示例4: buildAdjacencyMatrix
import org.jgrapht.Graphs; //导入方法依赖的package包/类
protected INDArray buildAdjacencyMatrix(Graph<V, E> graph, Map<V, Integer> index) {
final double[][] matrix = new double[graph.vertexSet().size()][graph.vertexSet().size()];
for (Map.Entry<V, Integer> entry : index.entrySet()) {
for (final E edge : graph.edgesOf(entry.getKey())) {
final V neighbor = Graphs.getOppositeVertex(graph, edge, entry.getKey());
matrix[entry.getValue()][index.get(neighbor)] = graph.getEdgeWeight(edge);
}
}
for (int r = 0; r < matrix.length; r++) matrix[r][r] = 1;
return Nd4j.create(matrix);
}
示例5: getPrioritySubset
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Returns a List with unique elements,
* @param v1 vertex from g1
* @return
*/
public List<V> getPrioritySubset(V v1){
//The resulting list
List<V> result = new ArrayList<V>();
//list of already mapped vertices that neighbour v1
List<V> v1Others = new ArrayList<V>();
V v1other;
V v2other;
for(E e1 : g1.edgesOf(v1)){
v1other = Graphs.getOppositeVertex(g1, e1, v1);
if(mappedVerticesFromG1.contains(v1other)){
v1Others.add(v1other);
}
}
for(V v2 : g2.vertexSet()){
//if v2's label is the same of v1's label and v2 has not been mapped yet
if(v1.getLabel().equals(v2.getLabel()) && !mappedVerticesFromG2.contains(v2)){
//test if there is an edge to a vertex which has already been mapped
for(E e2 : g2.edgesOf(v2)){
v2other = Graphs.getOppositeVertex(g2, e2, v2);
//if the vertex v2other has already been mapped
if(mappedVerticesFromG2.contains(v2other)){
//labels are not checked, this is done at a later stage anyway and doing it twice is not needed and takes too much time
result.add(v2);
break;
}
}
}
}
return result;
}
示例6: createEdgeList
import org.jgrapht.Graphs; //导入方法依赖的package包/类
private void createEdgeList(SimpleDirectedWeightedGraph<Object,IntraDomainEdge> graph, ClosestFirstIteratorModified<Object,IntraDomainEdge> iter, Object startVertex, Object endVertex)
{
List<IntraDomainEdge> edgeList = new ArrayList<IntraDomainEdge>();
Object v = endVertex;
while (true) {
IntraDomainEdge edge = iter.getSpanningTreeEdge(v);
if (edge == null) {
break;
}
edgeList.add(edge);
v = Graphs.getOppositeVertex(graph, edge, v);
}
Collections.reverse(edgeList);
double pathLength = iter.getShortestPathLength(endVertex);
path =
new GraphPathImpl<Object,IntraDomainEdge>(
graph,
startVertex,
endVertex,
edgeList,
pathLength);
}
示例7: addUnseenChildrenOf
import org.jgrapht.Graphs; //导入方法依赖的package包/类
private void addUnseenChildrenOf(V vertex)
{
for (E edge : specifics.edgesOf(vertex)) {
if (nListeners != 0) {
fireEdgeTraversed(createEdgeTraversalEvent(edge));
}
V oppositeV = Graphs.getOppositeVertex(graph, edge, vertex);
if (isSeenVertex(oppositeV)) {
encounterVertexAgain(oppositeV, edge);
} else {
encounterVertex(oppositeV, edge);
}
}
}
示例8: calculatePathLength
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Determine path length to a vertex via an edge, using the path length for
* the opposite vertex.
*
* @param vertex the vertex for which to calculate the path length.
* @param edge the edge via which the path is being extended.
*
* @return calculated path length.
*/
private double calculatePathLength(V vertex, E edge)
{
assertNonNegativeEdge(edge);
V otherVertex = Graphs.getOppositeVertex(getGraph(), edge, vertex);
FibonacciHeapNode<QueueEntry<V, E>> otherEntry =
getSeenData(otherVertex);
return otherEntry.getKey()
+ getGraph().getEdgeWeight(edge);
}
示例9: createEdgeList
import org.jgrapht.Graphs; //导入方法依赖的package包/类
private void createEdgeList(
Graph<V, E> graph,
ClosestFirstIterator<V, E> iter,
V startVertex,
V endVertex)
{
List<E> edgeList = new ArrayList<E>();
V v = endVertex;
while (true) {
E edge = iter.getSpanningTreeEdge(v);
if (edge == null) {
break;
}
edgeList.add(edge);
v = Graphs.getOppositeVertex(graph, edge, v);
}
Collections.reverse(edgeList);
double pathLength = iter.getShortestPathLength(endVertex);
path =
new GraphPathImpl<V, E>(
graph,
startVertex,
endVertex,
edgeList,
pathLength);
}
示例10: getOppositeInter
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Report the opposite inter across the given relation of the provided inter
*
* @param inter one side of the relation
* @param relation the relation to cross
* @return the vertex at the opposite side of the relation
*/
public Inter getOppositeInter (Inter inter,
Relation relation)
{
return Graphs.getOppositeVertex(this, relation, inter);
}