(defun backSelect (treatment type) (_backSelect (list treatment) type)) (defun _backSelect (treatments type) (let ((good (list (first treatments))) (maxScore (runPom2 type (first treatments)))) (while (> (length treatments) 0) ;(format t "~A " (length treatments)) (let ((treatment (pop treatments))) (let ((score (runPom2 type treatment))) (if (> score (* .95 maxScore)) (progn (if (> score maxScore) (setf maxScore score)) (setf treatments (append treatments (getChildTreatments treatment))) (push treatment good)))))) (setf good (mapcar #'(lambda (x) (list x (length x) (runPom2 type x))) good)) (let ((lengths (list))) (mapc #'(lambda (x) (pushnew (second x) lengths)) good) (let ((finalTreatments (sort (mapcar #'(lambda (x) (let ((thisLength (copy-list (remove-if-not #'(lambda (y) (= (second y) x)) good)))) (setf thisLength (sort thisLength #'< :key #'second)) ;(print thisLength) (car thisLength))) lengths) #'> :key #'third))) (mapcar #'(lambda (x) (format t "~A, ~A~%" (third x) (first x))) finalTreatments) (print ""))))) (defun nDecimal (number &optional (points 2)) (float (/ (floor (* number (expt 10 points))) (expt 10 points)))) (defun average (lst) (/ (reduce '+ lst) (length lst))) (defun getChildTreatments (treatment) ;(format t "Adding treatments for ~A~%" treatment) (let (lst) (dotimes (x (length treatment)) (let ((tmpLst (copy-list treatment))) (push (remove-nths (list x) tmpLst) lst))) lst)) (defun remove-nths (doomeds l &optional (n 0)) (if (null doomeds) l (remove-nths1 doomeds (first l) (rest l) n))) (defun remove-nths1 (doomeds first rest n) (if (= n (first doomeds)) (remove-nths (rest doomeds) rest (1+ n)) (cons first (remove-nths doomeds rest (1+ n)))))