I am given the following requirements which need to be formulated into a CSP problem by defining a set of variables, and a set of constraints over those variables. However I'm having trouble formulating the constraints and variables for my problem.
Some info: The solution to the problem is a list of assignments: [Var, A1, A2, A3] where Var is the variable and A1, A2, A3 is an ordered sequence of valid assignments.
Requirements:
- Each variable is assigned a value in
problem.valid_assignments() - Each variable's first assignment is in
problem.first_assignments() - Each variable's assignment sequence is in
problem.valid_pairs()(Some assignments can't follow others) - Given an integer
K, there can be no more thanKcontinuous assignments where at least one is not in problem.k_assignment() - Every value in the given assignments list:
problem.assignmentmust be used.
Available Constraints:
NValuesconstraint: Given a list ofrequired_values, an upper bound and lower bound, makes sure that the number of variables whose value is inrequired_valuesis between the bounds.AllDifferentconstraint: Given a set of variables, enforces their inequality. That is no two variables in the set are equal.NotEqualconstraints: GivenVar1,Var2, enforces:Var1!=Var2
So Far:
- A Variable for each
Varwhose domain isproblem.valid_assignments() - A Variable for each
Varwhose domain isproblem.first_assignments() - A
NValuesconstraint for eachVarwhose scope is[Var], required valuesproblem.valid_assignments(Var), lower bound0, upper boundlen(domain).
Additional info:
-
The solution is a "list of assignments" as in for each
Varwe return[Var, A1, A2, A3]whereVaris the variable assigned andA1throughA3are valid assignments that fulfil the given constraints. The exact format doesn't matter as I'm only looking for a conceptual solution. AdditionallyA1, A2, A3(aka all assignments for aVar) must obviously be in the domain of that variable. (Domains can overlap between variables). -
valid_pairs()returns a list of tuples[(A1, A2), (A2,A3)]. The constraint is such that the returned solution list (as detailed above) must have consecutive assignments that form valid pairs that are given by this function. For example if the solution is[Var, A1, A2, A4, A3]and the valid pairs are[(A1, A2), (A2,A3)]then the solution is incorrect as(A2, A4) (A4, A3)is not in the list ((A1, A2)however is a valid pair). -
Essentially we're looking for arc-consistency.
from Constraint Satisfaction Problem formulation
No comments:
Post a Comment