From 6b1d7a478d08864fa426adab2fb4cee67821df19 Mon Sep 17 00:00:00 2001 From: Stephen Date: Fri, 9 Mar 2018 10:58:10 -0500 Subject: [PATCH] Sorta works now --- gp.jl | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/gp.jl b/gp.jl index c5764f6..99677a2 100644 --- a/gp.jl +++ b/gp.jl @@ -17,12 +17,6 @@ Number of elites: 2 Selection: Tournament =# - -function math_expr(op, op1, op2) - expr = Expr(:call, op, , op1, op2) - return expr -end - function GT(a,b) if a > b return 1 @@ -39,19 +33,18 @@ function DIV(a,b) end end -function create_single_full_tree(depth, function_set, terminal_set) +function create_single_full_tree(depth, fs, ts) # If we are not at the bottom - if depth > 2: - fn = function_set[1] - trm1 = create_single + 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() - - function_set = [:+, :-, :DIV, :GT] - terminal_Set = ["x", "v", -1] - - + fs = [:+, :-, :DIV, :GT] + ts = [:x, :v, -1] + tst = create_single_full_tree(4, fs, ts) end main()