Skip to content
Snippets Groups Projects
Select Git revision
  • 80a9cd87e45c78fda06ae9f29c166c1dbee7dd78
  • master default
  • dev_general
  • 0.1.5
  • 0.1.4
  • 0.1.3
  • 0.1.2
  • 0.1.1
8 results

GraphAnalyzer.java

Blame
  • user avatar
    Philipp Spohr authored
    Various small layout optimizations/fixes
    Added killswitches for result processing tasks
    Backend optimization
    740d75e6
    History
    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;
    	}
    }