;;; -*- Mode: Lisp; package: cl-user; Syntax: Common-lisp; Base: 10 -*-
(in-package :common-lisp-user)
-(defpackage #:asdf-cl-graph-test (:use #:cl #:asdf))
-(in-package #:asdf-cl-graph-test)
+(defpackage #:cl-graph-test-system (:use #:cl #:asdf))
+(in-package #:cl-graph-test-system)
(defsystem cl-graph-test
:version "0.1"
:maintainer "Gary Warren King <gwking@metabang.com>"
:licence "MIT Style License"
:description "Tests for CL-Graph"
-
:components ((:module
"unit-tests"
:components
"dev"
:components
((:static-file "notes.text"))))
- :depends-on (cl-graph lift))
+ :depends-on (:cl-graph :lift))
;;; -*- Mode: Lisp; package: cl-user; Syntax: Common-lisp; Base: 10 -*-
(in-package #:common-lisp-user)
-(defpackage #:asdf-cl-graph (:use #:cl #:asdf))
-(in-package #:asdf-cl-graph)
+(defpackage #:cl-graph-system (:use #:cl #:asdf))
+(in-package #:cl-graph-system)
(unless (find-system 'asdf-system-connections nil)
- (when (find-package 'asdf-install)
- (print "Trying to install asdf-system-connections with ASDF-Install...")
- (funcall (intern (symbol-name :install) :asdf-install) 'asdf-system-connections)))
-;; give up with a useful (?) error message
-(unless (find-system 'asdf-system-connections nil)
- (error "The CL-Graph system requires ASDF-SYSTEM-CONNECTIONS. See
+ (warn "The CL-Graph system would enjoy having asdf-system-connections
+around. See
http://www.cliki.net/asdf-system-connections for details and download
instructions."))
-
-(asdf:operate 'asdf:load-op 'asdf-system-connections)
+(when (find-system 'asdf-system-connections nil)
+ (operate 'load-op 'asdf-system-connections))
(defsystem cl-graph
- :version "0.8.3"
+ :version "0.8.4"
:author "Gary Warren King <gwking@metabang.com>"
:maintainer "Gary Warren King <gwking@metabang.com>"
:licence "MIT Style License"
:description "Graph manipulation utilities for Common Lisp"
- :components ((:module
+ :components ((:static-file "COPYING")
+ (:module
"dev"
:components
((:file "package")
:components
((:module "source"
:components ((:static-file "index.lml"))))))
- :in-order-to ((test-op (load-op cl-graph-test)))
+ :in-order-to ((test-op (load-op :cl-graph-test)))
:perform (test-op :after (op c)
- (describe
- (funcall (intern (symbol-name '#:run-tests) :lift)
- :suite '#:cl-graph-test)))
+ (funcall
+ (intern (symbol-name '#:run-tests) :lift)
+ :config :generic))
:depends-on (:metatilities
:cl-containers
:metabang-bind
(collect-elements
(make-iterator (connected-components graph) :unique t :transform #'parent))))
-;;; ---------------------------------------------------------------------------
-
(defmethod find-connected-components ((graph basic-graph))
(collect-elements
(make-iterator (connected-components graph) :unique t :transform #'parent)
:transform
(lambda (component)
(subgraph-containing graph (element component)
- most-positive-fixnum))))
+ :depth most-positive-fixnum))))
#+Alternate
(defmethod find-connected-components ((graph basic-graph))
(when error-if-not-found?
(error 'graph-vertex-not-found-error :vertex value :graph graph))))
-;;; ---------------------------------------------------------------------------
+(defmethod find-vertex ((graph basic-graph) (vertex basic-vertex)
+ &optional (error-if-not-found? t))
+ (cond ((eq graph (graph vertex))
+ vertex)
+ (t
+ (when error-if-not-found?
+ (error 'graph-vertex-not-found-error
+ :vertex vertex :graph graph)))))
(defmethod find-vertex ((edge basic-edge) (value t)
&optional (error-if-not-found? t))
#:has-children-p
#:has-parent-p
#:number-of-neighbors
-
+ #:graph-vertexes
+ #:replace-vertex
+
#:edge-count ; graph
#:vertex-count ; graph
#:project-bipartite-graph
#:make-vertex-edges-container
-
+ #:make-vertex-for-graph
+
#:vertex-degree-counts
#:vertex-degree
#:average-vertex-degree
#:graph-mixing-matrix
#:graph-edge-mixture-matrix
#:assortativity-coefficient
- #:vertex-degree-summary)
+ #:vertex-degree-summary
+ #:connected-components
+ #:average-local-clustering-coefficient
+ #:vertex-triangle-count
+ #:graph-edges
+ #:graph-vertexes)
(:export
#:print-dot-key-value
(ensure-same (size g) 6 :test '=)))
+#|
;;; ---------------------------------------------------------------------------
;;; copying
;;; ---------------------------------------------------------------------------
(ensure (not
(find-edge-between-vertexes g2 (find-vertex g1 'a) (find-vertex g1 'b))))))
-;;; ---------------------------------------------------------------------------
-
+|#
(deftestsuite cl-graph-test () ())
-(deftestsuite test-test-vertex () ())
+(deftestsuite test-test-vertex (cl-graph-test) ())
(addtest (test-test-vertex)
test-1
(delete-edge-between-vertexes graph-directed 'a 'b)
(ensure-same (size (graph-edges graph-directed)) 3))
-;;; ---------------------------------------------------------------------------
+#|
(deftestsuite cl-graph-test-traversal (cl-graph-test)
((g (make-container 'graph-container)))
(h j)) do
(add-edge-between-vertexes g src dst :edge-type :directed)))
-;;; ---------------------------------------------------------------------------
-
#|
a - b - e
(ensure-same (reverse result)
'(e f b c g i j h d a) :test #'equal)))
-;;; ---------------------------------------------------------------------------
-
(addtest (cl-graph-test-traversal)
(let ((result nil))
(traverse-elements
(ensure-same (reverse result)
'(a b c d e f g h i j) :test #'equal)))
+|#
;;; ---------------------------------------------------------------------------
;;; test-replace-vertex
--- /dev/null
+(in-package cl-graph)
+
+(defun foo ()
+ (let ((graph (cl-graph:make-graph 'cl-graph:graph-container
+ :vertex-test #'equal)))
+ (cl-graph:add-vertex graph "a")
+ (cl-graph:add-vertex graph "b")
+ (cl-graph:add-vertex graph "c")
+ (cl-graph:add-vertex graph "d")
+ (cl-graph:add-vertex graph "e")
+ (cl-graph:add-edge-between-vertexes graph "a" "b" :edge-type :directed)
+ (cl-graph:add-edge-between-vertexes graph "b" "c" :edge-type :directed)
+ (cl-graph:add-edge-between-vertexes graph "c" "a" :edge-type :directed)
+ (cl-graph:add-edge-between-vertexes graph "d" "e" :edge-type :directed)
+ graph))
+
+(loop for component in
+ (cl-graph:find-connected-components (foo))
+ for index from 1 do
+ (format t "~&Component ~D (~d node~:p and ~d edge~:p)"
+ index (vertex-count component) (edge-count component))
+ (iterate-edges component (lambda (edge)
+ (format t "~& ~a to ~a"
+ (source-vertex edge)
+ (target-vertex edge))))
+ (format t "~%"))
+
+
+(defun mk-graph ()
+ (let ((graph (cl-graph:make-graph 'cl-graph:graph-container
+ :vertex-test #'equal)))
+ (cl-graph:add-vertex graph "a")
+ (cl-graph:add-vertex graph "b")
+ (cl-graph:add-vertex graph "c")
+ (cl-graph:add-vertex graph "d")
+ (cl-graph:add-vertex graph "e")
+ (cl-graph:add-edge-between-vertexes graph "a" "b" :edge-type :directed)
+ (cl-graph:add-edge-between-vertexes graph "b" "c" :edge-type :directed)
+ (cl-graph:add-edge-between-vertexes graph "c" "a" :edge-type :directed)
+ (cl-graph:add-edge-between-vertexes graph "d" "e" :edge-type :directed)
+ graph))
+
+(mk-graph)
+
+(setf *g* (mk-graph))
+
+(mapcar (lambda (v)
+ (list v (cl-graph:in-cycle-p *g* v)))
+ (cl-graph:vertexes *g*))
+
+(car (cl-graph:vertexes *g*))