On Mon, 20 Oct 2014 20:11:31 +0300 (EEST) Jori Mantysalo <jori.mantys...@uta.fi> wrote:
> When I hit this, I was making a code for posets, but this is actually more > general question. Shortly, do (di)graphs have some kind of order of > vertices? Sort of. The code seems to assume this in various places, and uses python's sorted liberally. It makes sense that the code should assume this, because list and matrices need an order. If the vertices happen to have a total ordering everything should be fine. If the vertices happen to have a total preorder, most things should be fine because python uses stable sort. Otherwise things get scary. Many functions accept a parameter called key that gets used for custom ordering of the output. IMHO it would be a very good idea to allow a default key-function to be passed to the constructor. That way the user can force their own (total) ordering if this is wanted. I think this would make the assumption much more acceptable. Such a parameter is especially useful if there is no total ordering on the vertices, or when comparisons throw exceptions. Shall I open a ticket for this? Here is an example of a comparison throwing an exception: sage: G = Graph({complex(3):[complex(4)]}) sage: G.vertices() --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-65-bde47caa7c87> in <module>() ----> 1 G.vertices() /home/erik/sage/local/lib/python2.7/site-packages/sage/graphs/generic_graph.pyc in vertices(self, key, boundary_first) 8986 """ 8987 if not boundary_first: -> 8988 return sorted(list(self.vertex_iterator()), key=key) 8989 8990 from sage.misc.superseded import deprecation TypeError: no ordering relation is defined for complex numbers > To start, will > > Graph({'b':['a']}).vertices() > > always print ['a', 'b'], not ['b', 'a']? Yes, but only because strings compare lexicographically by ascii value in python: https://docs.python.org/2/tutorial/datastructures.html#comparing-sequences-and-other-types > How about directed graphs? I think .vertices is the same method, so should be the same. > What > about adding or deleting vertex (or edge), can it change order of > remaining vertices? How about list of incoming or outgoing list? If there is a total (pre)order, everything should be fine. If there is not, my bet is as good as yours. > Is there even some kind of general rule about this kind of thing at Sage? If there is, I'd like to know. Regards, Erik Massop -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.