private void gotoNext() { while (edgeIt.hasNext()) { next = edgeIt.next().getOpposite(AbstractNode.this); if (!visited.contains(next)) { visited.add(next); return; } } next = null; }
private void gotoNext() { while (edgeIt.hasNext()) { next = edgeIt.next().getOpposite(AbstractNode.this); if (!visited.contains(next)) { visited.add(next); return; } } next = null; }
@SuppressWarnings("all") public <T extends Edge> T getEdgeToward(String id) { List<? extends Edge> edges = mygraph.connectivity.get(this); for (Edge edge : edges) { if (edge.getOpposite(this).getId().equals(id)) return (T) edge; } return null; }
@SuppressWarnings("all") public <T extends Edge> T getEdgeToward(String id) { List<? extends Edge> edges = mygraph.connectivity.get(this); for (Edge edge : edges) { if (edge.getOpposite(this).getId().equals(id)) return (T) edge; } return null; }
public State next() { return getState(it.next().getOpposite(source)); }
public State next() { return getState(it.next().getOpposite(source)); }
public <T extends Node> T getOpposite(Node node) { T n; if (node instanceof SynchronizedNode) node = ((SynchronizedNode) node).wrappedElement; sg.elementLock.lock(); n = sg.getNode(wrappedElement.getOpposite(node).getIndex()); sg.elementLock.unlock(); return n; }
/** * Returns the node preceding the target in the shortest path from the * source to the target. This node is the parent of the target in the * shortest path tree. * * @param target * a node * @return the predecessor of the target in the shortest path, {@code null} * if there is no path from the source to the target or if the * target and the source are the same node. * @see #getEdgeFromParent(Node) * @complexity O(1) */ public <T extends Node> T getParent(Node target) { Edge edge = getEdgeFromParent(target); if (edge == null) return null; return edge.getOpposite(target); }
/** * Returns the node preceding the target in the shortest path from the * source to the target. This node is the parent of the target in the * shortest path tree. * * @param target * a node * @return the predecessor of the target in the shortest path, {@code null} * if there is no path from the source to the target or if the * target and the source are the same node. * @see #getEdgeFromParent(Node) * @complexity O(1) */ public <T extends Node> T getParent(Node target) { Edge edge = getEdgeFromParent(target); if (edge == null) return null; return edge.getOpposite(target); }
public <T extends Node> T getOpposite(Node node) { T n; if (node instanceof SynchronizedNode) node = ((SynchronizedNode) node).wrappedElement; sg.elementLock.lock(); n = sg.getNode(wrappedElement.getOpposite(node).getIndex()); sg.elementLock.unlock(); return n; }
protected void extendPathStep() { int last = nodes.size() - 1; Node v = nodes.get(last); double lengthV = getPathLength(v); Iterator<Edge> it = iterators.get(last); while (it.hasNext()) { Edge e = it.next(); Node u = e.getOpposite(v); if (getPathLength(u) + getLength(e, v) == lengthV) { nodes.add(u); iterators.add(u.getEnteringEdgeIterator()); return; } } nodes.remove(last); iterators.remove(last); }
/** * Cross the given edge, eventually storing it in the memory and * incrementing its count as well as the count of the current node. * @param e The edge. */ protected void cross(Edge e) { current = e.getOpposite(current); addPass(e, current); addToTabu(current); }
protected void extendPathStep() { int last = nodes.size() - 1; Node v = nodes.get(last); double lengthV = getPathLength(v); Iterator<Edge> it = iterators.get(last); while (it.hasNext()) { Edge e = it.next(); Node u = e.getOpposite(v); if (getPathLength(u) + getLength(e, v) == lengthV) { nodes.add(u); iterators.add(u.getEnteringEdgeIterator()); return; } } nodes.remove(last); iterators.remove(last); }
/** * Cross the given edge, eventually storing it in the memory and * incrementing its count as well as the count of the current node. * @param e The edge. */ protected void cross(Edge e) { current = e.getOpposite(current); addPass(e, current); addToTabu(current); }
protected void gotoNext() { while (next != null) { int i = next.getIndex(); while (iterator[i].hasNext()) { Node neighbor = iterator[i].next().getOpposite(next); int j = neighbor.getIndex(); if (iterator[j] == null) { parent[j] = next; iterator[j] = directed ? neighbor.getLeavingEdgeIterator() : neighbor.getEnteringEdgeIterator(); depth[j] = depth[i] + 1; if (depth[j] > maxDepth) maxDepth = depth[j]; next = neighbor; return; } } next = parent[i]; } }
@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; }
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; } }
private void visitNode(Node node, int[] marks) { int mark = marks[node.getIndex()]; if (mark == MARK_TEMP) { throw new GraphHasCycleException(); } else if (mark == MARK_UNMARKED) { marks[node.getIndex()] = MARK_TEMP; for (Edge edge : node.getEachLeavingEdge()) { visitNode(edge.getOpposite(node), marks); } marks[node.getIndex()] = MARK_PERM; sortedNodes[index] = node; index--; } }