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


3.4 Repair

Using the test function defined in a previous example (see Evaluation), the code block below searches for a “repair” of the buggy gcd implementation in ../test/gcd/gcd.s. The “repair” will be a version of gcd which passes all 11 tests run in test.

The target and max-evals keyword arguments are passed to evolve (see evolve). These arguments terminate the evolutionary search when either a repair has been reached or a budget of fitness evaluations has been exhausted respectively.

The following properties of this example should be noted.

  1. Before calling evolve the population is populated with copies of the original program.
  2. The *orig* individual is assigned a fitness before the *population* is populated. This is necessary as the search functions assume that every element of *population* already have a fitness assigned.
  3. The *population* is not explicitly passed to the evolve function which implicitly modifies the *population* variable. When this function terminates the evolved program variants will be saved in the *population*.
(in-package :software-evolution-example)

(defvar *orig* (from-file (make-instance 'asm) "../test/gcd/gcd.s"))

(setf (fitness *orig*) (test *orig*))   ; (2)

(setf *population*
      (loop :for i :below 100 :collect (copy *orig*))) ; (1)

(evolve #'test :max-evals 100 :target 11) ; (3)

Parallel Repair

Evolution may be parallelized by calling evolve in multiple threads. For example a parallel version of the above example would replace,

(evolve #'test :max-evals 100 :target 11)

with the following.

(require 'bordeaux-threads)
(defvar *num-threads* 64 "Number of available cores.")

;; launch *num-threads* evolution threads
(let (threads)
  (loop :for n :below *num-threads* :do
     (push (bordeaux-threads:make-thread
            (lambda () (evolve #'test :max-evals 100 :target 11))
            :name (format nil "opt-~d" n))
           threads)))

;; wait for all threads to return
(mapc #'bordeaux-threads:join-thread threads)

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