public int getDegree() { int d; elementLock.lock(); d = wrappedElement.getDegree(); elementLock.unlock(); return d; }
public int getDegree() { int d; elementLock.lock(); d = wrappedElement.getDegree(); elementLock.unlock(); return d; }
/** * Compute the degree distribution of this graph. Each cell of the returned * array contains the number of nodes having degree n where n is the index * of the cell. For example cell 0 counts how many nodes have zero edges, * cell 5 counts how many nodes have five edges. The last index indicates * the maximum degree. * * @complexity O(n) where n is the number of nodes. */ public static int[] degreeDistribution(Graph graph) { if (graph.getNodeCount() == 0) return null; int max = 0; int[] dd; int d; for (Node node : graph) { d = node.getDegree(); if (d > max) max = d; } dd = new int[max + 1]; for (Node node : graph) { d = node.getDegree(); dd[d] += 1; } return dd; }
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; }
public Iterator<Node> getNeighborNodeIterator() { ArrayList<Node> l; Iterator<Node> it; elementLock.lock(); sg.elementLock.lock(); l = new ArrayList<Node>(wrappedElement.getDegree()); it = wrappedElement.getNeighborNodeIterator(); while (it.hasNext()) l.add(sg.getNode(it.next().getIndex())); sg.elementLock.unlock(); elementLock.unlock(); return l.iterator(); }
public Iterator<Node> getNeighborNodeIterator() { ArrayList<Node> l; Iterator<Node> it; elementLock.lock(); sg.elementLock.lock(); l = new ArrayList<Node>(wrappedElement.getDegree()); it = wrappedElement.getNeighborNodeIterator(); while (it.hasNext()) l.add(sg.getNode(it.next().getIndex())); sg.elementLock.unlock(); elementLock.unlock(); return l.iterator(); }
/** * Choose an edge at random from the edges connected to the given node. * * @param random * The random number generator to use. * @return An edge chosen at random, null if the node has no edges. * @complexity O(1). */ public static Edge randomEdge(Node node, Random random) { int n = node.getDegree(); if (n > 0) { return node.getEdge(random.nextInt(n)); // int r = random.nextInt(n); // int i = 0; // // for (Edge edge : node.getEdgeSet()) { // if (r == i) // return edge; // i++; // } } return null; }
/** * Choose an edge at random from the edges connected to the given node. * * @param random * The random number generator to use. * @return An edge chosen at random, null if the node has no edges. * @complexity O(1). */ public static Edge randomEdge(Node node, Random random) { int n = node.getDegree(); if (n > 0) { return node.getEdge(random.nextInt(n)); // int r = random.nextInt(n); // int i = 0; // // for (Edge edge : node.getEdgeSet()) { // if (r == i) // return edge; // i++; // } } return null; }
/** * Returns the value of the degree average deviation of the graph. * * @return The degree average deviation. * @complexity O(n) where n is the number of nodes. */ public static double degreeAverageDeviation(Graph graph) { double average = averageDegree(graph); double sum = 0; for (Node node : graph) { double d = node.getDegree() - average; sum += d * d; } return Math.sqrt(sum / graph.getNodeCount()); }
/** * Returns the value of the degree average deviation of the graph. * * @return The degree average deviation. * @complexity O(n) where n is the number of nodes. */ public static double degreeAverageDeviation(Graph graph) { double average = averageDegree(graph); double sum = 0; for (Node node : graph) { double d = node.getDegree() - average; sum += d * d; } return Math.sqrt(sum / graph.getNodeCount()); }
protected double findPath(LinkedList<Node> path, Node source, Node target) { path.addLast(source); if (source == target) return Double.MAX_VALUE; double minCf; for (int i = 0; i < source.getDegree(); i++) { Edge e = source.getEdge(i); Node o = e.getOpposite(source); if (getCapacity(source, o) - getFlow(source, o) > 0 && !path.contains(o)) { if ((minCf = findPath(path, o, target)) > 0) return Math.min(minCf, getCapacity(source, o) - getFlow(source, o)); } } path.removeLast(); return 0; } }
protected double findPath(LinkedList<Node> path, Node source, Node target) { path.addLast(source); if (source == target) return Double.MAX_VALUE; double minCf; for (int i = 0; i < source.getDegree(); i++) { Edge e = source.getEdge(i); Node o = e.getOpposite(source); if (getCapacity(source, o) - getFlow(source, o) > 0 && !path.contains(o)) { if ((minCf = findPath(path, o, target)) > 0) return Math.min(minCf, getCapacity(source, o) - getFlow(source, o)); } } path.removeLast(); return 0; } }
protected void computeCentrality() { int count = graph.getNodeCount(); switch (mode) { case INOUT: for (int idx = 0; idx < count; idx++) data[idx] = graph.getNode(idx).getDegree(); break; case IN: for (int idx = 0; idx < count; idx++) data[idx] = graph.getNode(idx).getInDegree(); break; case OUT: for (int idx = 0; idx < count; idx++) data[idx] = graph.getNode(idx).getOutDegree(); break; } }
protected void computeCentrality() { int count = graph.getNodeCount(); switch (mode) { case INOUT: for (int idx = 0; idx < count; idx++) data[idx] = graph.getNode(idx).getDegree(); break; case IN: for (int idx = 0; idx < count; idx++) data[idx] = graph.getNode(idx).getInDegree(); break; case OUT: for (int idx = 0; idx < count; idx++) data[idx] = graph.getNode(idx).getOutDegree(); break; } }
public void compute() { Node source = flowGraph.getNode(sourceId); Node sink = flowGraph.getNode(sinkId); if (source == null) throw new ElementNotFoundException("node \"%s\"", sourceId); if (sink == null) throw new ElementNotFoundException("node \"%s\"", sinkId); checkArrays(); loadCapacitiesFromAttribute(); for (int i = 0; i < flowGraph.getEdgeCount(); i++) { Edge e = flowGraph.getEdge(i); setFlow(e.getNode0(), e.getNode1(), 0); setFlow(e.getNode1(), e.getNode0(), 0); } double minCf; LinkedList<Node> path = new LinkedList<Node>(); while ((minCf = findPath(path, source, sink)) > 0) { for (int i = 1; i < path.size(); i++) { Node u = path.get(i - 1); Node v = path.get(i); setFlow(u, v, getFlow(u, v) + minCf); setFlow(v, u, getFlow(v, u) - minCf); } path.clear(); } double flow = 0; for (int i = 0; i < source.getDegree(); i++) flow += getFlow(source, source.getEdge(i).getOpposite(source)); maximumFlow = flow; }