; http://geocities.com/n8chz/tweak.txt
; Use of this file is ungoverned by the Cypherpunks Anti-License.
; Do with it as you will.
; Kitchen tested under
; Gnu Common Lisp
; version 2-2.2000000000000002
; the file referenced below is at
; http://geocities.com/n8chz/utgraph.txt
(load "utgraph.lsp")
; swap e1'th and e2'th elements of a list
(defun swap (e1 e2 liszt)
(let
((n (length liszt)))
(do
((k 0 (1+ k)))
((= k n) liszt)
(cond
((equal e1 (nth k liszt))
(setf (nth k liszt) e2))
((equal e2 (nth k liszt))
(setf (nth k liszt) e1))))))
; swap two values in a
; midpoint partition
; generated by
; #'random-partition
; in "utgraph.lsp"
; "swap in randomized midpoint partition"
(defun sir-mpp (mpp)
(let*
((n (length mpp))
(i (random n))
(jj (random (1- n)))
(j (if (>= jj i) (1+ jj) jj))
(dummy (nth i mpp)))
(setf (nth i mpp) (nth j mpp))
(setf (nth j mpp) dummy)
mpp))
; swap values
; in a random embedding
; generated by #'random-init-embed
; (in "utgraph.lsp")
(defun swap-in-embed (embed)
(transpose (mapcar #'sir-mpp (transpose embed))))
; do swap-in-embed on embed
; portion of graph structure
; as defined in "utgraph.lsp"
(defun swap-in-graph (graph)
(setf (cdr graph) (swap-in-embed (cdr graph)))
graph)
; brute force method for improving graphs
; using swap-in-graph
; this is notably slower than
; #'improve-graph
; (in "utgraph.lsp")
; for some reason it doesn't work
(defun iterate-graph (graph)
(do*
((oldcorr (correlate-graph graph))
(propose (swap-in-graph graph) (swap-in-graph propose)))
((< (correlate-graph propose) oldcorr) propose)))
; iterate graph n times
; write intermediate results
; to file named by 'filename
(defun ign (graph n filename)
(do
((left n (1- left))
(val graph (iterate-graph val))
(stream (open filename :direction :output)))
((zerop left) (close stream) val)
(print val stream)
(print (cons left (correlate-graph val)))))