anchor.diff:  ;;;;
   ;;
   ;; Usage example:
  -;;  (let*
  -;;      ((graph (bmg:read-graph #P"/path/to/data.bmg"))
  -;;       (start-node (gethash "Protein_UniProt:P04083" (bmg:node-by-name graph)))
  -;;       (goal-node (gethash "Protein_UniProt:P07355" (bmg:node-by-name graph))))
  -;;    (time (run-iterations graph 5000 start-node goal-node)))
  +;; (let*
  +;;     ((graph (bmg:read-graph #P"/path/to/data.bmg"))
  +;;      (start-node (gethash "Protein_UniProt:P04083" (bmg:node-by-name graph)))
  +;;      (goal-node (gethash "Protein_UniProt:P07355" (bmg:node-by-name graph))))
  +;;   (time (array-ttnr:run-iterations
  +;; 	 #'array-ttnr:bfs-lazy-with-bit-vectors
  +;; 	 graph 5000 start-node goal-node)))
   ;;
  -;;  (let*
  -;;      ((graph (bmg:read-graph #P"/path/to/data.bmg"))
  -;;       (start-node (gethash "Protein_UniProt:P04083" (bmg:node-by-name graph)))
  -;;       (goal-node (gethash "Protein_UniProt:P07355" (bmg:node-by-name graph))))
  -;;    (time (run-lazy-iterations graph 10000 start-node goal-node)))
  +;; (let*
  +;;     ((graph (bmg:read-graph #P"/path/to/data.bmg"))
  +;;      (start-node (gethash "Protein_UniProt:P04083" (bmg:node-by-name graph)))
  +;;      (goal-node (gethash "Protein_UniProt:P07355" (bmg:node-by-name graph))))
  +;;   (time (array-ttnr:run-iterations
  +;; 	 #'array-ttnr:bfs-with-precomputed-gamma
  +;; 	 graph 5000 start-node goal-node)))
  +;;
   
   (defpackage #:array-ttnr
     (:use #:common-lisp #:iterate)
     (:export #:run-iterations
  -	   #:randomized-bfs))
  +	   #:bfs-lazy-with-bit-vectors
  +	   #:bfs-with-precomputed-gamma
  +	   #:create-gamma))
   
   (in-package :array-ttnr)
   
  
positive.code:     array))
  
  
  (defun bfs-with-gamma (start-node goal-node gamma &optional
  		       (visited (make-array (list (array-dimension gamma 0)) :element-type 'bit)))
    (declare (optimize (speed 3) (safety 0) (space 0) (debug 0) (compilation-speed 0)))
    (let ((queue (list (bmg:id start-node)))
  	(goal-node (bmg:id goal-node))
  	(max-node-id (- (array-dimension gamma 0) 1)))
      (loop while queue do
  	 (let ((current-node (pop queue)))
  	   (if (eq current-node goal-node)
  	       (return-from bfs-with-gamma t))
  	   (setf (aref visited current-node) 1)
  
   	   (iterate (for i from 0 to max-node-id)
  		    (when (eq 1 (aref gamma current-node i))
  		      (if (eq 0 (aref visited i))
  			  (if (not queue)
  			      (setf queue (cons i queue))
  			      (nconc queue (list i))))))))))
  
  
  (defun lazy-random-bfs (graph start-node goal-node)
    (let* ((weights (create-weight-matrix graph))
  	 (queue (list (bmg:id start-node)))
  	 (goal-node (bmg:id goal-node))
  
negative.code: 	 (visited (make-array (list array-size) :element-type 'bit))
  	 (calculated (make-array (list array-size array-size) :element-type 'bit))
  	 (connected (make-array (list array-size array-size) :element-type 'bit)))
      (declare (type (simple-array bit) visited))
      (declare (type (array bit 2) calculated connected))
  
      (loop while queue do
  	 (let ((current-node (pop queue)))
  	   (when (eq current-node goal-node)
  	     (return-from bfs-lazy-with-bit-vectors t))
  	   (setf (aref visited current-node) 1)
  
   	   (iterate
  	     (for i from 0 to max-node-id)
  	     (let
  		 ((edge-existence-calculated (eq 1 (aref calculated current-node i)))
  		  (edge-weight (aref weights current-node i)))
  	       (declare (type single-float edge-weight))
  
  	       (when (and
  		      (eq nil edge-existence-calculated)
  		      (> edge-weight 0.0))
  
  		 (setf (aref connected current-node i)
  		       (let ((random-float (random 1.0)))
  			 (declare (type single-float random-float))
  			 (if (> edge-weight random-float) 1 0)))
  		 (setf (aref calculated current-node i) 1))
  
  	       (when (eq 1 (aref connected current-node i))
  		 (unless (eq 1 (aref visited i))
  		   (if (not queue)
  		       (setf queue (cons i queue))
  		       (nconc queue (list i)))))))))))
  
  
  (defun run-iterations (implementation graph iteration-count from to)
    (let ((successful-iterations 0))
      (dotimes (iterations-so-far iteration-count)
        (when (funcall implementation graph from to)
  	(incf successful-iterations)))
      (values (format nil "~f" (/ successful-iterations iteration-count))
  	    successful-iterations iteration-count)))
  