From c78963a693aac062da29f25641ace0430b6c1591 Mon Sep 17 00:00:00 2001 From: Gary King Date: Thu, 9 Feb 2006 14:40:12 -0500 Subject: [PATCH] Notes; also exported several dot-graph classes darcs-hash:20060209194012-3cc5d-206a420d9cdfcd91bc5626f22c2c83ce355f24e9.gz --- dev/graphviz-support.lisp | 28 ++++++++++++-------- dev/notes.text | 62 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 10 deletions(-) diff --git a/dev/graphviz-support.lisp b/dev/graphviz-support.lisp index 65a4f57..a47f66c 100644 --- a/dev/graphviz-support.lisp +++ b/dev/graphviz-support.lisp @@ -315,22 +315,30 @@ B--D [] (:layer text))) (defclass* dot-attributes-mixin () - ((dot-attributes nil ia))) + ((dot-attributes nil ia)) + (:export-p t)) -(defclass* dot-graph-mixin (dot-attributes-mixin) ()) -(defclass* dot-vertex-mixin (dot-attributes-mixin) ()) -(defclass* dot-edge-mixin (dot-attributes-mixin) ()) +(defclass* dot-graph-mixin (dot-attributes-mixin) () + (:export-p t)) +(defclass* dot-vertex-mixin (dot-attributes-mixin) () + (:export-p t)) +(defclass* dot-edge-mixin (dot-attributes-mixin) () + (:export-p t)) (defclass* dot-graph (graph-container dot-graph-mixin) () (:default-initargs :vertex-class 'dot-vertex - :directed-edge-class 'dot-edge - :undirected-edge-class 'dot-edge)) - -(defclass* dot-vertex (graph-container-vertex dot-vertex-mixin) ()) -(defclass* dot-edge (graph-container-edge dot-edge-mixin) ()) -(defclass* dot-directed-edge (directed-edge-mixin dot-edge) ()) + :directed-edge-class 'dot-directed-edge + :undirected-edge-class 'dot-edge) + (:export-p t)) + +(defclass* dot-vertex (graph-container-vertex dot-vertex-mixin) () + (:export-p t)) +(defclass* dot-edge (graph-container-edge dot-edge-mixin) () + (:export-p t)) +(defclass* dot-directed-edge (directed-edge-mixin dot-edge) () + (:export-p t)) (defmethod graph->dot-properties ((graph dot-graph) (stream t)) (loop for (name value) on (dot-attributes graph) by #'cddr diff --git a/dev/notes.text b/dev/notes.text index 2588de0..997c35a 100644 --- a/dev/notes.text +++ b/dev/notes.text @@ -1,3 +1,65 @@ +#| +(in-package cl-graph) + +(let ((g (make-instance 'graph-container + :default-edge-type :directed))) + (add-edge-between-vertexes g :a :b) + (add-edge-between-vertexes g :a :c) + (add-edge-between-vertexes g :b :d) + (graph->dot g t)) +-> (prints) +digraph G { +graph []; + +3 [] +1 [] +0 [] +2 [] +1->3 [] +0->1 [] +0->2 [] +} +# + +(defclass* weighted-directed-edge (directed-edge-mixin weighted-edge) + ()) + +(let ((g (make-instance 'graph-container + :default-edge-class 'weighted-directed-edge))) + (add-edge-between-vertexes g :a :b) + (add-edge-between-vertexes g :a :c) + (add-edge-between-vertexes g :b :d :weight 2.5) + (graph->dot g t + :edge-formatter + (lambda (e s) (format s "weight=~D" (weight e))))) +-> (prints) +graph G { +graph []; + +3 [] +1 [] +0 [] +2 [] +0--1 [dir=forward, ] +1--3 [] +0--2 [] +} +-> (returns) +# + + +(defun weighted-sum-of-connected-vertexes (vertex) + (let ((sum 0)) + (iterate-target-edges + vertex + (lambda (e) + (incf sum (* (weight e) (element (other-vertex e vertex)))))) + sum)) + +graph-roots +|# + + (in-package metabang.graph) (in-package cl-graph) -- 1.7.10.4