(defclass* graph-container-edge (basic-edge)
((vertex-1 nil ir "`Vertex-1` is one of the two vertexes that an edge connects. In a directed-edge, `vertex-1` is also the `source-edge`.")
(defclass* graph-container-edge (basic-edge)
((vertex-1 nil ir "`Vertex-1` is one of the two vertexes that an edge connects. In a directed-edge, `vertex-1` is also the `source-edge`.")
(defmethod print-object ((object graph-container-edge) stream)
(print-unreadable-object (object stream :type t)
(format stream "<~A ~A ~A>" (vertex-1 object) (vertex-2 object)
(value object))))
(defmethod print-object ((object graph-container-edge) stream)
(print-unreadable-object (object stream :type t)
(format stream "<~A ~A ~A>" (vertex-1 object) (vertex-2 object)
(value object))))
(defclass* weighted-edge (weighted-edge-mixin graph-container-edge)
()
(:export-p t)
(:documentation "A weighted edge is both a weighted-edge-mixin and a graph-container-edge."))
(defclass* weighted-edge (weighted-edge-mixin graph-container-edge)
()
(:export-p t)
(:documentation "A weighted edge is both a weighted-edge-mixin and a graph-container-edge."))
:vertex-edges-container-class 'vector-container)
(:documentation "A graph container vertex keeps track of its edges in the the vertex-edges slot. The storage for this defaults to a vector-container but can be changed using the vertex-edges-container-class initarg."))
:vertex-edges-container-class 'vector-container)
(:documentation "A graph container vertex keeps track of its edges in the the vertex-edges slot. The storage for this defaults to a vector-container but can be changed using the vertex-edges-container-class initarg."))
(defmethod make-vertex-edges-container ((vertex graph-container-vertex)
container-class &rest args)
(apply #'make-container container-class args))
(defmethod make-vertex-edges-container ((vertex graph-container-vertex)
container-class &rest args)
(apply #'make-container container-class args))
(defmethod initialize-instance :after ((object graph-container-vertex) &key
vertex-edges-container-class)
(setf (slot-value object 'vertex-edges)
(make-vertex-edges-container object vertex-edges-container-class)))
(defmethod initialize-instance :after ((object graph-container-vertex) &key
vertex-edges-container-class)
(setf (slot-value object 'vertex-edges)
(make-vertex-edges-container object vertex-edges-container-class)))
(defmethod make-vertex-container ((graph graph-container) initial-size)
(make-container 'simple-associative-container
:initial-size initial-size
:test (vertex-test graph)))
(defmethod make-vertex-container ((graph graph-container) initial-size)
(make-container 'simple-associative-container
:initial-size initial-size
:test (vertex-test graph)))
(defmethod make-edge-container ((graph graph-container) initial-size)
(make-container 'vector-container :initial-size initial-size
:fill-pointer 0))
(defmethod make-edge-container ((graph graph-container) initial-size)
(make-container 'vector-container :initial-size initial-size
:fill-pointer 0))
(defmethod initialize-instance :after ((object graph-container-directed-edge)
&key source-vertex target-vertex)
(defmethod initialize-instance :after ((object graph-container-directed-edge)
&key source-vertex target-vertex)
(defmethod add-edge ((graph graph-container) (edge graph-container-edge)
&key force-new?)
(declare (ignore force-new?))
(defmethod add-edge ((graph graph-container) (edge graph-container-edge)
&key force-new?)
(declare (ignore force-new?))
(defmethod add-edge-to-vertex :around ((edge graph-container-edge)
(vertex graph-container-vertex))
(insert-item (vertex-edges vertex) edge))
(defmethod add-edge-to-vertex :around ((edge graph-container-edge)
(vertex graph-container-vertex))
(insert-item (vertex-edges vertex) edge))
(defmethod make-node-for-container ((graph graph-container) (node t) &key)
(make-vertex-for-graph graph :element node))
(defmethod make-node-for-container ((graph graph-container) (node t) &key)
(make-vertex-for-graph graph :element node))
(v2 (find-vertex graph value-2 error-if-not-found?)))
(or (and v1 v2 (find-edge-between-vertexes-if graph v1 v2 fn))
(when error-if-not-found?
(error 'graph-edge-not-found-error :vertex-1 v1 :vertex-2 v2)))))
(v2 (find-vertex graph value-2 error-if-not-found?)))
(or (and v1 v2 (find-edge-between-vertexes-if graph v1 v2 fn))
(when error-if-not-found?
(error 'graph-edge-not-found-error :vertex-1 v1 :vertex-2 v2)))))
(defmethod find-edge ((graph graph-container) (edge graph-container-edge)
&optional error-if-not-found?)
(defmethod find-edge ((graph graph-container) (edge graph-container-edge)
&optional error-if-not-found?)
(defmethod delete-edge ((graph graph-container) (edge graph-container-edge))
(let ((vertex-1 (vertex-1 edge))
(defmethod delete-edge ((graph graph-container) (edge graph-container-edge))
(let ((vertex-1 (vertex-1 edge))
(defmethod iterate-edges ((vertex graph-container-vertex) fn)
(iterate-elements (vertex-edges vertex) fn))
(defmethod iterate-edges ((vertex graph-container-vertex) fn)
(iterate-elements (vertex-edges vertex) fn))
(defmethod iterate-source-edges ((vertex graph-container-vertex) fn)
(iterate-elements (vertex-edges vertex)
(lambda (edge)
(when (or (undirected-edge-p edge)
(defmethod iterate-source-edges ((vertex graph-container-vertex) fn)
(iterate-elements (vertex-edges vertex)
(lambda (edge)
(when (or (undirected-edge-p edge)
(defmethod iterate-target-edges ((vertex graph-container-vertex) fn)
(iterate-elements (vertex-edges vertex)
(lambda (edge)
(when (or (undirected-edge-p edge)
(defmethod iterate-target-edges ((vertex graph-container-vertex) fn)
(iterate-elements (vertex-edges vertex)
(lambda (edge)
(when (or (undirected-edge-p edge)
(defmethod iterate-neighbors ((vertex graph-container-vertex) fn)
(iterate-edges vertex
(lambda (edge)
(funcall fn (other-vertex edge vertex)))))
(defmethod iterate-neighbors ((vertex graph-container-vertex) fn)
(iterate-edges vertex
(lambda (edge)
(funcall fn (other-vertex edge vertex)))))
(defmethod vertices-share-edge-p ((vertex-1 graph-container-vertex)
(vertex-2 graph-container-vertex))
(defmethod vertices-share-edge-p ((vertex-1 graph-container-vertex)
(vertex-2 graph-container-vertex))