Next: Neutral Variants, Previous: Mutation, Up: Usage [Contents][Index]
The example code below does the following.
test
function used to evaluate the fitness of a
software object. This function makes use of an external shell script
test driver which is run using the shell
function defined in
the software-evolution-utility
library.
fitness
field of each mutant is set using the previously
defined test
method.
(in-package :software-evolution-example) (defun test (asm) ; (1) (ignore-errors (with-temp-file (bin) (phenome asm :bin bin) (count-if #'identity (loop :for i :below 11 :collect (multiple-value-bind (stdout stderr errno) (shell "../test/gcd/test.sh ~a ~d" bin i) (declare (ignorable stdout stderr)) (zerop errno))))))) (let ((orig (from-file (make-instance 'asm) "../test/gcd/gcd.s"))) ; (2) (loop :for i :below 10 :do (multiple-value-bind (mutant edit) (mutate (copy orig)) ; (3) (setf (fitness mutant) (test mutant)) ; (4) (format t "~2d fitness for edit ~S~%" (fitness mutant) edit)))) ; (5)
Executing this code will print output resembling the following.
0 fitness for edit (:INSERT 76 38) 0 fitness for edit (:SWAP 66 77) 0 fitness for edit (:CUT 50) 10 fitness for edit (:CUT 11) 10 fitness for edit (:SWAP 62 39) 0 fitness for edit (:INSERT 2 48) 10 fitness for edit (:CUT 66) 0 fitness for edit (:CUT 73) 10 fitness for edit (:INSERT 73 26) 0 fitness for edit (:INSERT 71 1)