(defun demo-search2 () (ga 'AG) (ga 'AG2) (ga 'HY) (ga 'PB)) (defun ga (type) (let* ((best (completeAllBut (list))) (bestScore (runPom2 type best)) (iterationsSinceLastChange 0) (maxIterationsSinceChange 10) (triesPerIteration 50) (maxIterations 100) (iterations 0) (treatmentSize (length best)) (percentToRemove .49)) (format t "~%==================~%This is Genetic Program for ~A~%====================~%" type) (while (and (< iterations maxIterations) (< iterationsSinceLastChange maxIterationsSinceChange)) (let ((newTreatments (list))) (format t "Iteration ~A of ~A. Iterations since last change: ~A. Best Score: ~A~%" iterations maxIterations iterationsSinceLastChange bestScore) (dotimes (x triesPerIteration) (push (completeAllBut (removePercentFromList best percentToRemove)) newTreatments)) ;(incf iterationsSinceLastChange) (let (tmpBest (tmpBestScore 0)) (dolist (new newTreatments) (let ((tmpScore (runPom2 type new))) (if (> tmpScore tmpBestScore) (setf tmpBest new tmpBestScore tmpScore)))) (if (> tmpBestScore bestScore) (progn (setf best tmpBest bestScore tmpBestScore iterationsSinceLastChange 0) (format t "-Better:~A,~% ~A~%" bestScore best)) (incf iterationsSinceLastChange))) (incf iterations))) (format t "===================~%The best found had a score of ~A for treatment:~% ~A~%=========================~%Starting backselect~%~%" bestScore best) (backSelect best type))) (defun removePercentFromList (lst percent) (let ((numToRemove (ceiling (* (length lst) percent)))) (setf lst (shuffle (copy-list lst))) ;(print lst) (dotimes (x numToRemove) (pop lst))) ;(print lst) lst)