本文整理汇总了Java中org.jgrapht.graph.SimpleGraph.edgesOf方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleGraph.edgesOf方法的具体用法?Java SimpleGraph.edgesOf怎么用?Java SimpleGraph.edgesOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgrapht.graph.SimpleGraph
的用法示例。
在下文中一共展示了SimpleGraph.edgesOf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: adjacentsOf
import org.jgrapht.graph.SimpleGraph; //导入方法依赖的package包/类
/**
*
* @param graph
* @param node
* @return An array of nodes that are adjacent to the passed node in the graph
*/
public static Node[] adjacentsOf(SimpleGraph<Node, Border> graph, Node node)
{
ArrayList<Border> edges = new ArrayList<Border>(graph.edgesOf(node));
Node[] adjacents = new Node[edges.size()];
for(int i =0 ; i < edges.size();i++)
{
adjacents[i] = edges.get(i).getN1().equals(node)?edges.get(i).getN2():edges.get(i).getN1();
}
return adjacents;
}
示例2: getSubGraph
import org.jgrapht.graph.SimpleGraph; //导入方法依赖的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;
}
示例3: enumerateCliques
import org.jgrapht.graph.SimpleGraph; //导入方法依赖的package包/类
/**
*
* @param g The graph where the largest clique needs to be found
* @param c Set of vertices belonging to the current clique
* @param p Set of vertices which can be added to C
* @param s set of vertices which are not allowed to be added to C
* @return the largest clique in graph g
*/
private static <V,E> Set<V> enumerateCliques(SimpleGraph<V,E> g, Set<V> c, Set<V> p, int currentmaxresult){
if(interruptFlag) return null;
Set<V> result = new LinkedHashSet<V>(c);
if(p.isEmpty() || p.size() + c.size() <= currentmaxresult){ //if p=EMPTY and s=EMPTY
//check for s.isEmpty is removed because the code will return the same result if only P is empty
//added p.size() + c.size() <= currentmaxresult, if this is true, then the new clique can not be bigger then the clique that has already been found
return result; //REPORT.CLIQUE
} else {
List<V> pList = new ArrayList<V>(p);
V ut = pList.get(0); //Let ut be a vertex from P
for(V currentVertex : p){ //for i <- 1 to k
if(!g.containsEdge(ut, currentVertex)){ //if ui is not adjacent ut ut
pList.remove(currentVertex); //P <-P\{ui}
Set<V> pNext = new LinkedHashSet<V>(pList); //P' <- P
Set<V> n = new LinkedHashSet<V>();
for(E edge : g.edgesOf(currentVertex)){
V neighbour = g.getEdgeSource(edge);
if(neighbour.equals(currentVertex)){
neighbour = g.getEdgeTarget(edge);
}
n.add(neighbour);
} //N <- { v ELEMENTOF V | {ui,v} ELEMENTOF E }
Set<V> cNext = new LinkedHashSet<V>(c);
cNext.add(currentVertex); //C UNION {ui}
pNext.retainAll(n); //P' INTERSECTION N
Set<V> clique = enumerateCliques(g, cNext, pNext, currentmaxresult); //ENUMERATE.CLIQUES....
if(clique.size() > result.size()){
result = clique;
currentmaxresult = clique.size();
}
}
}
}
return result;
}
示例4: neighbourVertices
import org.jgrapht.graph.SimpleGraph; //导入方法依赖的package包/类
/**
*
* @param u a Vertex of g
* @return {v ELEMENTOF V | {u,v} ELEMENTOF E}
*/
private static <V,E> Set<V> neighbourVertices(SimpleGraph<V,E> g, V u){
Set<V> result = new LinkedHashSet<V>();
for(E edge : g.edgesOf(u)){
V neighbour = g.getEdgeSource(edge);
if(neighbour.equals(u)){
neighbour = g.getEdgeTarget(edge);
}
result.add(neighbour);
}
return result;
}
示例5: neighbour_C_Vertices
import org.jgrapht.graph.SimpleGraph; //导入方法依赖的package包/类
/**
* return only the vertices that neighbour u with C_Edges
* @param u a Vertex of g
* @return {v ELEMENTOF V | {u,v} ELEMENTOF E}
*/
private static <V> Set<V> neighbour_C_Vertices(SimpleGraph<V,CompatibilityEdge> g, V u){
Set<V> result = new LinkedHashSet<V>();
for(CompatibilityEdge edge : g.edgesOf(u)){
if(edge.isC_Edge()){
V neighbour = g.getEdgeSource(edge);
if(neighbour.equals(u)){
neighbour = g.getEdgeTarget(edge);
}
result.add(neighbour);
}
}
return result;
}
示例6: enumerateCliques
import org.jgrapht.graph.SimpleGraph; //导入方法依赖的package包/类
/**
*
* @param g The graph where the largest clique needs to be found
* @param c Set of vertices belonging to the current clique
* @param p Set of vertices which can be added to C
* @param s set of vertices which are not allowed to be added to C
* @return the largest clique in graph g
*/
private static <V,E> Set<V> enumerateCliques(SimpleGraph<V,E> g, Set<V> c, Set<V> p, int currentmaxresult){
Set<V> result = new LinkedHashSet<V>(c);
if(p.isEmpty() || p.size() + c.size() <= currentmaxresult){ //if p=EMPTY and s=EMPTY
//check for s.isEmpty is removed because the code will return the same result if only P is empty
return result; //REPORT.CLIQUE
} else {
Set<V> pCopy = new LinkedHashSet<V>(p);
for(V currentVertex : p){ //for i <- 1 to k
pCopy.remove(currentVertex); //P <-P\{ui}
Set<V> pNext = new LinkedHashSet<V>(pCopy); //P' <- P
Set<V> n = new LinkedHashSet<V>();
for(E edge : g.edgesOf(currentVertex)){
V neighbour = g.getEdgeSource(edge);
if(neighbour.equals(currentVertex)){
neighbour = g.getEdgeTarget(edge);
}
n.add(neighbour);
} //N <- { v ELEMENTOF V | {ui,v} ELEMENTOF E }
Set<V> cNext = new LinkedHashSet<V>(c);
cNext.add(currentVertex); //C UNION {ui}
pNext.retainAll(n); //P' INTERSECTION N
Set<V> clique = enumerateCliques(g, cNext, pNext, currentmaxresult); //ENUMERATE.CLIQUES....
if(clique.size() > result.size()){
result = clique;
currentmaxresult = clique.size();
}
}
}
return result;
}