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 (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.
|
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, |
|
|
T |
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.
METHOD: appendConstraint
- 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.
METHOD: dropConstraint
- 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.
METHOD: getDomain
- 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.
METHOD: getSize
- 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.
FUNCTION: hasUniqueSolution
- 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.
METHOD: isSatisfiable
- Returns:
- true if the CSP has at least a possible solution, false otherwise
template<class T >
void CSP< T >::refreshDomains |
( |
void |
|
) |
[inline] |
Updates the domains of the variables. Any constraint or node fixed value is applied.
METHOD: refreshDomains
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.
METHOD: setConstraint
- 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.
METHOD: setConstraint
- Parameters:
-
| c | Boolean function representing the constraint of the CSP |
template<class T >
void CSP< T >::setDomain |
( |
size_t |
index, |
|
|
T |
domain[], |
|
|
int |
size | |
|
) |
| | [inline] |
Set the domain for the i-th variable.
METHOD: setDomain
- 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.
METHOD: setDomain
- 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, |
|
|
T |
value | |
|
) |
| | [inline] |
Set the value of a variable as a constraint.
METHOD: setValue
- 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.
METHOD: unsetValue
- Parameters:
-
| index | Index of the variable to be unset |
The documentation for this class was generated from the following files: