;;;; Created on 2007-03-21 17:56:00 (defun metropolis (&key (steps 10000) (cost 'cost) (next 'mutate) (first 'start) (near 0.001)) (let* (best (time 1) (bestS (expt 10 32)) new newS (current (funcall first)) (currentS (funcall cost current))) (loop (if (<= time 0 ) (return (values best bestS))) (setf new (funcall next current) newS (funcall cost new)) (if (< newS bestS) (progn ;(format t " !~a old ~a new ~a delta ~a~%" (say time) (say bestS) (say newS) (say (- bestS newS))) (format t " !~a ~a~%" (say time) (say (- bestS newS))) (setf best (copy-list new) bestS newS))) (if (accept (- newS currentS) time) (setf current (copy-list new) currentS newS)) (setf time (- time (/ 1.0 steps))) ))) (defun accept(delta time) (cond ((< delta 0) ;(format t "-~a" (say time)) t) ((< (random 1.0) (expt 2.781281828 (* -1.0 (/ delta time)))) ;(format t "+~a" (say time)) t) (t nil)))