public Collection<Edge> getEdgeSet() { ArrayList<Edge> l; Iterator<Edge> it; elementLock.lock(); l = new ArrayList<Edge>(wrappedElement.getDegree()); it = wrappedElement.getEachEdge().iterator(); while (it.hasNext()) l.add(sg.getEdge(it.next().getIndex())); elementLock.unlock(); return l; }
public Collection<Edge> getEdgeSet() { ArrayList<Edge> l; Iterator<Edge> it; elementLock.lock(); l = new ArrayList<Edge>(wrappedElement.getDegree()); it = wrappedElement.getEachEdge().iterator(); while (it.hasNext()) l.add(sg.getEdge(it.next().getIndex())); elementLock.unlock(); return l; }
private void initializeAlgorithm() { for (Node aNode : graph.getEachNode()) { for (Edge anEdge : aNode.getEachEdge()) { double aWeight = anEdge.getNumber(getWeightAttribute()); if (Double.isNaN(aWeight)) { weighted = false; } } distanceMap.put(aNode, 0.0); } }
@SuppressWarnings("unchecked") public T next() { if (qHead >= qTail) throw new NoSuchElementException(); Node current = queue[qHead++]; int level = depth[current.getIndex()] + 1; Iterable<Edge> edges = directed ? current.getEachLeavingEdge() : current.getEachEdge(); for (Edge e : edges) { Node node = e.getOpposite(current); int j = node.getIndex(); if (depth[j] == -1) { queue[qTail++] = node; depth[j] = level; } } return (T)current; }
@SuppressWarnings("unchecked") public T next() { if (qHead >= qTail) throw new NoSuchElementException(); Node current = queue[qHead++]; int level = depth[current.getIndex()] + 1; Iterable<Edge> edges = directed ? current.getEachLeavingEdge() : current.getEachEdge(); for (Edge e : edges) { Node node = e.getOpposite(current); int j = node.getIndex(); if (depth[j] == -1) { queue[qTail++] = node; depth[j] = level; } } return (T)current; }
/** * Compute the weighted degree of a given node. For each entering * and leaving 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 twice. * 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 for weights on edges, it must be a number. * @param defaultWeightValue The default weight value to use if edges do not have the 'weightAttribute'. * @return The weighted degree. */ public static double weightedDegree(Node node, String weightAttribute, double defaultWeightValue) { double wdegree = 0; for(Edge edge:node.getEachEdge()) { if(edge.hasNumber(weightAttribute)) { if(edge.getSourceNode() == edge.getTargetNode()) wdegree += edge.getNumber(weightAttribute) * 2; else wdegree += edge.getNumber(weightAttribute); } else { if(edge.getSourceNode() == edge.getTargetNode()) wdegree += defaultWeightValue * 2; else wdegree += defaultWeightValue; } } return wdegree; }
/** * Compute the weighted degree of a given node. For each entering * and leaving 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 twice. * 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 for weights on edges, it must be a number. * @param defaultWeightValue The default weight value to use if edges do not have the 'weightAttribute'. * @return The weighted degree. */ public static double weightedDegree(Node node, String weightAttribute, double defaultWeightValue) { double wdegree = 0; for(Edge edge:node.getEachEdge()) { if(edge.hasNumber(weightAttribute)) { if(edge.getSourceNode() == edge.getTargetNode()) wdegree += edge.getNumber(weightAttribute) * 2; else wdegree += edge.getNumber(weightAttribute); } else { if(edge.getSourceNode() == edge.getTargetNode()) wdegree += defaultWeightValue * 2; else wdegree += defaultWeightValue; } } return wdegree; }