data.c File Reference

Static data storage (resources). More...

#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

domaindomain_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.
resourcetyperestype_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.
resourcetyperestype_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.
resourceres_new (resourcetype *restype, char *name)
 Add a new resource to a resource type.
resourceres_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.
resourceres_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.
tupleinfotuple_new (char *name)
 Add a new tuple.
void tuple_freeall ()
 Free all tuples.
tuplelisttuplelist_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.
outputextoutputext_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.
extext_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.
slistslist_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().
populationpopulation_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.
resourcetypedat_restype = NULL
 Array of dat_typenum resource types.
int dat_tuplenum = 0
 Number of all defined tuples (events).
tupleinfodat_tuplemap = NULL
 Array of dat_tuplenum tuples.
domaindat_domains = NULL
 Linked list of defined domains.


Detailed Description

Static data storage (resources).


Function Documentation

int compact_conflicts (  ) 

Generates conflict lookup tables for all defined resource types.

Returns:
0 on success and -1 on error.

int compact_domains (  ) 

Finds and merges duplicate domains.

This function must be called after all tuples were added.

Returns:
0 on success and -1 on error.

int data_init (  ) 

Prepare data structures for use.

Returns:
0 on success and -1 on error.

int domain_addtuple ( domain dom,
tupleinfo tuple 
)

Adds a tuple to a domain.

Parameters:
dom Pointer to the domain struct.
tuple Pointer to the tupleinfo struct.
Returns:
0 on success or -1 on error.

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.

Parameters:
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.

Parameters:
dom Pointer to the domain struct.
val Value to be checked for.
Returns:
1 if the value is present in a domain or 0 if the value is not present.

int domain_compare ( domain d1,
domain d2 
)

Compare if two domains contain same values.

Parameters:
d1 Pointer to the first domain
d2 Pointer to the second domain
Returns:
1 if domains are equal or 0 if they are not

void domain_free ( domain dom  ) 

Free a domain structure.

Parameters:
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.

Parameters:
restype Resource type for this domain.
Returns:
Pointer to the created domain struct or NULL on error.

int domain_rand ( domain dom  ) 

Returns a random value from a domain.

Parameters:
dom Pointer to the domain struct.
Returns:
Random value from the domain.

ext* ext_new ( ext **  ex,
int  contype,
int  vartype 
)

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.

Parameters:
ex Pointer to the linked list.
contype Constant resource type id.
vartype Variable resource type id.
Returns:
Pointer to the new extension struct or NULL on error.

void ext_update ( ext ex,
table tab 
)

Update extension with new data from a timetable.

Parameters:
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.

Parameters:
dest Pointer to the output extenstion struct to free.

outputext* outputext_new ( char *  contype,
char *  vartype 
)

Allocate a new output extension struct.

Parameters:
contype Constant resource type.
vartype Variable resource type.
Returns:
Pointer to the new output extension struct or NULL on error.

int outputext_update ( outputext ex,
table tab 
)

Update output extension with new data from a timetable.

Parameters:
ex Pointer to the output extension structure to update.
tab Pointer to the table with the new data.
Returns:
0 on success and -1 on error.

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.

Parameters:
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.

Parameters:
pop Pointer to the population structure to be initialized.
size Size of the population.
Returns:
Pointer to the initialized structure on success and NULL on error.

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)

Parameters:
pop Pointer to the population to be randomized.

resource* res_find ( resourcetype restype,
char *  name 
)

Find a resource by name.

Parameters:
restype Pointer to the resource type structure in which to search for the resource.
name Name of the resource type to find.
Returns:
Pointer to the resource structure or NULL if this resource was not found.

int res_findid ( resourcetype restype,
char *  name 
)

Find a resource by name and return its resource ID.

Parameters:
restype Pointer to the resource type structure in which to search for the resource.
name Name of the resource type to find.
Returns:
Resource ID or INT_MIN if this resource was not found.

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.

Parameters:
restype Pointer to the resource type structure.
width Width of the matrix.
height Height of the matrix.
Returns:
0 on success (width and height are set to correct values) and -1 on error (this resource type does not contain a matrix of resources - width and height are not touched.

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.

Parameters:
restype Pointer to a resource type structure.
name Name of the resource to add.
Returns:
Pointer to the resource struct on success and NULL on failure.

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.

Parameters:
restype Pointer to a resource type structure.
width Width of the matrix.
height Height of the matrix.
Returns:
Pointer to the last resource struct in the matrix on success and NULL on failure.

void res_set_conflict ( resource res1,
resource res2 
)

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);

Parameters:
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.

Parameters:
type Name of the resource type to find.
Returns:
Pointer to the resourcetype struct or NULL if this resource type was not found.

int restype_findid ( char *  type  ) 

Find a resource type (either variable or constant) by name and return a resource type ID.

Parameters:
type Name of the resource type to find.
Returns:
Resource type ID or INT_MIN if this resource type was not found.

resourcetype* restype_new ( int  var,
char *  type 
)

Define a new resource type.

Parameters:
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).
Returns:
Pointer to the resourcetype struct or NULL on error.

slist* slist_new ( slist **  list,
int  vartype 
)

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.

Parameters:
list Pointer to the linked list.
vartype Variable resource type id.
Returns:
Pointer to the new slist struct or NULL on error.

void slist_update ( slist list,
table tab 
)

Update slist with new data from a timetable.

Parameters:
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.

Parameters:
tupleid1 Tuple ID of the first event.
tupleid2 Tuple ID of the second event.
Returns:
1 if events are equal or 0 if the are not.

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.

Parameters:
name Name of the tuple (event).
Returns:
Pointer to the tupleinfo struct of the new tuple or NULL on error.

void tuple_set ( tupleinfo tuple,
resource res 
)

Set a resource in a tuple.

Note that only one resource of each type can be used in a tuple.

Parameters:
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.

Parameters:
dest Pointer to the tuplelist structure.
tupleid Tuple ID to add.
Returns:
0 on success and -1 on error.

void tuplelist_free ( tuplelist dest  ) 

Frees a tuplelist structure.

Parameters:
dest Pointer to the structure to free.

tuplelist* tuplelist_new (  ) 

Allocate a new empty tuplelist structure.

Returns:
Pointer to the allocated structure or NULL on error.


Generated on Tue Jul 3 13:23:36 2007 for Tablix by  doxygen 1.5.2