On Fri, May 14, 2010 at 12:13:10PM -0700, Bruce wrote:
> I think I see what I need to do. Create a dummy class C which is
> hashable and immutable.
> Have a dictionary which has objects of C and planar graphs.
> Every time I create a planar graph, see if it is isomorphic to one in
> the dictionary.
> If not add it to the dictionary. Is this sensible?

Given a Sage graph, you can ask for an isomorphic copy in "canonical
form" by using G.canonical_label().

So an alternative would be to systematically put your graphs into
canonical form whenever you construct / change them.

About immutability: it ought to be possible to create
immutable/hashable graphs in Sage. Alas this is not yet the case, and
this has annoyed us in many occasions. Please open a ticket (if there
is not one already).

And, ooooops, I just realized that I inadvertently let a hack of mine
slip into the graphviz #7004 patch, and Vincent did not catch it!
Promised, that was not intentional!

In any cases, with Sage 4.4.1, you can actually cheat around this, and
pretend that your graph is immutable:

    sage: G = DiGraph(4)
    sage: hash(G)
    ------------------------------------------------------------
    Traceback (most recent call last):
    ...
    TypeError: graphs are mutable, and thus not hashable

    sage: G._immutable = True
    sage: hash(G)
    -236023159

This is *dangerous*, so use with all due care. But maybe this can be
sufficient as a workaround for you until a proper mutability
management is implemented for graphs.

Cheers,
                                Nicolas
--
Nicolas M. ThiƩry "Isil" <nthi...@users.sf.net>
http://Nicolas.Thiery.name/

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to