#8284: IntervalGraph generator and a bug in is_chordal
-----------------------------+----------------------------------------------
   Reporter:  ncohen         |       Owner:  ncohen         
       Type:  defect         |      Status:  positive_review
   Priority:  critical       |   Milestone:  sage-4.4.4     
  Component:  graph theory   |    Keywords:                 
     Author:  Nathann Cohen  |    Upstream:  N/A            
   Reviewer:  Robert Miller  |      Merged:                 
Work_issues:                 |  
-----------------------------+----------------------------------------------

Comment(by jason):

 You might be able to get away with just creating a class that doesn't have
 a defined hash function, so that the default (the memory address) is used.
 The problem with using a tuple is that the two hash values below are the
 same:

 {{{
 sage: a=(1,2)
 sage: b=(1,2)
 sage: hash(a)
 3713081631934410656
 sage: hash(b)
 3713081631934410656
 }}}

 We can use a feature of user-defined classes, though:

 "User-defined classes have __cmp__()  and __hash__()  methods by default;
 with them, all objects compare unequal (except with themselves) and
 x.__hash__()  returns id(x)."

 This means we can get vertices which contain objects which normally would
 be considered equal in a dictionary to be stored as two different things
 in a dictionary:

 {{{
 sage: class Vertex(object):
 ....:     def __init__(self, value):
 ....:         self.__value=value
 ....:
 sage: a=Vertex((1,2))
 sage: b=Vertex((1,2))
 sage: a is b
 False
 sage: hash(a)
 4528980944
 sage: hash(b)
 4528980816
 sage: Graph({a: [b]})
 Graph on 2 vertices
 }}}

 Does that address the problem?  It introduces a problem, in that now you
 can't do:

 {{{g[Vertex((1,2))]}}}

 to get the neighbors, since, of course, the element you are creating is
 not the same as any of the vertices of the graph.  Also, you have to use
 v.__value to get the interval (or better, make some accessors for the
 attribute (and if you want, try to disallow changing it).

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8284#comment:14>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to