class CspC

Constraint Satisfaction Problem

Inheritance:


Public Classes

struct ConstraintS
The storage for a constraint between two variables.

Public Fields

typedef ConstraintS* ConstraintT
The type for a constraint between two variables

Public Methods

void const AddConflict ( VariableT const iVariable1, VariableT const iVariable2, ValueT const iValue1, ValueT const iValue2 )
Adding conflicts
void const AddConstraint ( VariableT const iVariable1, VariableT const iVariable2 )
Adding constraints
CspC ( const CspC & iCsp )
Copy constructor
CspC ( NumberOfVariablesT const iNumberOfVariables )
Constructor
DomainSizeT const GetDomainSize ( VariableT const iVariable )
Getting the domainsize
int const GetNumberOfConflicts ( ValueT const iSolution [] )
Getting the number of conflicts
unsigned int const GetNumberOfConstraints ( )
Getting the number of constraints
NumberOfVariablesT const GetNumberOfVariables ()
Getting the number of variables
bool const IsConflict ( VariableT const iVariable1, VariableT const iVariable2, ValueT const iValue1, ValueT const iValue2 )
Testing conflicts
bool const IsConstraint ( VariableT const iVariable1, VariableT const iVariable2 )
Testing constraints
bool const IsDirty ()
Testing dirty
bool const IsValid ( ValueT const iSolution [] )
Checking for valid solutions
bool const LoadFromFile ( char const * iFilename )
Loading a CSP
CspC const& operator= ( const CspC & iCsp )
Operator =
virtual void ProduceFileName ( char * FileName )
Virtual member-function
virtual void const ProduceProblem ()
Virtual member-function
void const RemoveConflict ( VariableT const iVariable1, VariableT const iVariable2, ValueT const iValue1, ValueT const iValue2 )
Removing conflicts
void const RemoveConstraint ( VariableT const iVariable1, VariableT const iVariable2 )
Removing constraints
void const Reset ()
Resetting the CSP
bool const SaveToFile ( char const * const iFilename )
Saving a CSP
void const SetDomainSize ( VariableT const iVariable, DomainSizeT const iDomainSize )
Setting the domainsize
virtual ~CspC ()
Destructor

Public

struct ConstraintS
The storage for a constraint between two variables.

Protected Methods

ConstraintT const GetConstraint ( VariableT const iVariable1, VariableT const iVariable2 )
Getting constraints

Private Methods

void const Copy ( CspC const & iCsp )
Copying a CSP
void const Create ( NumberOfVariablesT const iNumberOfVariables )
Creating a CSP problem
void const Destroy ()
Destroying the CSP
bool const IsValidParameter ( VariableT const iVariable, ValueT const iValue )
Testing values
bool const IsValidParameter ( VariableT const iVariable )
Testing variables
void const Swap ( VariableT & iVariable1, VariableT & iVariable2 )
Swap function

Documentation

A base class for implementing Binary ConstrainS Satisfaction Problems.

struct ConstraintS
The storage for a constraint between two variables.

typedef ConstraintS* ConstraintT
The type for a constraint between two variables

CspC( NumberOfVariablesT const iNumberOfVariables )
Constructor, allocates memory for all the objects except for the conflicts. The conflicts will be allocated as needed when constraints are added to the CSP.

Returns:
nothing.
Parameters:
iNumberOfVariables - number of variables used in the CSP.
Author:
J.I. van Hemert
Version:
1.0

CspC( const CspC & iCsp )
Copy constructor for CspC. Takes an existing CSP as input and copies it to the new CSP, including all constraints and conflicts.

Returns:
nothing.
Parameters:
iCsp - existing object of CspC class.
Author:
J.I. van Hemert
Version:
1.0

CspC const& operator= ( const CspC & iCsp )
Destroys the left CSP and overwrites it with the right CSP. The left CSP will receive the constraints and conflicts of the right CSP.

Returns:
new CSP, copied from iCsp.
Parameters:
iCsp - existing CSP.
Author:
J.I. van Hemert
Version:
1.0

virtual ~CspC()
Destructor deallocates all memory used by the object.

Returns:
nothing.
Author:
J.I. van Hemert
Version:
1.0

NumberOfVariablesT const GetNumberOfVariables()
Get the number of variables present in the CSP.

Returns:
number of variables in CSP.
Author:
J.I. van Hemert
Version:
1.0

DomainSizeT const GetDomainSize( VariableT const iVariable )
Get the size of the domain of a variable.

Returns:
Size of the domain of the given variable.
Parameters:
iVariable - A number corresponding to a variable.
Author:
J.I. van Hemert
Version:
1.0

void const SetDomainSize( VariableT const iVariable, DomainSizeT const iDomainSize )
Set the size of the domain of a variable.

Returns:
nothing.
Parameters:
iVariable - A number corresponding to a variabe.
iDomainSize - size of the domain of iVariable.
Author:
J.I. van Hemert
Version:
1.0

bool const IsValid( ValueT const iSolution [] )
A way of checking if solutions for the CSP are valid. The input array with the size of the number of variables in the problem is checked as a solution for the CSP. If there are no conflicts true is returned.

Returns:
true if the offered solution does not offend a conflict, false otherwise.
Parameters:
iSolution - an array with values, where the first array index equals the first variable.
Author:
J.I. van Hemert
Version:
1.0

int const GetNumberOfConflicts( ValueT const iSolution [] )
A way of finding out how many conflicts a solution violates within the CSP. Given a array of size equal to the number of variables, check how many conflicts this solutions violates in the CSP.

Returns:
number of violated conflicts.
Parameters:
iSolution - an array with values, where the first array index equals the first variable.
Author:
J.I. van Hemert
Version:
1.0

unsigned int const GetNumberOfConstraints( )
Get the number of constraints currently in the CSP.

Returns:
number of constraints in CSP.
Author:
J.I. van Hemert
Version:
1.0

void const AddConstraint( VariableT const iVariable1, VariableT const iVariable2 )
Add a constraint between two variables.

Returns:
nothing.
Parameters:
iVariable1 - one of the two variables.
iVariable2 - another variable.
Author:
J.I. van Hemert
Version:
1.0

void const RemoveConstraint( VariableT const iVariable1, VariableT const iVariable2 )
Removes a constraint between two variables. Frees up memory from conflicts of the constraint.

Returns:
nothing.
Parameters:
iVariable1 - one of the two variables.
iVariable2 - another variable.
Author:
J.I. van Hemert
Version:
1.0

bool const IsConstraint( VariableT const iVariable1, VariableT const iVariable2 )
Check for the existence of a constraint between two variables.

Returns:
true when the constraint exists, else it returns false.
Parameters:
iVariable1 - one of the two variables.
iVariable2 - another variable.
Author:
J.I. van Hemert
Version:
1.0

void const AddConflict( VariableT const iVariable1, VariableT const iVariable2, ValueT const iValue1, ValueT const iValue2 )
Add a conflict between the values of two variables.

Returns:
nothing.
Parameters:
iVariable1 - one of the two variables.
iVariable2 - another variable.
iValue1 - value of first variable.
iValue2 - value of the second variable.
Author:
J.I. van Hemert
Version:
1.0

void const RemoveConflict( VariableT const iVariable1, VariableT const iVariable2, ValueT const iValue1, ValueT const iValue2 )
Remove a conflict between the values of two variables.

Returns:
nothing.
Parameters:
iVariable1 - one of the two variables.
iVariable2 - another variable.
iValue1 - value of first variable.
iValue2 - value of the second variable.
Author:
J.I. van Hemert
Version:
1.0

bool const IsConflict( VariableT const iVariable1, VariableT const iVariable2, ValueT const iValue1, ValueT const iValue2 )
Check for an existing conflict between the values of two variables.

Returns:
true for existing constraint with conflict between values, false for non-existing conflict or non-existing constraint.
Parameters:
iVariable1 - one of the two variables.
iVariable2 - another variable.
iValue1 - value of first variable.
iValue2 - value of the second variable.
Author:
J.I. van Hemert
Version:
1.0

bool const SaveToFile( char const * const iFilename )
Save the CSP to a file. The fileformat is simple, first the number of variables is saved, then on the next line all the domainsizes of the variables are saved with spaces between them. A blank line follows, after which the conflicts are saved.

Returns:
true for success, false for a failure.
Parameters:
iFilename - the filename of the file to save to.
Author:
J.I. van Hemert
Version:
1.0

bool const LoadFromFile( char const * iFilename )
Load the CSP from a file.

Returns:
true for success, false for a failure.
Parameters:
iFilename - the filename of the file to load from.
Author:
J.I. van Hemert
Version:
1.0

bool const IsDirty()
Check if a CSP file has been touched.

Returns:
false if it is still empty, true if it has been touched.
Author:
J.I. van Hemert
Version:
1.0

void const Reset()
Removes all constraints, conflicts and domainsizes from the CSP, freeing memory for the conflicts, but without freeing memory for the constraints. The CSP can be reused for a new CSP, because the number of variables is not cleared.

Returns:
nothing.
Author:
J.I. van Hemert
Version:
1.0

virtual void const ProduceProblem()
This pure virtual function has to be implemented by the class that is inherits from this class. It should produce a Constraint Satisfaction Problem according to some specific algorithm.

Returns:
nothing.

virtual void ProduceFileName( char * FileName )
This pure virtual function has to be implemented by the class that is inherits from this class. It should produce a filename that is unique for the parameters of problem made by the class it belongs to.

Returns:
nothing.

ConstraintT const GetConstraint( VariableT const iVariable1, VariableT const iVariable2 )
Gets a constraint between two variables. Still not sure if we want this to be public or protected.

Returns:
a constraint.
Parameters:
iVariable1 - one of the two variables.
iVariable2 - another variable.
Author:
J.I. van Hemert
Version:
1.0
See Also:
the structure of a constraint in ConstraintS.

bool const IsValidParameter( VariableT const iVariable )
Check for the existence of a variable.

Returns:
true for existence, false for non-existence.
Parameters:
iVariable - the variable to check.
Author:
J.I. van Hemert
Version:
1.0

bool const IsValidParameter( VariableT const iVariable, ValueT const iValue )
Check for the existence of a variable and if its value lies in its domain.

Returns:
true for existence and valid value, false for non-existence or non-valid value.
Parameters:
iVariable - the variable to check.
iValue - value of the variable.
Author:
J.I. van Hemert
Version:
1.0

void const Create( NumberOfVariablesT const iNumberOfVariables )
Creates memory needed for holding the CSPs problem. initialises the CSP by allocating enough memory to hold all the constraints. No memory is allocated for the conflicts yet.

Returns:
nothing.
Parameters:
iNumberOfVariables - number of variables used in the CSP.
Author:
J.I. van Hemert
Version:
1.0

void const Destroy()
Deallocates memory from the CSP problem. Used in constructors and destructors.

Returns:
nothing.
Author:
J.I. van Hemert
Version:
1.0

void const Copy( CspC const & iCsp )
Copies an existing CSP to this one by calling Create and copying all the constraints and conflicts.

Returns:
nothing.
Parameters:
iCsp - existing CSP.
Author:
J.I. van Hemert @version 1.0

void const Swap( VariableT & iVariable1, VariableT & iVariable2 )
Swap the two parameters.

Returns:
nothing.
Parameters:
iVariable1 - First parameter.
iVariable2 - Second parameter.
Author:
J.I. van Hemert
Version:
1.0


Direct child classes:
RandomCspC

alphabetic index hierarchy of classes


this page has been generated automatically by doc++

(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de