depend.c File Reference

Support for updater functions for dependent events. More...

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "error.h"
#include "data.h"
#include "depend.h"
#include "gettext.h"
#include "assert.h"

Functions

static int * updater_evaluate (updaterfunc *updater)
 Evaluates an updater function and returns an array of all output values.
static int updater_get_valid_inputs (updaterfunc *updater, int **list)
 Calculates the list of valid input values for an updater.
int updater_fix_domains ()
 Fixes resource domains when updater functions are used.
static int updater_dependent (updaterfunc *updater)
 Checks if the source event of the updater function itself depends on another event or not.
static void updater_movetoend (updaterfunc **list, updaterfunc *updater)
 Moves an updaterfunc structure to the end of a linked list.
int updater_reorder ()
 Reorders dep_updaterlist linked list.
int updater_check (int dst, int typeid)
 Checks if an updater function has been registered that has dst as a destination event.
updaterfuncupdater_new (int src, int dst, int typeid, updater_f func)
 Register a new updater function.
int updater_call (updaterfunc *updater, int resid)
 Calls an updater function.
void updater_call_all (table *tab)
 Calls all registered updater functions.

Variables

static updaterfuncdep_updaterlist = NULL
 Linked list of all updater functions for dependent events.


Detailed Description

Support for updater functions for dependent events.


Function Documentation

int updater_call ( updaterfunc updater,
int  resid 
)

Calls an updater function.

Parameters:
updater Pointer to the updater function to be called.
resid Resource ID of the resource of the correct type that is assigned to the source tuple of the updater function.
Returns:
Resource ID that should be assigned to the destination tuple.

void updater_call_all ( table tab  ) 

Calls all registered updater functions.

Functions are called in the order of the linked list. updater_reorder() must be called before the first call to updater_call_all() to properly reorder the linked list.

Parameters:
tab Pointer to the timetable structure.

int updater_check ( int  dst,
int  typeid 
)

Checks if an updater function has been registered that has dst as a destination event.

If no such updater function has been registered, this means that it is safe to register a new updater function with dst as a destination event.

Parameters:
dst Tuple ID of the event to check.
typeid Resource type ID to check.
Returns:
0 if no such updater function has been registered or -1 otherwise.

static int updater_dependent ( updaterfunc updater  )  [static]

Checks if the source event of the updater function itself depends on another event or not.

Helper function for updater_reorder().

This function walks the dat_updatelist linked list and searches for an updater function that has a destination event equal to the source event of the updater function in the argument.

Parameters:
updater Pointer to the updaterfunc structure to be checked.
Returns:
0 if the source event is independent or -1 if it is dependent.

static int* updater_evaluate ( updaterfunc updater  )  [static]

Evaluates an updater function and returns an array of all output values.

if range[] is the array returned by updater_evaluate() function, then range[x] is the value returned by the updater function for input x.

Parameters:
updater Pointer to the updater function to be evaluated
Returns:
Array of function outputs or NULL on error. Array must be freed with free() after use.

int updater_fix_domains (  ) 

Fixes resource domains when updater functions are used.

If no updater functions are used this function has no effect.

If updater functions are used in a problem description, the source tuples of updater functions must have their resource domains checked if any value in them causes the updater function to set a resource in the destination tuple outside its domain.

This function changes the resource domains of tuples so that this can not happen.

This function must be called after updater_reorder() and before data_init().

Returns:
0 on success and -1 if there was a memory allocation error.

static int updater_get_valid_inputs ( updaterfunc updater,
int **  list 
) [static]

Calculates the list of valid input values for an updater.

Updater function may for some inputs return values that are not in the resource domain of the destination tuple. This function call the updater function for all values in the resource domain of the source tuple and checks them against the domain of the destination tuple.

Those inputs that are not forbidden by the destination resource domain are added to the list of valid inputs.

See also:
updater_fix_domains()
Parameters:
updater Pointer to the updater function to be checked.
list This pointer will be set to an array of valid input values for this updater function. Sufficient memory is allocated for this array automatically and it must be freed after use.
Returns:
Number of values in the list array or INT_MIN if memory allocation failed.

static void updater_movetoend ( updaterfunc **  list,
updaterfunc updater 
) [static]

Moves an updaterfunc structure to the end of a linked list.

Helper function for updater_reorder().

Parameters:
list Pointer to a linked list of updaterfunc structures.
updater Pointer to the updaterfunc structure to be moved to the end of the list.

updaterfunc* updater_new ( int  src,
int  dst,
int  typeid,
updater_f  func 
)

Register a new updater function.

It is recommended that updater_check() is called before calling this function to verify if there isn't another updater function registered for this dependent event.

Parameters:
src Tuple ID of the independent event.
dst Tuple ID of the dependent event.
typeid Resource type ID this updater function changes.
func Pointer to the updater function.
Returns:
Pointer to the updaterfunc structure or NULL on error.

int updater_reorder (  ) 

Reorders dep_updaterlist linked list.

A source (independent) event for an updater function can infact be a destination (dependent) event of another updater function. This means that updater functions must be called in the correct order.

Example: Function A has a source event 2 and destination event 3. Function B has a source event 1 and destination event 2. In this case updater_reorder() puts function B in front of A.

Returns:
0 on success or -1 on error (there was a circular dependency and the correct order of calling can not be determined.


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