aboutsummaryrefslogtreecommitdiff
path: root/src/weighted-quick-union.lisp
diff options
context:
space:
mode:
authorLoic GUEGAN <loic.guegan@yahoo.fr>2019-01-31 15:31:37 +0100
committerLoic GUEGAN <loic.guegan@yahoo.fr>2019-01-31 15:31:37 +0100
commitd0f6e2ff9cdf4c35e99b54fa765aca7f46ed6a24 (patch)
tree7e48a591715e18f3a74324030cb3963c4421cc49 /src/weighted-quick-union.lisp
parent0038d9bd0318c1025b8edd005f3aaa609a308a57 (diff)
Clean project
Diffstat (limited to 'src/weighted-quick-union.lisp')
-rw-r--r--src/weighted-quick-union.lisp55
1 files changed, 0 insertions, 55 deletions
diff --git a/src/weighted-quick-union.lisp b/src/weighted-quick-union.lisp
deleted file mode 100644
index 679de80..0000000
--- a/src/weighted-quick-union.lisp
+++ /dev/null
@@ -1,55 +0,0 @@
-;;;; Weighted Quick Union Algorithm
-;;;; This algorithm solve dynamic connectivity
-;;;; problem by providing a way to find if there
-;;;; is a path between two nodes in a dynamic graph.
-;;;; It is an improved version of the Quick Union algorithm
-;;;; by improving the way that the union-tree is constructed
-;;;; The algorithm try to reduce the deepness of the tree in
-;;;; order to optimize the find-root function
-
-;;; Base functions
-
-(defun create-network (n)
- "Build a quick-find network using a multi-dimensional dynamic vector:\n
-1st dimension = the network\n 2nd dimension = each subtree node quantities"
- (let ((network (make-array `(2 ,n) :initial-element 1)))
- (dotimes (id n)
- (setf (aref network 0 id) id))
- network))
-
-(defun find-root (network node)
- "Find the root of a sub-tree in the network."
- (do ((id node value)
- (value (aref network 0 node) (aref network 0 value)))
- ((= id value) id)))
-
-(defun union_ (network n1 n2)
- "Connect to sub-tree together. union represent the union operation on the Quick Union algorithm"
- (let ((new-network (copy-tree network))) ; Duplicate network
- (let* ((n1-root (find-root new-network n1))
- (n2-root (find-root new-network n2))
- (n1-size (aref new-network 1 n1-root))
- (n2-size (aref new-network 1 n2-root)))
- (if (>= n1-size n2-size) ; Check which subtree is LARGER (not deeper)
- (progn (setf (aref new-network 0 n2-root) (aref new-network 0 n1-root)) ; Modify the second node
- (setf (aref new-network 1 n1-root) ; Update tree larger
- (+ (aref new-network 1 n1-root) (aref new-network 1 n2-root))))
- (progn (setf (aref new-network 0 n1-root) (aref new-network 0 n2-root)) ; Otherwise modify the first node
- (setf (aref new-network 1 n2-root) ; Update tree larger
- (+ (aref new-network 1 n2-root) (aref new-network 1 n1-root)))))
- new-network)))
-
-
-;;; Macro definitions
-
-
-(defmacro connected (network n1 n2)
- "Return true if n1 and n2 are connected and nil otherwise. connection represent
-the find operation on the Quick Union algorithm"
- `(= (find-root ,network ,n1) (find-root ,network ,n2)))
-
-(defmacro nunion_ (network n1 n2)
- "A destructive version of the union function."
- `(setf ,network (union_ ,network ,n1 ,n2)))
-
-