Select Git revision
GraphAnalyzer.java
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
GraphAnalyzer.java 1.10 KiB
package de.hhu.ba.yoshikoWrapper.cytoUtil;
import java.util.List;
import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyNetwork;
public class GraphAnalyzer {
public static boolean isMultiGraph(CyNetwork net) {
//TODO: Better algorithm?
int n = net.getNodeCount();
List<CyEdge> edges = net.getEdgeList();
//Easiest check: Check if the graph contains more edges than a complete graph
if (edges.size() > (n*(n-1))/2) {
return true;
}
for (int i = 0; i < edges.size()-1; i++) {
for (int j=i+1; j<edges.size();j++) {
if (connectSameNodes(edges.get(i),edges.get(j))){
return true;
}
}
}
return false;
}
private static boolean connectSameNodes(CyEdge e1, CyEdge e2) {
if (//Treating all edges as undirected here
(e1.getSource() == e2.getTarget() && e1.getTarget() == e2.getSource()) ||
(e1.getSource() == e2.getSource() && e1.getTarget() == e2.getTarget())
) {
return true;
}
return false;
}
public static boolean isDirected(CyNetwork net) {
for (CyEdge e: net.getEdgeList()) {
if (e.isDirected()) {
return true;
}
}
return false;
}
}