Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

geqo_recombination.c File Reference

#include "postgres.h"
#include "optimizer/geqo_random.h"
#include "optimizer/geqo_recombination.h"
Include dependency graph for geqo_recombination.c:

Go to the source code of this file.

Functions

void init_tour (PlannerInfo *root, Gene *tour, int num_gene)
Cityalloc_city_table (PlannerInfo *root, int num_gene)
void free_city_table (PlannerInfo *root, City *city_table)

Function Documentation

City* alloc_city_table ( PlannerInfo root,
int  num_gene 
)

Definition at line 72 of file geqo_recombination.c.

References palloc().

Referenced by geqo().

{
    City       *city_table;

    /*
     * palloc one extra location so that nodes numbered 1..n can be indexed
     * directly; 0 will not be used
     */
    city_table = (City *) palloc((num_gene + 1) * sizeof(City));

    return city_table;
}

void free_city_table ( PlannerInfo root,
City city_table 
)

Definition at line 90 of file geqo_recombination.c.

References pfree().

Referenced by geqo().

{
    pfree(city_table);
}

void init_tour ( PlannerInfo root,
Gene tour,
int  num_gene 
)

Definition at line 38 of file geqo_recombination.c.

References geqo_randint, i, palloc(), and pfree().

Referenced by random_init_pool().

{
    Gene       *tmp;
    int         remainder;
    int         next,
                i;

    /* Fill a temp array with the IDs of all not-yet-visited cities */
    tmp = (Gene *) palloc(num_gene * sizeof(Gene));

    for (i = 0; i < num_gene; i++)
        tmp[i] = (Gene) (i + 1);

    remainder = num_gene - 1;

    for (i = 0; i < num_gene; i++)
    {
        /* choose value between 0 and remainder inclusive */
        next = geqo_randint(root, remainder, 0);
        /* output that element of the tmp array */
        tour[i] = tmp[next];
        /* and delete it */
        tmp[next] = tmp[remainder];
        remainder--;
    }

    pfree(tmp);
}