예제 #1
0
	Node* generate_full_tree(std::mt19937& random, int levels, bool is_ghost)
	{
		if (levels <= 0) return nullptr;
		if (levels == 1)
		{
			return generate_terminal_node(random, is_ghost);
		}
		else
		{
			Node* parent = generate_parent_node(random);
			for (int child_index = 0; child_index < parent->GetMinChildren(); ++child_index)
			{
				parent->children.emplace_back(generate_full_tree(random, levels - 1, is_ghost));
			}
			return parent;
		}
	}
예제 #2
0
void individual_spawn(
        individual_s * const individual )
{
    if( individual == NULL )
    {
        fprintf( stderr, "bad parameter in individual_spawn\n");
        graceful_exit( EXIT_FAILURE );
    }

    individual->tree_root_node = node_alloc();
    individual->fitness = 0;
    individual->tree_node_count = 1;
    individual->tree_nonterminal_count = 0;
    individual->tree_terminal_count = 0;

    node_s *parent = NULL;
    unsigned long current_depth = 0;

    generate_full_tree(
            individual->tree_root_node,
            current_depth,
            parent );
}