public E addEdge(N n1, N n2) { if (defaultFactory == null) throw new RuntimeException("No default EdgeFactory set!"); return addEdge(n1, n2, defaultFactory); }
public void removeEdge(int i, int j) { removeEdge(getVertex(i), getVertex(j)); }
public int edgeCount(EdgeType type) { int c = 0; for (N n : vertices()) { c += n.degree(type); } return c / 2; }
public boolean containsEdge(N n1, N n2) { if (defaultFactory == null) throw new RuntimeException("No default EdgeFactory set!"); EdgeType t = defaultFactory.getEdgeType(); return containsEdge(n1, n2, t); }
public void removeEdge(N n1, N n2) { if (defaultFactory == null) throw new RuntimeException("No default EdgeFactory set!"); EdgeType t = defaultFactory.getEdgeType(); removeEdge(n1, n2, t); }
public void removeVertex(N n) { removeVertex(n.getIndex()); }
public void removeEdge(E e) { if ( getVertex(e.getSource().getIndex()) == e.getSource() && getVertex(e.getTarget().getIndex()) == e.getTarget()) { e.getSource().removeEdge(e); e.getTarget().removeEdge(e); } else { throw new RuntimeException("Edge connects Vertices that are not contained in this graph!"); } }
public int edgeCount() { int c = 0; for (N n : vertices()) { c += n.degree(); } return c / 2; }
public E addEdge(N n1, N n2, EdgeType type) { EdgeFactory<? extends E, N> f = edgeFactories.get(type); if (f == null) throw new RuntimeException("No EdgeFactory for type " + type); return addEdge(n1, n2, f); }
/** * Returns a collection of {@link Edge}s used in this graph. This collection * is not related to the graph and can be changed without effecting the graphs structure. * Also note that the collection is not cached and created each time you call this methods. * It need O(|vertices|) to build the edge set. * * @return collection of edges associated with this graph */ public Collection<E> getAllEdges() { /*TreeSet<E> allEdges = new TreeSet<E>(); for (N vertex : vertices()) { for (E edge : vertex.edges()) { allEdges.add(edge); } } return allEdges;*/ //TreeSet<E> allEdges = new TreeSet<E>(); List<E> allEdges = new ArrayList<E>(); for (N vertex : vertices()) { for (E edge : vertex.edges()) { //System.out.println("im simplegraph, adde egde : " + edge.getSource() + " --- " + edge.getWeight() + " --- " + edge.getTarget()); // if (!allEdges.contains(edge)){ allEdges.add(edge); //} } } //System.out.println("vor retrun in get all edges , size = " + allEdges.size()); return allEdges; }
protected E addEdge(N n1, N n2, EdgeFactory<? extends E, N> f) { E e = f.createEdge(n1, n2); return addEdge(e); }