CSP-Constraint
Implementation of the CSP constraint class, which is used to represent a constraint in the CSP-Fork library.
Defines types and operations for a CSPConstraint.
- Author
Ch. Demko
- Date
2024
Typedefs
-
typedef struct _CSPConstraint CSPConstraint
The constraint of a CSP problem.
-
typedef bool CSPChecker(const CSPConstraint*, const size_t*, const void*)
The check function of a CSP constraint.
- Param constraint:
The constraint to check.
- Param values:
The values of the variables.
- Param data:
The data to pass to the check function.
- Return:
true if the constraint is satisfied, false otherwise.
- Pre:
constraint != NULL
- Pre:
values != NULL
Functions
-
CSPConstraint *csp_constraint_create(size_t arity, CSPChecker *check)
Create a constraint with the specified arity and check function.
- Parameters:
arity – The arity of the constraint.
check – The check function of the constraint.
- Returns:
The constraint created or NULL if an error occurred.
- Pre:
The csp library is initialised.
- Pre:
arity > 0
- Pre:
check != NULL
- Post:
The constraint variables are initialised to 0.
- Post:
The constraint arity is set to the specified arity.
- Post:
The constraint check function is set to the specified check function.
-
void csp_constraint_destroy(CSPConstraint *constraint)
Destroy the constraint.
- Parameters:
constraint – The constraint to destroy.
- Pre:
The csp library is initialised.
- Pre:
constraint != NULL
- Post:
The constraint variables are freed.
- Post:
The constraint is freed.
-
size_t csp_constraint_get_arity(const CSPConstraint *constraint)
Get the arity of the constraint.
- Parameters:
constraint – The constraint to get the arity.
- Returns:
The arity of the constraint.
- Pre:
The csp library is initialised.
-
CSPChecker *csp_constraint_get_check(const CSPConstraint *constraint)
Get the check function of the constraint.
- Parameters:
constraint – The constraint to get the check function.
- Returns:
The check function of the constraint.
- Pre:
The csp library is initialised.
-
size_t csp_constraint_get_variable(const CSPConstraint *constraint, size_t index)
Get the variable of the constraint at the specified index.
- Parameters:
constraint – The constraint to get the variable.
index – The index of the variable.
- Returns:
The variable at the specified index.
- Pre:
The csp library is initialised.
- Pre:
index < constraint->arity
-
void csp_constraint_set_variable(CSPConstraint *constraint, size_t index, size_t variable)
Set the variable of the constraint at the specified index.
- Parameters:
constraint – The constraint to set the variable.
index – The index of the variable.
variable – The variable to set.
- Pre:
The csp library is initialised.
- Pre:
index < constraint->arity