private Edge getEnteringEdge(String toNodeId) { Collection<Edge> enteringEdges = graph.getNode(toNodeId).getEnteringEdgeSet(); if (enteringEdges.size() == 1) return enteringEdges.iterator().next(); else { for (Edge e : enteringEdges) { if (e.getId().startsWith("shipment")) { continue; } return e; } } return null; }
private Edge getEnteringEdge(String toNodeId) { Collection<Edge> enteringEdges = graph.getNode(toNodeId).getEnteringEdgeSet(); if (enteringEdges.size() == 1) return enteringEdges.iterator().next(); else { for (Edge e : enteringEdges) { if (e.getId().startsWith("shipment")) { continue; } return e; } } return null; }
private void computeKahns() { while (!sourceNodes.isEmpty()) { Node aSourceNode = sourceNodes.iterator().next(); sourceNodes.remove(aSourceNode); sortedNodes[index] = aSourceNode; index++; for (Iterator<Edge> it = aSourceNode.getLeavingEdgeIterator(); it.hasNext(); ) { Edge aLeavingEdge = it.next(); Node aTargetNode = aLeavingEdge.getTargetNode(); it.remove(); aTargetNode.getEnteringEdgeSet().remove(aLeavingEdge); if (aTargetNode.getEnteringEdgeSet().isEmpty()) { sourceNodes.add(aTargetNode); } } } boolean hasCycle = false; for (Node aNode : graph.getEachNode()) { if (!aNode.getEnteringEdgeSet().isEmpty()) { hasCycle = true; break; } } if (hasCycle) { throw new GraphHasCycleException(); } }
/** * Compute the weighted entering degree of a given node. For each * entering edge the value contained by the 'weightAttribute' is * considered. If the edge does not have such an attribute, the value * 'defaultWeightValue' is used instead. Loop edges are counted once * if directed, but twice if undirected. The 'weightAttribute' must * contain a number or the default value is used. * @param node The node to consider. * @param weightAttribute The name of the attribute to look on edges, it must be a number. * @param defaultWeightValue The default weight value to use if edges do not have the 'weightAttribute'. * @return The entering weighted degree. */ public static double enteringWeightedDegree(Node node, String weightAttribute, double defaultWeightValue) { double wdegree = 0; for(Edge edge:node.getEnteringEdgeSet()) { if(edge.hasNumber(weightAttribute)) { wdegree += edge.getNumber(weightAttribute); } else { wdegree += defaultWeightValue; } } return wdegree; }
/** * Compute the weighted entering degree of a given node. For each * entering edge the value contained by the 'weightAttribute' is * considered. If the edge does not have such an attribute, the value * 'defaultWeightValue' is used instead. Loop edges are counted once * if directed, but twice if undirected. The 'weightAttribute' must * contain a number or the default value is used. * @param node The node to consider. * @param weightAttribute The name of the attribute to look on edges, it must be a number. * @param defaultWeightValue The default weight value to use if edges do not have the 'weightAttribute'. * @return The entering weighted degree. */ public static double enteringWeightedDegree(Node node, String weightAttribute, double defaultWeightValue) { double wdegree = 0; for(Edge edge:node.getEnteringEdgeSet()) { if(edge.hasNumber(weightAttribute)) { wdegree += edge.getNumber(weightAttribute); } else { wdegree += defaultWeightValue; } } return wdegree; }
/** * Compute the scores for all relevant communities for the selected node * using epidemic label propagation paradigm. * * @param u * The node for which the scores computation is performed * @complexity O(DELTA) where DELTA is is the average node degree in the * network */ protected void communityScores(Node u) { /* * Reset the scores for each communities */ communityScores = new HashMap<Object, Double>(); /* * Iterate over the nodes that this node "hears" */ for (Edge e : u.getEnteringEdgeSet()) { Node v = e.getOpposite(u); /* * Update the count for this community */ if (v.hasAttribute(marker)) if (communityScores.get(v.getAttribute(marker)) == null) communityScores.put(v.getAttribute(marker), 1.0); else communityScores.put(v.getAttribute(marker), communityScores.get(v.getAttribute(marker)) + 1.0); } }
/** * Compute the scores for all relevant communities for the selected node * using epidemic label propagation paradigm. * * @param u * The node for which the scores computation is performed * @complexity O(DELTA) where DELTA is is the average node degree in the * network */ protected void communityScores(Node u) { /* * Reset the scores for each communities */ communityScores = new HashMap<Object, Double>(); /* * Iterate over the nodes that this node "hears" */ for (Edge e : u.getEnteringEdgeSet()) { Node v = e.getOpposite(u); /* * Update the count for this community */ if (v.hasAttribute(marker)) if (communityScores.get(v.getAttribute(marker)) == null) communityScores.put(v.getAttribute(marker), 1.0); else communityScores.put(v.getAttribute(marker), communityScores.get(v.getAttribute(marker)) + 1.0); } }
for (Edge e : u.getEnteringEdgeSet()) { Node v = e.getOpposite(u);
for (Edge e : u.getEnteringEdgeSet()) { Node v = e.getOpposite(u);
for (Edge e : u.getEnteringEdgeSet()) { Node v = e.getOpposite(u);
for (Edge e : u.getEnteringEdgeSet()) { Node v = e.getOpposite(u);
for (Edge e : node.getEnteringEdgeSet()) { Node v = e.getOpposite(node); if (v.hasAttribute(marker)
for (Edge e : node.getEnteringEdgeSet()) { Node v = e.getOpposite(node); if (v.hasAttribute(marker)