Refine search
public V getOpposite(V vertex, E edge) { Pair<V> incident = this.getEndpoints(edge); V first = incident.getFirst(); V second = incident.getSecond(); if (vertex.equals(first)) return second; else if (vertex.equals(second)) return first; else throw new IllegalArgumentException(vertex + " is not incident to " + edge + " in this graph"); }
public boolean removeEdge(E edge) { if (!containsEdge(edge)) return false; Pair<V> endpoints = this.getEndpoints(edge); V source = endpoints.getFirst(); V dest = endpoints.getSecond(); // remove vertices from each others' adjacency maps vertices.get(source).getSecond().remove(dest); vertices.get(dest).getFirst().remove(source); edges.remove(edge); return true; } }
public boolean removeEdge(E edge) { if (!containsEdge(edge)) return false; Pair<V> endpoints = getEndpoints(edge); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); // remove edge from incident vertices' adjacency sets vertices.get(v1).remove(edge); vertices.get(v2).remove(edge); edges.remove(edge); return true; }
/** * Resets the indices for this edge and its parallel edges. * Should be invoked when an edge parallel to <code>e</code> * has been added or removed in this graph. * @param graph the graph with respect to which the index is calculated * @param e the edge whose indices are to be reset for {@code graph} */ public void reset(Graph<V,E> graph, E e) { Pair<V> endpoints = graph.getEndpoints(e); getIndex(graph, e, endpoints.getFirst()); getIndex(graph, e, endpoints.getFirst(), endpoints.getSecond()); }
/** * Resets the indices for this edge group and its parallel groups. Should be * invoked when an edge parallel to the group has been added or removed. * @param group */ public void reset(Graph graph, Object group) { Pair endpoints = graph.getEndpoints(group); getIndex(graph, (MessageGroup)group, (AgentGroup)endpoints.getFirst()); getIndex(graph, (MessageGroup)group, (AgentGroup)endpoints.getFirst(), (AgentGroup)endpoints.getSecond()); }