use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.
the class PartitionUtilTest method testPartition2.
@Test
public void testPartition2() {
CyNetworkView networkView = mock(CyNetworkView.class);
CyNetwork network = mock(CyNetwork.class);
when(networkView.getModel()).thenReturn(network);
EdgeWeighter edgeWeighter = new EdgeWeighter();
List<LayoutPartition> result = PartitionUtil.partition(networkView, false, edgeWeighter);
assertNotNull(result);
assertEquals(0, result.size());
}
use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.
the class PartitionUtilTest method testPartition1.
@Test
public void testPartition1() {
CyNetworkView networkView = mock(CyNetworkView.class);
CyNetwork network = mock(CyNetwork.class);
when(networkView.getModel()).thenReturn(network);
Collection<CyNode> nodes = new ArrayList<CyNode>();
EdgeWeighter edgeWeighter = new EdgeWeighter();
List<LayoutPartition> result = PartitionUtil.partition(networkView, nodes, edgeWeighter);
assertNotNull(result);
assertEquals(0, result.size());
}
use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.
the class AbstractCyNodeTest method testSetNestedNetwork.
@Test
public void testSetNestedNetwork() {
CyNode n1 = net.addNode();
CyNetwork net2 = mock(CyNetwork.class);
n1.setNetworkPointer(net2);
assertNotNull(n1.getNetworkPointer());
assertEquals(net2, n1.getNetworkPointer());
}
use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.
the class PartitionUtil method partition.
/**
* Partition the graph -- this builds the LayoutEdge and LayoutNode
* arrays as a byproduct. The algorithm for this was taken from
* algorithms/graphPartition/SGraphPartition.java.
*
* @param networkView the CyNetworkView representing the graph
* @param nodeSet the set of nodes to consider
* @param edgeWeighter the weighter to use for edge weighting
* @return a List of LayoutPartitions
*/
public static List<LayoutPartition> partition(CyNetworkView networkView, Collection<CyNode> nodeSet, EdgeWeighter edgeWeighter) {
final List<LayoutPartition> partitions = new ArrayList<LayoutPartition>();
final CyNetwork network = networkView.getModel();
final Map<CyNode, Integer> nodesSeenMap = new HashMap<CyNode, Integer>();
final Map<CyEdge, Integer> edgesSeenMap = new HashMap<CyEdge, Integer>();
final Map<CyNode, View<CyNode>> nodesToViews = new HashMap<CyNode, View<CyNode>>();
int partitionNumber = 1;
// Initialize the maps
for (final View<CyNode> nv : networkView.getNodeViews()) {
nodesSeenMap.put(nv.getModel(), m_NODE_HAS_NOT_BEEN_SEEN);
nodesToViews.put(nv.getModel(), nv);
}
for (CyEdge edge : network.getEdgeList()) edgesSeenMap.put(edge, m_NODE_HAS_NOT_BEEN_SEEN);
// OK, now traverse the graph
for (final CyNode node : nodeSet) {
// Have we seen this already?
if (nodesSeenMap.get(node) == m_NODE_HAS_BEEN_SEEN)
continue;
// Nope, first time
final LayoutPartition part = new LayoutPartition(network.getNodeCount(), network.getEdgeCount());
part.setPartitionNumber(partitionNumber++);
// Set the edge weighter
part.setEdgeWeighter(edgeWeighter);
nodesSeenMap.put(node, m_NODE_HAS_BEEN_SEEN);
// Traverse through all connected nodes
traverse(network, networkView, nodesToViews, node, part, nodesSeenMap, edgesSeenMap);
// Done -- finalize the parition
part.trimToSize();
// Finally, now that we're sure we've touched all of our
// nodes. Fix up our edgeLayout list to have all of our
// layoutNodes
part.fixEdges();
partitions.add(part);
}
// Now sort the partitions based on the partition's node count
Collections.sort(partitions, new Comparator<LayoutPartition>() {
public int compare(LayoutPartition p1, LayoutPartition p2) {
return (p2.size() - p1.size());
}
public boolean equals(LayoutPartition obj) {
return false;
}
});
return partitions;
}
use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.
the class AbstractCyNodeTest method testSetNullNestedNetwork.
// null nested networks are allowed
@Test
public void testSetNullNestedNetwork() {
CyNode n1 = net.addNode();
// put a real network here first
CyNetwork net2 = mock(CyNetwork.class);
n1.setNetworkPointer(net2);
assertNotNull(n1.getNetworkPointer());
assertEquals(net2, n1.getNetworkPointer());
// now put a null network to verify that we've "unset" things
n1.setNetworkPointer(null);
assertNull(n1.getNetworkPointer());
}
Aggregations