Next: , Previous: , Up: Usage   [Contents][Index]


3.2 Evaluation

The example code below does the following.

  1. Defines a 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.
  2. The original program is initialized from a file on disk.
  3. Ten mutants of the original are generated by applying random edits.
  4. The fitness field of each mutant is set using the previously defined test method.
  5. The edits and fitness of each mutant are printed.
(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)