(defun demo-search4 () (format t "************************************~% This is Simulated Annealing talking to you~%**********************************************~%") (format t "I'm now running SA with Agile~%") (simulatedAnnealing 'AG 10) (format t "~%~%------------------------------------------~%") (format t "I'm now running SA with Agile2~%") (simulatedAnnealing 'AG2 10) (format t "~%~%------------------------------------------~%") (format t "I'm now running SA with Planbased~%") (simulatedAnnealing 'PB 10) (format t "~%~%------------------------------------------~%") (format t "I'm now running SA with Hybrid~%") (simulatedAnnealing 'HY 10)) (defun simulatedAnnealing(type maxIteration) (let ((bestTreatment nil) (bestResult 0) (conntinue T) (iteration 0) (result 0) (treatment)) ;Resets all the distributions (reset-all-sample) ;First run of Pom2 to get a startingpoint (setf bestResult (runPom2 type)) ;Saves the treatment (setf bestTreatment (completeAllBut(getStatic))) (format t "~%~%Iteration: ") (while conntinue ;Which iteration (incf iteration) (format t "~A, " iteration) ;Create a new tratment from the previous one, nudge by exp(-3*iteration/Max iteations) procent (setf treatment (nudgeAll bestTreatment (exp (/ (* -3 iteration) maxIteration)))) (setf result (runPom2 type (completeAllBut treatment))) ;If this was better the the so far best one,is so save and start over (if (> result bestResult) (progn (setf bestResult result) (setf bestTreatment (completeAllBut treatment)) (format t "~%Found new best treatment with score: ~A~%" bestResult) (print bestTreatment) (format t "~%~%Iteration: "))) ;Stopping critera, if we have done so many iterations, could be more advanced and adaptive (setf conntinue (< iteration maxIteration))) (format t "~%~%Finished~% The best found treatment had the score ~A" bestResult) (print bestTreatment) (format t "~%~%Running backseleect with the best treatment~%~%") ; (backselect bestTreatment type) )) (defun nudgeAll (treatment nudgeFactor) (let ((newTreatment nil)) (dolist (param treatment newTreatment) (push (list (first param) (nudge (second param) nudgeFactor (first param))) newTreatment))))