CSP-Problem
Implementation of the CSP problem class, which is used to represent a constraint satisfaction problem (CSP) in the CSP-Fork library.
Defines types and operations for a CSPProblem.
- Author
Ch. Demko
- Date
2024
Typedefs
-
typedef struct _CSPProblem CSPProblem
The CSP problem.
Functions
-
CSPProblem *csp_problem_create(size_t num_domains, size_t num_constraints)
Create a CSP problem with the specified number of variables and constraints.
- Parameters:
num_domains – The number of variables of the CSP problem.
num_constraints – The number of constraints of the CSP problem.
- Returns:
The CSP problem created or NULL if an error occurred.
- Pre:
The csp library is initialised.
- Pre:
num_variables > 0
- Pre:
num_constraints > 0
- Post:
The CSP problem domains are initialised to 0.
- Post:
The CSP problem constraints are initialised to NULL.
- Post:
The CSP problem number of domains is set to the specified number of domains.
- Post:
The CSP problem number of constraints is set to the specified number of constraints.
-
void csp_problem_destroy(CSPProblem *csp)
Destroy the CSP problem.
- Parameters:
csp – The CSP problem to destroy.
- Pre:
The csp library is initialised.
- Post:
The CSP problem constraints are freed.
- Post:
The CSP problem domains is freed.
- Post:
The CSP problem is freed.
-
size_t csp_problem_get_num_constraints(const CSPProblem *csp)
Get the number of constraints of the CSP problem.
- Parameters:
csp – The CSP problem to get the number of constraints.
- Returns:
The number of constraints of the CSP problem.
- Pre:
The csp library is initialised.
-
CSPConstraint *csp_problem_get_constraint(const CSPProblem *csp, size_t index)
Get the constraint of the CSP problem at the specified index.
- Parameters:
csp – The CSP problem to get the constraint.
index – The index of the constraint.
- Returns:
The constraint at the specified index.
- Pre:
The csp library is initialised.
-
size_t csp_problem_get_num_domains(const CSPProblem *csp)
Get the number of domains of the CSP problem.
- Parameters:
csp – The CSP problem to get the number of domains.
- Returns:
The number of domains of the CSP problem.
- Pre:
The csp library is initialised.
-
size_t csp_problem_get_domain(const CSPProblem *csp, size_t index)
Get the domain of the CSP problem at the specified index.
- Parameters:
csp – The CSP problem to get the domain.
index – The index of the domain.
- Returns:
The domain at the specified index.
- Pre:
The csp library is initialised.
- Pre:
index < csp->num_domains
-
void csp_problem_set_constraint(CSPProblem *csp, size_t index, CSPConstraint *constraint)
Set the constraint of the CSP problem at the specified index.
- Parameters:
csp – The CSP problem to set the constraint.
index – The index of the constraint.
constraint – The constraint to set.
- Pre:
The csp library is initialised.
- Pre:
index < csp->num_constraints
- Pre:
constraint != NULL
-
void csp_problem_set_domain(CSPProblem *csp, size_t index, size_t domain)
Set the domain of the CSP problem at the specified index.
- Parameters:
csp – The CSP problem to set the domain.
index – The index of the domain.
domain – The domain to set.
- Pre:
The csp library is initialised.
- Pre:
index < csp->num_domains