[cl-graph-devel] how to subclass vertices, too?
Gary King
gwking at metabang.com
Fri Feb 10 16:15:40 UTC 2006
> Would you believe that:
>
> (1) I needed to make "my-happy-vertex" subclass
> "graph-container-vertex" in order for things to work?
Yes, and I should have mentioned it. Someday I hope to use dynamic
class creation to ensure that vertexes and so forth extend the
correct base class but that's up to the user now. (I just updated the
documentation).
> (2) When so subclassing the vertex class, I have to set the "element"
> slot to be something unique? Failure to do so seemed to confuse the
> duplicate-prevention machinery. In fact, I didn't set it at all so it
> was nil (obviously I didn't see this coming), and then things got
> weird as only one of my nil "elemented" vertices was added...
I'm not so sure about this. Maybe this code will make things clearer
(or not!)
> (in-package cl-graph)
>
> (defclass* my-happy-vertex (graph-container-vertex)
> ())
>
> (let ((g (make-container 'graph-container :vertex-class 'my-happy-
> vertex)))
> (loop for (a b) in '((a b) (c d) (a c) (d e) (f g) (f h) (g i)) do
> (add-edge-between-vertexes g a b))
>
> (print "Vertexes")
> ;; could also use the more generic iterate-nodes
> (iterate-vertexes g (lambda (x) (print x)))
>
> (print "Elements")
> (iterate-elements g (lambda (x) (print x)))
>
> g)
For me, this prints:
> "Vertexes"
> #<A>
> #<I>
> #<G>
> #<B>
> #<E>
> #<H>
> #<C>
> #<D>
> #<F>
> "Elements"
> A
> I
> G
> B
> E
> H
> C
> D
> F
> #<GRAPH-CONTAINER 9 #xF4AF10E>
The point is that when I call add-edge-between-vertexes <graph>
<value> <value>, then the graph code takes care of wrapping the
values into vertexes such that the element of the vertex is the
value. Does this correspond to what you're doing?
Thanks,
--
Gary Warren King
metabang.com
http://www.metabang.com/
More information about the cl-graph-devel
mailing list