00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <utils/eoRNG.h>
00019 #include "TreeBuilder.h"
00020
00021 Sym TreeBuilder::make_terminal() const {
00022 if (rng.flip(vcprob)) {
00023 return table.get_random_var();
00024 }
00025
00026 return table.get_random_const();
00027 }
00028
00029 Sym TreeBuilder::build_tree(unsigned max_depth, bool grow) const {
00030 if (max_depth == 0 || grow && rng.random(2) == 0) {
00031 return make_terminal();
00032 }
00033
00034
00035
00036 functor_t func = table.get_random_function();
00037
00038 SymVec args(func.arity);
00039
00040 for (unsigned i = 0; i < args.size(); ++i) {
00041 args[i] = build_tree(max_depth-1, grow);
00042 }
00043
00044 return Sym(func.token, args);
00045 }
00046