예제 #1
0
void setup_population()
{
    /* function set */
    struct function *functions[10] = {
        function_new_func(ADD, 2),
        function_new_func(SUB, 2),
        function_new_func(MUL, 2),
        function_new_func(DIV, 2),
        function_new_func(POW, 2),

        function_new_func(LOG, 1),
        function_new_func(EXP, 1),
        function_new_func(RAD, 1),
        function_new_func(SIN, 1),
        function_new_func(COS, 1)
    };
    fs = function_set_new(functions, 10);

    /* terminal set */
    float *one= malloc_float(1.0);
    float *two = malloc_float(2.0);

    struct terminal *terminals[2] = {
        terminal_new_constant(FLOAT, one),
        terminal_new_constant(FLOAT, two)
    };
    ts = terminal_set_new(terminals, 2);

    /* setup config */
    c = config_new();
    c->population_size = 100;

    /* general config */
    c->get_score = tree_score;
    c->copy_func = tree_copy;
    c->free_func = tree_destroy;
    c->cmp = tree_cmp;

    /* tree config */
    c->data_struct = tree_config_new();
    ((struct tree_config *) c->data_struct)->build_method = FULL;
    ((struct tree_config *) c->data_struct)->max_depth = 3;
    ((struct tree_config *) c->data_struct)->fs = fs;
    ((struct tree_config *) c->data_struct)->ts = ts;
    c->data_struct_free = tree_config_destroy;

    /* create trees */
    p = tree_population(c);

    free(one);
    free(two);
}
예제 #2
0
/* FUNCTION SET TESTS */
void setup_function_set(void)
{
    struct function *functions[9] = {
        function_new_func(ADD, 2),
        function_new_func(SUB, 2),
        function_new_func(MUL, 2),
        function_new_func(DIV, 2),
        function_new_func(POW, 2),

        function_new_func(LOG, 1),
        function_new_func(EXP, 1),
        function_new_func(SIN, 1),
        function_new_func(COS, 1)
    };
    int n = sizeof(functions) / sizeof(struct function *);

    fs = function_set_new(functions, n);
}
예제 #3
0
void setup(void)
{
    /* function set */
    struct function *functions[9] = {
        function_new_func(ADD, 2),
        function_new_func(SUB, 2),
        function_new_func(MUL, 2),
        function_new_func(DIV, 2),
        function_new_func(POW, 2),

        function_new_func(LOG, 1),
        function_new_func(EXP, 1),
        function_new_func(SIN, 1),
        function_new_func(COS, 1)
    };
    fs = function_set_new(functions, 9);

    /* terminal set */
    int one = 1;
    float two = 2.0;
    const char *three = "three";

    float min = 0.0;
    float max = 100.0;

    struct terminal *terminals[4] = {
        terminal_new_constant(INTEGER, &one),
        terminal_new_constant(FLOAT, &two),
        terminal_new_constant(STRING, (void *) three),
        terminal_new_random_constant(FLOAT, &min, &max, 2)
    };
    ts = terminal_set_new(terminals, 4);

    /* generate trees */
    t1 = tree_generate(FULL, fs, ts, 1);
    t2 = tree_generate(FULL, fs, ts, 1);
}
예제 #4
0
int test_function_new_and_destroy(void)
{
    f = function_new(DEFAULT, 0, 2);
    mu_check(f->type == DEFAULT);
    mu_check(f->function == 0);
    mu_check(f->arity == 2);
    function_destroy(f);

    /* default function */
    f = function_new_func(0, 2);
    mu_check(f->type == DEFAULT);
    mu_check(f->function == 0);
    mu_check(f->arity == 2);
    function_destroy(f);

    /* classification function */
    f = function_new_cfunc(0, 2);
    mu_check(f->type == CLASSIFICATION);
    mu_check(f->function == 0);
    mu_check(f->arity == 2);
    function_destroy(f);

    return 0;
}