本文整理汇总了Java中org.jgrapht.graph.SimpleGraph.containsEdge方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleGraph.containsEdge方法的具体用法?Java SimpleGraph.containsEdge怎么用?Java SimpleGraph.containsEdge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgrapht.graph.SimpleGraph
的用法示例。
在下文中一共展示了SimpleGraph.containsEdge方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildPartitionListenableGraph
import org.jgrapht.graph.SimpleGraph; //导入方法依赖的package包/类
/**
* Builds a listenable graph based on the adjacency of the members of the
* passed partition,deciding if an edge exist between any two members will
* be based on the passed graph
*
* @param par
* @param graph
* @return a listenable graph
*/
public static ListenableUndirectedGraph<Node, Border> buildPartitionListenableGraph(Partition par, SimpleGraph<Node, Border> graph) {
ListenableUndirectedGraph<Node, Border> parGraph = new ListenableUndirectedGraph<Node, Border>(Border.class);
ArrayList<Node> members = par.getMembers();
for (int i = 0; i < members.size(); i++)
{
parGraph.addVertex(members.get(i));
}
for (int i = 0; i < members.size(); i++) {
for (int j = 0; j < members.size(); j++) {
if (i != j) {
if (graph.containsEdge(members.get(i), members.get(j))) {
parGraph.addEdge(members.get(i), members.get(j), new Border(members.get(i), members.get(j)));
}
}
}
}
return parGraph;
}
示例2: toAdjacencyMatrix
import org.jgrapht.graph.SimpleGraph; //导入方法依赖的package包/类
public static double[][] toAdjacencyMatrix(SimpleGraph graph) {
Set set1 = graph.vertexSet();
Iterator it1 = set1.iterator();
double[][] adj = new double[set1.size()][set1.size()];
int i = 0, j = 0;
while (it1.hasNext()) {
Object p1 = it1.next();
Set set2 = graph.vertexSet();
Iterator it2 = set2.iterator();
j = 0;
while (it2.hasNext()) {
Object p2 = it2.next();
if (graph.containsEdge(p1, p2)) {
adj[i][j] = 1;
} else {
adj[i][j] = 0;
}
j++;
}
i++;
}
return adj;
}
示例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: adjacentInMembersTo
import org.jgrapht.graph.SimpleGraph; //导入方法依赖的package包/类
public static Node adjacentInMembersTo(SimpleGraph<Node, Border> graph, ArrayList<Node> partitionMembers, Node node)
{
for (int i = 0; i < partitionMembers.size(); i++) {
if (graph.containsEdge(partitionMembers.get(i), node))
return partitionMembers.get(i);
}
return null;
}
示例5: enumerate_C_Cliques
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, because they are neighbours of vertex u via C-Edges
* @param d Set of vertices which cannot directly be added to C because they are neighbours of u via D-Edges
* @param s set of vertices which are not allowed to be added to C
* @return the largest clique in graph g
*/
private static <V> Set<V> enumerate_C_Cliques(SimpleGraph<V,CompatibilityEdge> g, Set<V> c, Set<V> p, Set<V> d, Set<V> t, int currentmaxresult){
Set<V> result = new LinkedHashSet<V>(c);
if(p.isEmpty() || p.size() + c.size() + d.size() <= currentmaxresult){//if p=EMPTY
return result; //REPORT.CLIQUE
} else {
List<V> pList = new ArrayList<V>(p);
V ut = pList.get(0);
for(V ui : p){ //for i <- 1 to k
Set<V> target = new LinkedHashSet<V>(d);
target.removeAll(neighbourVertices(g, ut)); //target is all vertices from D that are not adjacent to ut
if(!g.containsEdge(ut, ui) || // if ui is not adjacent to ut
hasCPath(g, ui, target, new LinkedHashSet<V>())){ //or ui is connected via a c-path to a
//vertex form D that is not adjacent to ut
pList.remove(ui); //P <-P\{ui}
Set<V> pNext = new LinkedHashSet<V>(pList); //P' <- P
Set<V> dNext = new LinkedHashSet<V>(d); //D' <- D
Set<V> n = neighbourVertices(g,ui);//N <- { v ELEMENTOF V | {ui,v} ELEMENTOF E }
for(V v : d){ // for all v ELEMENTOF D'
//(note that D and D' are the same at this point, to allow concurrent modification we loop over D)
if(p.contains(v)){ //if v ELEMENTOF P
pNext.add(v); // then P' = P' UNION {v}
} else if(d.contains(v)){ // else if v ELEMENTOF D \\can v be added to P?
if(hasC_Edge(g, ui, v)){ // then if v and ui are adjacent via a C-edge
// \\is v an initializing vertex
if(!t.contains(v)){ // if v ELEMENTOF T
} else {
pNext.add(v); // else P'=P' UNION {v}
}
dNext.remove(v);
}
}
}
Set<V> cNext = new LinkedHashSet<V>(c);
cNext.add(ui); //C UNION {ui}
pNext.retainAll(n); //P' INTERSECTION N
dNext.retainAll(n); //D' INTERSECTION N
Set<V> clique = enumerate_C_Cliques(g, cNext, pNext, dNext, t, currentmaxresult); //ENUMERATE.C_CLIQUES....
if(clique.size() > result.size()){
result = clique;
currentmaxresult = clique.size();
}
}
}
}
return result;
}