public boolean isDirected() { return wrappedElement.isDirected(); }
public boolean isDirected() { return wrappedElement.isDirected(); }
/** * 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 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); }
/** * Returns the flow on an edge. * * If {@code sameDirection} is true, returns the flow from the source to the * target of the edge, otherwise returns the flow from the target to the * source of the edge. Note that for directed edges the flow can only pass * from the source node to the target node. For undirected edges there may * be independent flows in both directions. * * @param edge * An edge * @param sameDirection * If true, returns the flow from the source to the target. * @return The flow on the edge. */ public int getFlow(Edge edge, boolean sameDirection) { if (edge.isDirected()) return sameDirection ? arcs.get(edge.getId()).flow : 0; else return arcs.get((sameDirection ? "" : PREFIX + "REVERSE_") + edge.getId()).flow; }
/** * Returns the status of an edge in the current solution. * * An edge can be basic, non-basic at zero or non-basic at upper bound. Note * that undirected edges are interpreted as two directed arcs. If * {@code sameDirection} is true, the method returns the status of the arc * from the source to the target of the edge, otherwise it returns the * status of the arc from the target to the source. If the edge is directed * and {@code sameDirection} is false, returns {@code null}. * * @param edge * An edge * @param sameDirection * If true, returns the status of the arc from the source to the * target. * @return The status of the edge */ public ArcStatus getStatus(Edge edge, boolean sameDirection) { if (edge.isDirected()) return sameDirection ? arcs.get(edge.getId()).status : null; else return arcs.get((sameDirection ? "" : PREFIX + "REVERSE_") + edge.getId()).status; }
/** * Returns the flow on an edge. * * If {@code sameDirection} is true, returns the flow from the source to the * target of the edge, otherwise returns the flow from the target to the * source of the edge. Note that for directed edges the flow can only pass * from the source node to the target node. For undirected edges there may * be independent flows in both directions. * * @param edge * An edge * @param sameDirection * If true, returns the flow from the source to the target. * @return The flow on the edge. */ public int getFlow(Edge edge, boolean sameDirection) { if (edge.isDirected()) return sameDirection ? arcs.get(edge.getId()).flow : 0; else return arcs.get((sameDirection ? "" : PREFIX + "REVERSE_") + edge.getId()).flow; }
/** * Creates copies of all graph arcs and edges. Instantiates and fills * {@link #nodes} and {@link #arcs}. */ protected void cloneGraph() { nodes = new HashMap<String, NSNode>(4 * graph.getNodeCount() / 3 + 2); for (Node node : graph) { NSNode copy = new NSNode(node); nodes.put(copy.id, copy); } int arcCount = graph.getEdgeCount(); for (Edge edge : graph.getEachEdge()) if (!edge.isDirected()) arcCount++; arcs = new HashMap<String, NSArc>(4 * arcCount / 3 + 1); for (Edge edge : graph.getEachEdge()) { NSArc copy = new NSArc(edge, true); arcs.put(copy.id, copy); if (!edge.isDirected()) { copy = new NSArc(edge, false); arcs.put(copy.id, copy); } } }
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); }
@Override protected void exportGraph(Graph graph) { String graphId = graph.getId(); long timeId = 0; for (String key : graph.getAttributeKeySet()) graphAttributeAdded(graphId, timeId++, key, graph.getAttribute(key)); for (Node node : graph) { String nodeId = node.getId(); out.printf("\t\"%s\" %s;%n", nodeId, outputAttributes(node)); } for (Edge edge : graph.getEachEdge()) { String fromNodeId = edge.getNode0().getId(); String toNodeId = edge.getNode1().getId(); String attr = outputAttributes(edge); if (digraph) { out.printf("\t\"%s\" -> \"%s\"", fromNodeId, toNodeId); if (!edge.isDirected()) out.printf(" -> \"%s\"", fromNodeId); } else out.printf("\t\"%s\" -- \"%s\"", fromNodeId, toNodeId); out.printf(" %s;%n", attr); } }
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); }
@Override protected void exportGraph(Graph graph) { String graphId = graph.getId(); long timeId = 0; for (String key : graph.getAttributeKeySet()) graphAttributeAdded(graphId, timeId++, key, graph.getAttribute(key)); for (Node node : graph) { String nodeId = node.getId(); out.printf("\t\"%s\" %s;%n", nodeId, outputAttributes(node)); } for (Edge edge : graph.getEachEdge()) { String fromNodeId = edge.getNode0().getId(); String toNodeId = edge.getNode1().getId(); String attr = outputAttributes(edge); if (digraph) { out.printf("\t\"%s\" -> \"%s\"", fromNodeId, toNodeId); if (!edge.isDirected()) out.printf(" -> \"%s\"", fromNodeId); } else out.printf("\t\"%s\" -- \"%s\"", fromNodeId, toNodeId); out.printf(" %s;%n", attr); } }
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); } }
public void replay(String sourceId) { for (String key : getAttributeKeySet()) sendGraphAttributeAdded(sourceId, key, getAttribute(key)); for (int i = 0; i < getNodeCount(); i++) { Node node = getNode(i); String nodeId = node.getId(); sendNodeAdded(sourceId, nodeId); if (node.getAttributeCount() > 0) for (String key : node.getAttributeKeySet()) sendNodeAttributeAdded(sourceId, nodeId, key, node.getAttribute(key)); } for (int i = 0; i < getEdgeCount(); i++) { Edge edge = getEdge(i); String edgeId = edge.getId(); sendEdgeAdded(sourceId, edgeId, edge.getNode0().getId(), edge .getNode1().getId(), edge.isDirected()); if (edge.getAttributeCount() > 0) for (String key : edge.getAttributeKeySet()) sendEdgeAttributeAdded(sourceId, edgeId, key, edge.getAttribute(key)); } } }
public void replay(String sourceId) { for (String key : getAttributeKeySet()) sendGraphAttributeAdded(sourceId, key, getAttribute(key)); for (int i = 0; i < getNodeCount(); i++) { Node node = getNode(i); String nodeId = node.getId(); sendNodeAdded(sourceId, nodeId); if (node.getAttributeCount() > 0) for (String key : node.getAttributeKeySet()) sendNodeAttributeAdded(sourceId, nodeId, key, node.getAttribute(key)); } for (int i = 0; i < getEdgeCount(); i++) { Edge edge = getEdge(i); String edgeId = edge.getId(); sendEdgeAdded(sourceId, edgeId, edge.getNode0().getId(), edge .getNode1().getId(), edge.isDirected()); if (edge.getAttributeCount() > 0) for (String key : edge.getAttributeKeySet()) sendEdgeAttributeAdded(sourceId, edgeId, key, edge.getAttribute(key)); } } }