Review of objects overview overview
Class of objects Attributes/ methods
Object Instance of an class
Method A function that acts on objects of a class
Message passing Object to object
Inheritance Objects inheriting attributes and methods of superclasses as well as having their own attributes and methods
Abstraction Many to the few
Encapsulation Hide the complexities
Polymorphism Methods of same name can mean different things as they are tied to their own classes
GAs
Genetic Algorithms Definition a computer simulation in which a population of abstract representations (called chromosomes, genotype, or genome) of candidate solutions (called individuals, creatures, or phenotypes) to an optimization problem evolves toward better solutions. Basics A genetic representation of the solution domain, A fitness function to evaluate the solution domain. Along the way crossover and mutation Fitness tests Until a solution is found that satisfies minimum criteria
Interesting Example Example
Karl Sims Evolved Virtual Creatures Not an animation Evolved objects in motion Encased in various media (water, air, etc.) With gravity
Evolved Virtual Creatures
In lisp Creating a very simple genetic algorithm for producing melodies of a certain type
Step 1 1. program a class of objects that have music melodies as attributes
Step 2 2. create a whole bunch, say 100, of instances of this object class (initial population)
Step 3 3. give the objects a (fitness test) based on overall interval direction, say 9 [stop when fulfilled]
Step 4 4. the ones closest survive (selection), the rest are discarded
Step 5 5. the remaining ones (mate)
Step 6 6. their offspring inherit (crossover) the general shape of the parents combined melodies
Step 7 7. maybe a (mutation) creeps in
Step 8 8. return to step 3
1. program a class of objects that have music melodies as attributes 2. create a whole bunch, say 100, of instances of this object class (initial population) 3. give the objects a (fitness test) based on overall interval direction, say 9 [stop when fulfilled] 4. the ones closest survive (selection), the rest are discarded 5. the remaining ones (mate) 6. their offspring inherit (crossover) the general shape of the parents combined melodies 7. maybe a (mutation) creeps in 8. return to step 3
Variables ;;;variables (defvar *mutation* (defvar *allowable-deviation*
Object ;;;class of object with one attribute (a melody) (defclass individual () ((melody :initarg :melody :initform nil :accessor melody)) (:documentation "Our objects in the evolutionary potboiler."))
Functions ;;;functions (defun melody (defun fitness (defun mate (defun inherit (defun mutation
Top level ;;;top-level (defun produce-crossover-melodies
MGC ;;;use MGC to quickly turn into a midi file (mgc "GA-1.mid" :ontimes '() :pitches '() :durations '() :channels '() :dynamics '())
(defvar *mutation* (defvar *allowable-deviation* (defclass individual () ((melody :initarg :melody :initform nil :accessor melody)) ((melody :initarg :melody :initform nil :accessor melody)) (:documentation "Our objects in the evolutionary potboiler.")) (:documentation "Our objects in the evolutionary potboiler.")) (setf i-1 (make-instance 'individual)) (defun melody (defun fitness (defun mate (defun inherit (defun mutation (defun produce-crossover-melodies (mgc "GA-1.mid" :ontimes '() :pitches '() :durations '() :channels '() :dynamics '())