[elephant-devel] associations between instances of the same class

Christoph Ludwig ludwig at fh-worms.de
Sun Jul 20 18:35:43 UTC 2008


Hi,

we came across a (to us) surprising behavior of the association code in
elephant-unstable: If we generate associations between instances of the same
class, then elephant forces these associations to be symmetric. That means we
cannot use association slots to implement directed graphs.

For example, the attached program is supposed to set up a "diamond"; We'd
therefore expect the following output:

  Node A:
    successors:   (B C)
    predecessors: ()
  Node B:
    successors:   (D)
    predecessors: (A)
  Node C:
    successors:   (D)
    predecessors: (A)
  Node D:
    successors:   ()
    predecessors: (B C)

However, elephant makes both the successor and the predecessor slot hold
always the same references:

  Node A:
    successors:   (B C)
    predecessors: (B C)
  Node B:
    successors:   (A D)
    predecessors: (A D)
  Node C:
    successors:   (A D)
    predecessors: (A D)
  Node D:
    successors:   (B C)
    predecessors: (B C)

Is this by design or is this a bug? Or did we simply use the association API
incorrectly?

Regards

Christoph

-- 
FH Worms - University of Applied Sciences
Fachbereich Informatik / Telekommunikation
Erenburgerstr. 19, 67549 Worms, Germany
-------------- next part --------------
(elephant:open-store '(:BDB "/tmp/db"))

(elephant:defpclass DAGNode ()
  ((label :accessor label :initarg :label :type string :index t)
   (successors :accessor successors :associate (DAGNode predecessors) :many-to-many t)
   (predecessors :accessor predecessors :associate (DAGNode successors) :many-to-many t)))


(defvar *a* (make-instance 'DAGNode :label "A"))
(defvar *b* (make-instance 'DAGNode :label "B"))
(defvar *c* (make-instance 'DAGNode :label "C"))
(defvar *d* (make-instance 'DAGNode :label "D"))

(elephant:add-association *a* 'successors *b*)
(elephant:add-association *a* 'successors *c*)
(elephant:add-association *b* 'successors *d*)
(elephant:add-association *c* 'successors *d*)

(dolist (node (list *a* *b* *c* *d*))
  (format t "Node ~a:~%" (label node))
  (format t "  successors:   ~:a~%" (mapcar #'(lambda (x) (label x)) (successors node)))
  (format t "  predecessors: ~:a~%" (mapcar #'(lambda (x) (label x)) (predecessors node))))

(elephant:close-store)


More information about the elephant-devel mailing list