Main class for managing a CSP. More...
#include <csp++.h>
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. | |
T | 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. |
Main class for managing a CSP.
CSP< T >::CSP | ( | int | n, | |
bool(*)(std::vector< CSPvariable< T > >) | c = __default_constraint | |||
) |
Class constructor.
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) |
CSP< T >::CSP | ( | int | n, | |
T | default_value, | |||
bool | set_variables = false , |
|||
bool(*)(std::vector< CSPvariable< T > >) | c = __default_constraint | |||
) | [inline] |
Class constructor.
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) |
void CSP< T >::appendConstraint | ( | bool(*)(std::vector< CSPvariable< T > >) | c | ) |
Append a constraint to the list of the constraint of the CSP.
c | A function pointer returning a boolean value representing the new constraint |
void CSP< T >::dropConstraint | ( | size_t | index | ) | [inline] |
Drops a constraint from the CSP.
index | Index of the constraint to be dropped |
std::vector< T > CSP< T >::getDomain | ( | size_t | index | ) | [inline] |
Get the domain of the i-th variable.
index | Variable for which we're going to get the domain |
size_t CSP< T >::getSize | ( | void | ) | [inline] |
bool CSP< T >::hasUniqueSolution | ( | void | ) | [inline] |
bool CSP< T >::isSatisfiable | ( | void | ) | [inline] |
bool CSP< T >::isSet | ( | size_t | i | ) | [inline] |
Check if the i-th variable in the CSP has a fixed value.
i | Index of the variable to be checked |
void CSP< T >::setConstraint | ( | std::vector< bool(*)(std::vector< CSPvariable< T > >) > | c | ) | [inline] |
void CSP< T >::setConstraint | ( | bool(*)(std::vector< CSPvariable< T > >) | c | ) |
void CSP< T >::setDomain | ( | size_t | index, | |
T | domain[], | |||
int | size | |||
) | [inline] |
Set the domain for the i-th variable.
index | Variable for which we're setting the domain | |
domain | Array containing the possible values for that variable | |
size | Size of "domain" array |
void CSP< T >::setDomain | ( | size_t | index, | |
std::vector< T > | domain | |||
) |
Set the domain for the i-th variable.
index | Variable for which we're setting the domain | |
domain | Vector containing the possible values for that variable |
void CSP< T >::setValue | ( | size_t | index, | |
T | value | |||
) | [inline] |
Set the value of a variable as a constraint.
index | Index of the parameter to be set | |
value | Value to be set |
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.
index | Index of the variable to be unset |
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.
i | Index of the variable to get |