CSP< T > Class Template Reference

Main class for managing a CSP. More...

#include <csp++.h>

List of all members.

Classes

struct  arc

Public Member Functions

 CSP ()
 Empty constructor - just do nothing, used for declaring an object and initialize it later.
 CSP (int n, bool(*c)(std::vector< CSPvariable< T > >)=__default_constraint)
 Class constructor.
 CSP (int n, T default_value, bool set_variables=false, bool(*c)(std::vector< CSPvariable< T > >)=__default_constraint)
 Class constructor.
void setDomain (size_t index, std::vector< T > domain)
 Set the domain for the i-th variable.
void setDomain (size_t index, T domain[], int size)
 Set the domain for the i-th variable.
void setConstraint (bool(*c)(std::vector< CSPvariable< T > >))
 Apply the constraint to the CSP as a boolean function.
void setConstraint (std::vector< bool(*)(std::vector< CSPvariable< T > >) > c)
 Apply the constraints to the CSP as vector of boolean functions.
void dropConstraint (size_t index)
 Drops a constraint from the CSP.
void appendConstraint (bool(*c)(std::vector< CSPvariable< T > >))
 Append a constraint to the list of the constraint of the CSP.
void refreshDomains (void)
 Updates the domains of the variables. Any constraint or node fixed value is applied.
std::vector< T > getDomain (size_t index)
 Get the domain of the i-th variable.
size_t getSize (void)
 Get the number of variables in the current CSP.
void setValue (size_t index, T value)
 Set the value of a variable as a constraint.
void unsetValue (size_t index)
 Marks a variable as not set, and if a default value was assigned in the CSP constructor, this value will be set. By default, unless specified in the constructor, all the variables are considered as not set.
bool isSatisfiable (void)
 Check if the current CSP, with the applied constraints, is satisfiable.
bool hasUniqueSolution (void)
 Check if the CSP, with the given variables, domains and constraints, admits a unique solution, i.e. each domain of each variable contains an only element.
void assignUniqueDomains (void)
 Check if any of the variables in the CSP has a domain containing an only item. If so, it automatically assignes that item as value of the variable.
bool isSet (size_t i)
 Check if the i-th variable in the CSP has a fixed value.
value (size_t i)
 Get the value of the i-th variable of the CSP. Be careful: before using this function you should check whether the variable you're going to check is actually set, using the isSet() method, unless you know what you're doing, in order to avoid reading inconsistent data.

Detailed Description

template<class T>
class CSP< T >

Main class for managing a CSP.


Constructor & Destructor Documentation

template<class T >
CSP< T >::CSP ( int  n,
bool(*)(std::vector< CSPvariable< T > >)  c = __default_constraint 
)

Class constructor.

Parameters:
n Number of variables in the CSP
c Boolean function representing the constraint of the CSP If no constraint function is set in the constructor or using the applyConstraint() method, a default function always returning true will be used, that allows any domain for any variable to be valid (no constraint)
template<class T >
CSP< T >::CSP ( int  n,
default_value,
bool  set_variables = false,
bool(*)(std::vector< CSPvariable< T > >)  c = __default_constraint 
) [inline]

Class constructor.

Parameters:
n Number of variables in the CSP
default_value Default value for the variables in the CSP when initialized
set_variables Decide whether mark the variables set with default_value as "set" or "not set" (default: not set)
c Boolean function representing the constraint of the CSP If no constraint function is set in the constructor or using the applyConstraint() method, a default function always returning true will be used, that allows any domain for any variable to be valid (no constraint)

Member Function Documentation

template<class T >
void CSP< T >::appendConstraint ( bool(*)(std::vector< CSPvariable< T > >)  c  ) 

Append a constraint to the list of the constraint of the CSP.

Parameters:
c A function pointer returning a boolean value representing the new constraint
template<class T >
void CSP< T >::dropConstraint ( size_t  index  )  [inline]

Drops a constraint from the CSP.

Parameters:
index Index of the constraint to be dropped
template<class T >
std::vector< T > CSP< T >::getDomain ( size_t  index  )  [inline]

Get the domain of the i-th variable.

Parameters:
index Variable for which we're going to get the domain
Returns:
The domain of the i-th variable as a vector of T
template<class T >
size_t CSP< T >::getSize ( void   )  [inline]

Get the number of variables in the current CSP.

Returns:
Size of the CSP
template<class T >
bool CSP< T >::hasUniqueSolution ( void   )  [inline]

Check if the CSP, with the given variables, domains and constraints, admits a unique solution, i.e. each domain of each variable contains an only element.

Returns:
true if the CSP has an only possible solution, false otherwise
template<class T >
bool CSP< T >::isSatisfiable ( void   )  [inline]

Check if the current CSP, with the applied constraints, is satisfiable.

Returns:
true if the CSP has at least a possible solution, false otherwise
template<class T >
bool CSP< T >::isSet ( size_t  i  )  [inline]

Check if the i-th variable in the CSP has a fixed value.

Parameters:
i Index of the variable to be checked
Returns:
true if the i-th variable has a fixed value, false otherwise
template<class T >
void CSP< T >::setConstraint ( std::vector< bool(*)(std::vector< CSPvariable< T > >) >  c  )  [inline]

Apply the constraints to the CSP as vector of boolean functions.

Parameters:
c Vector containing pointers to boolean functions representing the constraints of the CSP
template<class T >
void CSP< T >::setConstraint ( bool(*)(std::vector< CSPvariable< T > >)  c  ) 

Apply the constraint to the CSP as a boolean function.

Parameters:
c Boolean function representing the constraint of the CSP
template<class T >
void CSP< T >::setDomain ( size_t  index,
domain[],
int  size 
) [inline]

Set the domain for the i-th variable.

Parameters:
index Variable for which we're setting the domain
domain Array containing the possible values for that variable
size Size of "domain" array
template<class T >
void CSP< T >::setDomain ( size_t  index,
std::vector< T >  domain 
)

Set the domain for the i-th variable.

Parameters:
index Variable for which we're setting the domain
domain Vector containing the possible values for that variable
template<class T >
void CSP< T >::setValue ( size_t  index,
value 
) [inline]

Set the value of a variable as a constraint.

Parameters:
index Index of the parameter to be set
value Value to be set
template<class T >
void CSP< T >::unsetValue ( size_t  index  )  [inline]

Marks a variable as not set, and if a default value was assigned in the CSP constructor, this value will be set. By default, unless specified in the constructor, all the variables are considered as not set.

Parameters:
index Index of the variable to be unset
template<class T >
T CSP< T >::value ( size_t  i  )  [inline]

Get the value of the i-th variable of the CSP. Be careful: before using this function you should check whether the variable you're going to check is actually set, using the isSet() method, unless you know what you're doing, in order to avoid reading inconsistent data.

Parameters:
i Index of the variable to get
Returns:
The value of the variable, if the variable exists

The documentation for this class was generated from the following files:
 All Classes Functions Variables
Generated on Mon May 24 01:58:02 2010 for libCSP++ by  doxygen 1.6.3