/** * Checks if an edge is incident to this node. Utility method that can be * useful in subclasses. * * @param e * an edge * @return {@code true} if {@code e} is incident edge for this node. */ public boolean isIncidentEdge(Edge e) { return e.getSourceNode() == this || e.getTargetNode() == this; } }
/** * Checks if an edge is incident to this node. Utility method that can be * useful in subclasses. * * @param e * an edge * @return {@code true} if {@code e} is incident edge for this node. */ public boolean isIncidentEdge(Edge e) { return e.getSourceNode() == this || e.getTargetNode() == this; } }
private void fillDistanceMapUnweighted(Node[] theSortedArray) { for (Node aNode : theSortedArray) { for (Edge anEdge : aNode.getEachEnteringEdge()) { Node aSourceNode = anEdge.getSourceNode(); Node aTargetNode = anEdge.getTargetNode(); Double aMaxDistance = Math.max(distanceMap.get(aTargetNode), distanceMap.get(aSourceNode)) + 1; distanceMap.put(aTargetNode, aMaxDistance); } } }
public <T extends Node> T getTargetNode() { T n; sg.elementLock.lock(); n = sg.getNode(wrappedElement.getTargetNode().getIndex()); sg.elementLock.unlock(); return n; }
public <T extends Node> T getTargetNode() { T n; sg.elementLock.lock(); n = sg.getNode(wrappedElement.getTargetNode().getIndex()); sg.elementLock.unlock(); return n; }
private static String toString(Graph g) { StringBuilder buffer = new StringBuilder(); buffer.append("id=\"").append(g.getId()).append("\" node={"); for (Node n : g) buffer.append("\"").append(n.getId()).append("\", "); buffer.append("}, edges={"); for (Edge e : g.getEachEdge()) buffer.append("\"").append(e.getId()).append("\":\"") .append(e.getSourceNode().getId()).append("\"--\"") .append(e.getTargetNode().getId()).append("\", "); buffer.append("}"); return buffer.toString(); } }
private static String toString(Graph g) { StringBuilder buffer = new StringBuilder(); buffer.append("id=\"").append(g.getId()).append("\" node={"); for (Node n : g) buffer.append("\"").append(n.getId()).append("\", "); buffer.append("}, edges={"); for (Edge e : g.getEachEdge()) buffer.append("\"").append(e.getId()).append("\":\"") .append(e.getSourceNode().getId()).append("\"--\"") .append(e.getTargetNode().getId()).append("\", "); buffer.append("}"); return buffer.toString(); } }
/** * Checks if an edge enters this node. Utility method that can be useful in * subclasses. * * @param e * an edge * @return {@code true} if {@code e} is entering edge for this node. */ public boolean isEnteringEdge(Edge e) { return e.getTargetNode() == this || (!e.isDirected() && e.getSourceNode() == this); }
private void fillDistanceMapWeighted(Node[] theSortedArray) { for (Node aNode : theSortedArray) { for (Edge anEdge : aNode.getEachEnteringEdge()) { Node aSourceNode = anEdge.getSourceNode(); Node aTargetNode = anEdge.getTargetNode(); double aWeight = anEdge.getNumber(getWeightAttribute()); Double aMaxDistance = Math.max(distanceMap.get(aTargetNode), distanceMap.get(aSourceNode) + aWeight); distanceMap.put(aTargetNode, aMaxDistance); } } }
/** * Checks if an edge enters this node. Utility method that can be useful in * subclasses. * * @param e * an edge * @return {@code true} if {@code e} is entering edge for this node. */ public boolean isEnteringEdge(Edge e) { return e.getTargetNode() == this || (!e.isDirected() && e.getSourceNode() == this); }
/** * Checks if an edge leaves this node. Utility method that can be useful in * subclasses. * * @param e * an edge * @return {@code true} if {@code e} is leaving edge for this node. */ public boolean isLeavingEdge(Edge e) { return e.getSourceNode() == this || (!e.isDirected() && e.getTargetNode() == this); }
/** * Checks if an edge leaves this node. Utility method that can be useful in * subclasses. * * @param e * an edge * @return {@code true} if {@code e} is leaving edge for this node. */ public boolean isLeavingEdge(Edge e) { return e.getSourceNode() == this || (!e.isDirected() && e.getTargetNode() == this); }
/** * gets longest path * * @return longest path */ public Path getLongestPath() { Path path = new Path(); for (int i = 0; i < longestPath.size(); i++) { for (Edge edge : graph.getEachEdge()) { if (!edge.getSourceNode().equals(longestPath.get(i))) { continue; } if (!edge.getTargetNode().equals(longestPath.get(i + 1))) { continue; } path.add(edge.getSourceNode(), edge); } } return path; }
/** * Creates a copy of an edge of the original graph * * @param edge * an edge of the original graph * @param sameDirection * true if the arc must have the same direction as the * original edge */ NSArc(Edge edge, boolean sameDirection) { if (edge.getId().startsWith(PREFIX)) throw new IllegalArgumentException( "Edge ids must not start with " + PREFIX); id = (sameDirection ? "" : PREFIX + "REVERSE_") + edge.getId(); double v = edge.getNumber(capacityName); if (Double.isNaN(v) || v < 0) v = INFINITE_CAPACITY; capacity = (int) v; v = edge.getNumber(costName); if (Double.isNaN(v)) v = 1; cost = new BigMNumber((int) v); String sourceId = edge.getSourceNode().getId(); String targetId = edge.getTargetNode().getId(); source = nodes.get(sameDirection ? sourceId : targetId); target = nodes.get(sameDirection ? targetId : sourceId); }
public void edgeRemoved(String sourceId, long timeId, String edgeId) { Edge edge = g.getEdge(edgeId); for (String key : edge.getAttributeKeySet()) edgeAttributeRemoved(sourceId, timeId, edgeId, key); Event e; e = new EdgeRemoved(edgeId, edge.getSourceNode().getId(), edge .getTargetNode().getId(), edge.isDirected()); events.add(e); }
public void edgeRemoved(String sourceId, long timeId, String edgeId) { Edge edge = g.getEdge(edgeId); for (String key : edge.getAttributeKeySet()) edgeAttributeRemoved(sourceId, timeId, edgeId, key); Event e; e = new EdgeRemoved(edgeId, edge.getSourceNode().getId(), edge .getTargetNode().getId(), edge.isDirected()); events.add(e); }
private void outputEdge(Edge e) { String style = getEdgeStyle(e); String uiPoints = ""; points.setElement(e); if (points.check()) { for (int i = 0; i < points.getPointsCount(); i++) { double x, y; x = points.getX(i); y = points.getY(i); x = width * (x - xmin) / (xmax - xmin); y = height * (y - ymin) / (ymax - ymin); uiPoints = String .format(l, "%s-- (%.3f,%.3f) ", uiPoints, x, y); } } out.printf(l, "\t\\draw[%s] (%s) %s%s (%s);%n", style, formatId(e .getSourceNode().getId()), uiPoints, e.isDirected() ? "->" : "--", formatId(e.getTargetNode().getId())); }
private void outputEdge(Edge e) { String style = getEdgeStyle(e); String uiPoints = ""; points.setElement(e); if (points.check()) { for (int i = 0; i < points.getPointsCount(); i++) { double x, y; x = points.getX(i); y = points.getY(i); x = width * (x - xmin) / (xmax - xmin); y = height * (y - ymin) / (ymax - ymin); uiPoints = String .format(l, "%s-- (%.3f,%.3f) ", uiPoints, x, y); } } out.printf(l, "\t\\draw[%s] (%s) %s%s (%s);%n", style, formatId(e .getSourceNode().getId()), uiPoints, e.isDirected() ? "->" : "--", formatId(e.getTargetNode().getId())); }
protected void modifyCost(String edgeId, double cval) { Edge e = env.getEdge(edgeId); if (e.isDirected()) modifyCost(getState(e.getSourceNode()), getState(e.getTargetNode()), cval); else { modifyCost(getState(e.getNode0()), getState(e.getNode1()), cval); modifyCost(getState(e.getNode1()), getState(e.getNode0()), cval); } }
protected void modifyCost(String edgeId, double cval) { Edge e = env.getEdge(edgeId); if (e.isDirected()) modifyCost(getState(e.getSourceNode()), getState(e.getTargetNode()), cval); else { modifyCost(getState(e.getNode0()), getState(e.getNode1()), cval); modifyCost(getState(e.getNode1()), getState(e.getNode0()), cval); } }