Re: [jgrapht-developers] Adding multiple edges and loops
Brought to you by:
barak_naveh,
perfecthash
From: Barak N. <ba...@3p...> - 2004-09-23 04:31:14
|
> > for a similar reason, if the user tries to "forcibly" add multiple ed= ges > to > > graph that forbids multiple edges (this can be done by abusing the > > addEdge(Edge e) method) then an exception should be thrown -- the gra= ph > > needs to defend its consistency. if this is not currently the case, i= t > > should be fixed. >=20 > This is currently not the case. addEdge(e) behaves exactly like=20 > addEdge(e.getSource(), e.getTarget()). It throws exception on forbidden > loops and silently ignores forbidden multiple edges.=20 hmm, my goof then.. i think it should be corrected (http://sourceforge.net/tracker/?func=3Ddetail&atid=3D579687&aid=3D103311= 1&group_id=3D86459) > > > > However, if the user attempts to add an edge which is already existin= g > > using addEdge(v1,v2), then it is not a mistake. he or she wants to in= clude > > the specified edge in the edge set. if the edge already in the edge s= et, > > there is nothing to do. if it is not, it is included. in other words= , the > > call can satisfy the user wish, without violating any graph consisten= cy > > criteria and therefore there is no reason to throw an exception. > > > > is my reasoning making sense? >=20 > Partly. I think it is more reasonible to let addEdge(e) behave exactly=20 > like addEdge(v1, v2), because on graphs with multiple edges allowed > your argumentation would fail. What does the user want when calling > addEdge(v1,v2) when such an edge is already present. Add another=20 > one or just ensure that an edge is present? I think a user calling=20 > addEdge really wants to add an Edge and following your reasoning > both versions of addEdge should always throw an exception when the=20 > two vertices are already connected and multiedges are forbidden. On graphs with multiple edges allowed the argumentation indeed becomes we= aker, or at least question raising. As a user i would want addEdge(v1,v2) to al= ways add a new edge if multiple edges are allowed. If multiple edges are forbi= den, i would want it to add a new edge only if no edge exists between v1 and v2.= Such behavior is (almost:) consistent with the fact that the edge set is, well= , a Set. As such, it behaves differently when multiple edges are allowed --pa= rallel edges are equal in the non-multiple case, but aren't in the multiple case= . Not sure if it's the best solution, but i suppose it's better than a sile= nt ignoring. What do you think? Other ideas? John? barak |