Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
JuliaGP/gp.jl
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
50 lines (46 sloc)
1.15 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#= | |
Objective: Find minimum time vehicle control program | |
Terminal Set: x (position) | |
v (velocity) | |
-1 | |
Function Set: +, -, *, DIV, GT, ABS | |
Cost: Time to bring behicle to phase plane origin | |
averaged over 20 random initial conditions | |
Gen. Limit: 50 | |
Pop. Size: 500 | |
Max Initial Tree Depth: 6 | |
Init. Method: Ramped half-and-half | |
Max. Tree depth: 17 | |
X-Over Prob.: 0.9 | |
Mutation prob.: 0 | |
Number of elites: 2 | |
Selection: Tournament | |
=# | |
function GT(a,b) | |
if a > b | |
return 1 | |
else | |
return -1 | |
end | |
end | |
function DIV(a,b) | |
if abs(b) < 10.0^-10 | |
return 1 | |
else | |
return a/b | |
end | |
end | |
function create_single_full_tree(depth, fs, ts) | |
# If we are not at the bottom | |
if depth == 1 | |
return Expr(:call, fs[rand(1:length(fs))], ts[rand(1:length(ts))], ts[rand(1:length(ts))]) | |
else | |
return Expr(:call, fs[rand(1:length(fs))], create_single_full_tree(depth-1, fs, ts), create_single_full_tree(depth-1, fs, ts)) | |
end | |
end | |
function main() | |
fs = [:+, :-, :DIV, :GT] | |
ts = [:x, :v, -1] | |
tst = create_single_full_tree(4, fs, ts) | |
end | |
main() |