#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include "main.h"
#include "data.h"
#include "modsup.h"
#include "error.h"
#include "gettext.h"
#include "assert.h"
Functions | |
domain * | domain_new (resourcetype *restype) |
Creates a new full domain. (domain with all possible values for a specified resource type). | |
int | domain_addtuple (domain *dom, tupleinfo *tuple) |
Adds a tuple to a domain. | |
void | domain_and (domain *dom, int *val, int valnum) |
Removes some values from a domain. | |
void | domain_free (domain *dom) |
Free a domain structure. | |
void | domain_freeall () |
Free all domains. | |
int | domain_compare (domain *d1, domain *d2) |
Compare if two domains contain same values. | |
int | compact_domains () |
Finds and merges duplicate domains. | |
int | domain_rand (domain *dom) |
Returns a random value from a domain. | |
int | domain_check (domain *dom, int val) |
Checks if a value is present in a domain. | |
resourcetype * | restype_new (int var, char *type) |
Define a new resource type. | |
int | restype_findid (char *type) |
Find a resource type (either variable or constant) by name and return a resource type ID. | |
resourcetype * | restype_find (char *type) |
Find a resource type by name. | |
void | res_set_conflict (resource *res1, resource *res2) |
Set conflict between resource res1 and resource res2. | |
int | compact_conflicts () |
Generates conflict lookup tables for all defined resource types. | |
resource * | res_new (resourcetype *restype, char *name) |
Add a new resource to a resource type. | |
resource * | res_new_matrix (resourcetype *restype, int width, int height) |
Adds a matrix of resources to a resource type. | |
int | res_get_matrix (resourcetype *restype, int *width, int *height) |
Finds the dimensions of a matrix of resources. | |
int | res_findid (resourcetype *restype, char *name) |
Find a resource by name and return its resource ID. | |
resource * | res_find (resourcetype *restype, char *name) |
Find a resource by name. | |
void | restype_freeall () |
Free all resource types and all resources. | |
void | tuple_set (tupleinfo *tuple, resource *res) |
Set a resource in a tuple. | |
int | tuple_compare (int tupleid1, int tupleid2) |
Compare two events. | |
tupleinfo * | tuple_new (char *name) |
Add a new tuple. | |
void | tuple_freeall () |
Free all tuples. | |
tuplelist * | tuplelist_new () |
Allocate a new empty tuplelist structure. | |
int | tuplelist_add (tuplelist *dest, int tupleid) |
Add a new tupleid to the tuplelist structure. | |
void | tuplelist_free (tuplelist *dest) |
Frees a tuplelist structure. | |
outputext * | outputext_new (char *contype, char *vartype) |
Allocate a new output extension struct. | |
int | outputext_update (outputext *ex, table *tab) |
Update output extension with new data from a timetable. | |
void | outputext_free (outputext *dest) |
Free an output extension struct. | |
ext * | ext_new (ext **ex, int contype, int vartype) |
Allocate a new extension struct in a linked list. | |
void | ext_update (ext *ex, table *tab) |
Update extension with new data from a timetable. | |
slist * | slist_new (slist **list, int vartype) |
Allocate a new slist struct in a linked list. | |
void | slist_update (slist *list, table *tab) |
Update slist with new data from a timetable. | |
int | data_init () |
Prepare data structures for use. | |
void | data_exit () |
Free all memory allocated by restype_new(), res_new(), domain_new() and tuple_new(). | |
static int | table_init (table *tab, int new) |
Helper function for population_init(). | |
population * | population_init (population *pop, int size) |
Initializes population structure. | |
void | population_rand (population *pop) |
Randomize the entire population. | |
void | table_hint (table *tab, int typeid) |
void | population_hint (population *pop, int hintpart) |
Hint a part of the population. | |
Variables | |
miscinfo | dat_info = { title: NULL, address: NULL, author: NULL } |
Miscellaneous information about the timetable. | |
int | dat_typenum = 0 |
Number of all defined resource types. | |
resourcetype * | dat_restype = NULL |
Array of dat_typenum resource types. | |
int | dat_tuplenum = 0 |
Number of all defined tuples (events). | |
tupleinfo * | dat_tuplemap = NULL |
Array of dat_tuplenum tuples. | |
domain * | dat_domains = NULL |
Linked list of defined domains. |
int compact_conflicts | ( | ) |
Generates conflict lookup tables for all defined resource types.
int compact_domains | ( | ) |
Finds and merges duplicate domains.
This function must be called after all tuples were added.
int data_init | ( | ) |
Prepare data structures for use.
Adds a tuple to a domain.
dom | Pointer to the domain struct. | |
tuple | Pointer to the tupleinfo struct. |
void domain_and | ( | domain * | dom, | |
int * | val, | |||
int | valnum | |||
) |
Removes some values from a domain.
This function removes all values from dom domain that are not in the val list.
dom | Pointer to the domain struct | |
val | Array of values | |
valnum | Number of values in the array |
int domain_check | ( | domain * | dom, | |
int | val | |||
) |
Checks if a value is present in a domain.
dom | Pointer to the domain struct. | |
val | Value to be checked for. |
Compare if two domains contain same values.
d1 | Pointer to the first domain | |
d2 | Pointer to the second domain |
void domain_free | ( | domain * | dom | ) |
Free a domain structure.
dom | Pointer to the domain struct to be freed |
domain* domain_new | ( | resourcetype * | restype | ) |
Creates a new full domain. (domain with all possible values for a specified resource type).
The allocated domain contains no tuples.
restype | Resource type for this domain. |
int domain_rand | ( | domain * | dom | ) |
Returns a random value from a domain.
dom | Pointer to the domain struct. |
Allocate a new extension struct in a linked list.
Linked list is first searched for an identical extension struct. If such a structure is found, only a pointer to it is returned and the linked is is not changed. If no such structure exists, a new structure is allocated and inserted at the beginning of the linked list.
ex | Pointer to the linked list. | |
contype | Constant resource type id. | |
vartype | Variable resource type id. |
Update extension with new data from a timetable.
ex | Pointer to the extension structure to update. | |
tab | Pointer to the table with the new data. |
void outputext_free | ( | outputext * | dest | ) |
Free an output extension struct.
dest | Pointer to the output extenstion struct to free. |
outputext* outputext_new | ( | char * | contype, | |
char * | vartype | |||
) |
Allocate a new output extension struct.
contype | Constant resource type. | |
vartype | Variable resource type. |
Update output extension with new data from a timetable.
ex | Pointer to the output extension structure to update. | |
tab | Pointer to the table with the new data. |
void population_hint | ( | population * | pop, | |
int | hintpart | |||
) |
Hint a part of the population.
If dat_tuplemap contains information that can be used to initialize variable chromosomes in the population (i.e. the user has loaded an XML file that already contains a partial or a full solution), then this function initializes some variable chromosomes.
If dat_tuplemap doesn't contain this information this function does nothing.
If the information in dat_tuplemap conflicts with a domain of a tuple then the dat_tuplemap information is ignored for that tuple and an error is reported.
pop | Pointer to the population to be hinted. | |
hintpart | Percent of the population that will be hinted. |
population* population_init | ( | population * | pop, | |
int | size | |||
) |
Initializes population structure.
All resources, resource types and tuples (events) must be defined before calling this function.
If pop is NULL, a new structure with population size size is allocated using the number of tuples and resource types. If pop is not NULL then only proper links to resources, etc. are made.
Checks are also performed to see if population pop is compatible with the number of defined resource types, etc. size parameter is not used in this case.
pop | Pointer to the population structure to be initialized. | |
size | Size of the population. |
void population_rand | ( | population * | pop | ) |
Randomize the entire population.
All variable chromosomes in the population are filled with random values (domains of individual tuples, as specified in dat_tuplemap are respected)
pop | Pointer to the population to be randomized. |
resource* res_find | ( | resourcetype * | restype, | |
char * | name | |||
) |
Find a resource by name.
restype | Pointer to the resource type structure in which to search for the resource. | |
name | Name of the resource type to find. |
int res_findid | ( | resourcetype * | restype, | |
char * | name | |||
) |
Find a resource by name and return its resource ID.
restype | Pointer to the resource type structure in which to search for the resource. | |
name | Name of the resource type to find. |
int res_get_matrix | ( | resourcetype * | restype, | |
int * | width, | |||
int * | height | |||
) |
Finds the dimensions of a matrix of resources.
This function finds the width and height of a matrix of resources that was defined by the res_new_matrix() function. There must be no other resources defined in the specified resource type.
restype | Pointer to the resource type structure. | |
width | Width of the matrix. | |
height | Height of the matrix. |
resource* res_new | ( | resourcetype * | restype, | |
char * | name | |||
) |
Add a new resource to a resource type.
After the first resource was added, any calls to restype_new() have unspecified effects.
restype | Pointer to a resource type structure. | |
name | Name of the resource to add. |
resource* res_new_matrix | ( | resourcetype * | restype, | |
int | width, | |||
int | height | |||
) |
Adds a matrix of resources to a resource type.
This function adds width * height new resources to the specified resource type. New resources have names "x y", where x goes from 0 to width -1 and y goes from 0 to height -1. Resources are ordered first by y and then by x.
For example:
x=resid/height; y=resid%height;
If there were no resources added to the resource type before the res_new_matrix() function was called, x now holds the x coordinate and y the y coordinate of the resource with resid resource ID in the matrix.
restype | Pointer to a resource type structure. | |
width | Width of the matrix. | |
height | Height of the matrix. |
Set conflict between resource res1 and resource res2.
Resources must be of the same type. In most cases you must call this function twice:
res_set_conflict(res1, res2); res_set_conflict(res2, res1);
res1 | Pointer to the first resource struct. | |
res2 | Pointer to the second resource struct. |
resourcetype* restype_find | ( | char * | type | ) |
Find a resource type by name.
type | Name of the resource type to find. |
int restype_findid | ( | char * | type | ) |
Find a resource type (either variable or constant) by name and return a resource type ID.
type | Name of the resource type to find. |
resourcetype* restype_new | ( | int | var, | |
char * | type | |||
) |
Define a new resource type.
var | 1 if this is a variable resource type and 0 if this is a constant resource type. | |
type | Name of this resource type (string is duplicated). |
Allocate a new slist struct in a linked list.
Linked list is first searched for an identical slist struct. If such a structure is found, only a pointer to it is returned and the linked is is not changed. If no such structure exists, a new structure is allocated and inserted at the beginning of the linked list.
list | Pointer to the linked list. | |
vartype | Variable resource type id. |
Update slist with new data from a timetable.
list | Pointer to the slist structure to update. | |
tab | Pointer to the table with the new data. |
int tuple_compare | ( | int | tupleid1, | |
int | tupleid2 | |||
) |
Compare two events.
Two events are considered equal (for example, they were defined as repeats of a single <event> tag), if their names are equal and if they have the same constant resources.
tupleid1 | Tuple ID of the first event. | |
tupleid2 | Tuple ID of the second event. |
tupleinfo* tuple_new | ( | char * | name | ) |
Add a new tuple.
After the first tuple was added, any calls to restype_new() and res_new() have unspecified effects.
Tuples are independent by default.
name | Name of the tuple (event). |
Set a resource in a tuple.
Note that only one resource of each type can be used in a tuple.
tuple | Pointer to the tupleinfo struct of the tuple to change. | |
res | Pointer to the resource which is used by the tuple. |
int tuplelist_add | ( | tuplelist * | dest, | |
int | tupleid | |||
) |
Add a new tupleid to the tuplelist structure.
dest | Pointer to the tuplelist structure. | |
tupleid | Tuple ID to add. |
void tuplelist_free | ( | tuplelist * | dest | ) |
Frees a tuplelist structure.
dest | Pointer to the structure to free. |
tuplelist* tuplelist_new | ( | ) |
Allocate a new empty tuplelist structure.