;; AI Final Project ;; Module: ALM Specifics-L-System mutations ;; CSC 466 - Graci ;; Jacob Peck - 20110330 (setf *alphabet* '(a b)) ; alphabet to choose mutations from, easily weightable (ex. (A B) vs. (A B B)) (defmethod perform-mutations ((pop population) (newpop population) &aux nr-mutations newinds newinds2 ind temp) (if *DEMO* (format t "~%~% Performing mutations~%")) (setf ind (population-individuals pop)) (setf newinds '()) (setf newinds2 '()) (setf nr-mutations (ceiling (* (length ind) (float (/ (population-chance-mutate pop) 100))))) (if *DEMO* (format t " doing ~A mutations~%" nr-mutations)) (setf offset (length (population-individuals newpop))) (dotimes (i nr-mutations NIL) (loop do (setf temp (select-individual pop)) until (null (member temp newinds))) (setf newinds (append newinds (list temp))) ) (dotimes (i nr-mutations NIL) (setf temp (copy-individual (nth i newinds))) (setf (individual-name temp) (+ i offset 1)) (mutate-individual temp) (setf newinds2 (append newinds2 (list temp))) ) (dolist (element newinds2 NIL) (add-individual newpop element) ) NIL ) (defmethod mutate-individual ((ind individual) &aux pos lsys changeable pos2) (setf lsys (individual-data ind)) (if *DEMO* (progn (format t "Original l-sys:~%") (format t "~A~%" (lsys-rules lsys)))) (setf pos (random (length (lsys-rules lsys)))) (setf changeable (cdr (nth pos (lsys-rules lsys)))) (setf pos2 (random (length changeable))) (setf (nth pos2 changeable) (pick *alphabet*)) (setf (nth pos (lsys-rules lsys)) (append (list (car (nth pos (lsys-rules lsys)))) changeable)) (setf (individual-data ind) lsys) (if *DEMO* (progn (format t "Possibly mutated individual (look for mutation at (~A,~A)):~%" pos pos2) (visualize-individual ind) (format t "~A~%" (lsys-rules (individual-data ind))) ) ) NIL )