In retrospect, this code is more applicable to quadcopters and helicopters than it is to conventional airplanes. Basic dynamics have been met, obstacles are avoided, and a firm appreciation of weights, constraints, and complaints has been fostered.
This code begins with a randomized guess; after some time of minimizing, if the error is larger than a prescribed error goal, then a new random guess is made. This process repeats until the error goal is satisfied and we are able to plot what the program was able to come up with.
Modifications to this code could done to resemble flight paths of specific classes and categories of aircraft. Feel free to experiment; add/subtract from the dynamics as you care to.
I hope this helps.