/** * Inform User of Network Stats. * * @param taskMonitor */ private void informUserOfGraphStats(CyNetwork newNetwork, TaskMonitor taskMonitor) { NumberFormat formatter = new DecimalFormat("#,###,###"); StringBuffer sb = new StringBuffer(); // Give the user some confirmation sb.append("Successfully loaded network from: "); sb.append(url); sb.append("\n\nNetwork contains " + formatter.format(newNetwork.getNodeCount())); sb.append(" nodes and " + formatter.format(newNetwork.getEdgeCount())); sb.append(" edges.\n\n"); // TODO: Port this // if (newNetwork.getNodeCount() < Integer.parseInt(CytoscapeInit.getProperties() // // .getProperty("viewThreshold"))) { // sb.append("Network is under " // + CytoscapeInit.getProperties().getProperty("viewThreshold") // + " nodes. A view will be automatically created."); // } else { // sb.append("Network is over " // + CytoscapeInit.getProperties().getProperty("viewThreshold") // + " nodes. A view has not been created." // + " If you wish to view this network, use " // + "\"Create View\" from the \"Edit\" menu."); // } taskMonitor.setStatusMessage(sb.toString()); }
@Test public void testRemoveNodeIndexStaysConstant() { assertEquals(0, net.getNodeCount()); CyNode n0 = net.addNode(); CyNode n1 = net.addNode(); long n0i = n0.getSUID(); long n1i = n1.getSUID(); net.removeNodes(Collections.singletonList(n0)); long nnli = n1.getSUID(); assertEquals(nnli, n1i); }
@Test public void testRemoveNodeGetNodeFromIndex() { assertEquals(0, net.getNodeCount()); CyNode n0 = net.addNode(); CyNode n1 = net.addNode(); long n0i = n0.getSUID(); long n1i = n1.getSUID(); assertEquals(net.getNode(n0i), n0); assertEquals(net.getNode(n1i), n1); assertTrue(net.removeNodes(Collections.singletonList(n0))); assertNull(net.getNode(n0i)); assertEquals(n1, net.getNode(n1i)); }
/** Assuming we only create one network. */ protected CyNetwork checkSingleNetwork(List<CyNetworkView> views, int numNodes, int numEdges) { assertNotNull(views); assertEquals(1, views.size()); CyNetwork net = views.get(0).getModel(); assertNotNull(net); assertEquals(numNodes, net.getNodeCount()); assertEquals(numEdges, net.getEdgeCount()); return net; }
public BellmanFordStatsImpl findPath( CyNetwork network, CyNode source, boolean directed, WeightFunction function) { Map<CyNode, MetaNode> nodeToMetaNodeMap = new IdentityHashMap<CyNode, MetaNode>(); boolean negativeCycle = true; for (CyNode node : network.getNodeList()) { MetaNode metaNode = new MetaNode(node, Double.POSITIVE_INFINITY, null); nodeToMetaNodeMap.put(node, metaNode); } nodeToMetaNodeMap.get(source).setDistance(0.0); for (int i = 0; i < network.getNodeCount() - 1; i++) { for (CyEdge edge : network.getEdgeList()) { MetaNode sourceMetaNode = nodeToMetaNodeMap.get(edge.getSource()); MetaNode targetMetaNode = nodeToMetaNodeMap.get(edge.getTarget()); if (targetMetaNode.getDistance() > sourceMetaNode.getDistance() + function.getWeight(edge)) { targetMetaNode.setDistance(sourceMetaNode.getDistance() + function.getWeight(edge)); targetMetaNode.setPredecessor(sourceMetaNode.getNode()); } } } for (CyEdge edge : network.getEdgeList()) { MetaNode sourceMetaNode = nodeToMetaNodeMap.get(edge.getSource()); MetaNode targetMetaNode = nodeToMetaNodeMap.get(edge.getTarget()); if (targetMetaNode.getDistance() > sourceMetaNode.getDistance() + function.getWeight(edge)) negativeCycle = false; } return new BellmanFordStatsImpl(source, nodeToMetaNodeMap, negativeCycle); }