Genetic program for determining the optimal control for a two-state Newtonian system
April 5, 2013

Gnu Clisp 2.49
LispIDE v20100318.07

Directions:

1. Download and install the latest version of CLISP (Common Lisp). Download and install an integrated development environment (IDE) for CLISP. The minimum-time control problem in the text "Evolutionary Optimization Algorithms" was implemented with LispIDE.

2. Change the Path variables in GPCartControl.lisp and PhasePlane.lisp to match the directory where your Lisp files are located.

3. Execute GPCartControl.lisp. Make sure the path variable (line 15) is set to the directory in which your programs reside. Necessary programs that are called by GPCartControl.lisp include:
   AddNodes.lisp
   CartSim.lisp
   CartStep.lisp
   DIV.lisp
   FindSubtree.lisp
   GetDepth.lisp
   GT.lisp
   Roulette.lisp
   Tournament.lisp

4. After GPCartControl is done, it will output two files. One file is <datestring>.txt, which contains the generation number, best cost, and average cost. The other file is <datestring>.lisp, which contains the best program found.

5. Run the Lisp command (setf LispPgm <best program>), where <best program> is a string variable that defines the best program found by the GP. For example, 
(setf LispPgm "(defun CartControl (x v) (if (> (* -1 x) (* v (abs v))) 1 -1))").

6. Run the Lisp function (PhasePlane LispPgm). This will create two files. One file is PhasePlane.txt, which is a list of (x, v, control) values generated by LispPgm. The other file is PhasePlane1.txt, which is a list of (x, v) values at which the control switches between -1 and +1. This assumes that the control generated by LispPgm is always saturated. If this assumption is not true, then PhasePlane1.txt will not be useful.

7. Run the Matlab program PlotPhasePlane.m with input string 'PhasePlane'. This will generate a phase plane plot of the control as a function of x and v. However, some of the plots will not be useful unless the assumption described above is satisfied - that is, unless the control generated by LispPgm is always saturated.

8. The fitness of a cart control Lisp program can be evaluated by running EvalCartControl.lisp. If CartControl is defined as a Lisp function (see step 4 above), then you can open EvalCartControl.lisp, evaluate it in the Lisp GUI so that EvalCartControl is a defined function, and then run "(EvalCartControl #'CartControl)" in Lisp.