0% found this document useful (0 votes)
51 views

A Note On Constraint Programming (CP)

Constraint programming (CP) is a technique for solving problems modeled as constraints or limiting conditions on a set of decision variables. CP focuses on finding feasible solutions rather than optimal solutions and allows modeling problems as constraints. CP is well-suited for problems like scheduling and sequencing that have large search spaces and complex constraints. In CP, users declare constraints and the solver propagates constraints to reduce the search space through domain reductions until a solution is found.

Uploaded by

Lohitava Ghosh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

A Note On Constraint Programming (CP)

Constraint programming (CP) is a technique for solving problems modeled as constraints or limiting conditions on a set of decision variables. CP focuses on finding feasible solutions rather than optimal solutions and allows modeling problems as constraints. CP is well-suited for problems like scheduling and sequencing that have large search spaces and complex constraints. In CP, users declare constraints and the solver propagates constraints to reduce the search space through domain reductions until a solution is found.

Uploaded by

Lohitava Ghosh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

A Note on Constraint Programming (CP)

Modeling Languages

Mathematical Constraint Programming


Programming (PM) (CP)

e.g., Job-shop scheduling


e.g., Linear, Integer, Non- problems, Time tabling,
Linear, etc. Sequencing problems,
etc.

What is Constraint Programming (CP)?


Constraint programming (CP) is the name given to identifying feasible solutions out of a very
large set of alternatives, where the problem can be modeled in terms of arbitrary constraints.
CP is based on feasibility (finding a feasible solution) rather than optimization (finding an
optimal solution) and focuses on the constraints and variables rather than the objective
function. In fact, a CP problem may not even have an objective function — the goal may simply
be to narrow down a very large set of possible solutions to a more manageable subset by adding
constraints to the problem.
In constraint programming, users declaratively state the constraints on the feasible solutions
for a set of decision variables. Constraints differ from the common primitives of imperative
programming languages in that they do not specify a step or sequence of steps to execute, but
rather the properties of a solution to be found. Examples: scheduling problems, sequencing
problems, planning, time tabling, allocation or rostering problems, etc.

For example: A company runs three 8-hour shifts per day and assigns three of its four
employees to different shifts each day, while giving the fourth the day off. The number of

1
possible schedules is: each day, there are 4! = 4 * 3 * 2 * 1 = 24 possible employee assignments,
so the number of possible weekly schedules is 24# , which is over 4.5 billion. Usually there will
be other constraints that reduce the number of feasible solutions — for example, that each
employee works at least a minimum number of days per week. The CP method keeps track of
which solutions remain feasible when you add new constraints, which makes it a powerful tool
for solving large, real-world scheduling problems.

Reasons for using CP:-


• Constraints are non-linear
• Non-convex solution space with many locally optimal solutions
• Irregularities in MP that make the problem difficult to solve
• Multiple disfunctions, resulting in poor information returned by linear
relaxation of problems
Characteristics of CP:-
• Uses only discrete variables in a defined domain
• Product of all domains sizes make up the search space
• Specific constraints, expressions, parameterizable propagation and search
• Supports logical constraints
• Supports non-linear costs. e.g., quadratic assignment problem
• Supports constraint on and between interval variables
• Supports compatibility and incompatibility constraints. e.g., Knight problem

Using CP in opl model:


• Declaration: using CP;

• It is possible to constrain floating point expressions to use them as an objective term.


Also possible to declare floating-point expressions with dexpr keyword.
• Domains are defined for D.V.s
• Specific arithmetic, logical, temporal, specialized constraints and expressions are
supported in CP optimizer engine for CP combinatorial and scheduling problems
• You can set parameters for propagation control, log control, search control, etc.
• Constraint Propagation: constraints in CP are propagated at execution time by the
solver, i.e., communicating domain reduction of a D.V. to all of the constraints that are

2
stated over this variable. This results in more domain reduction. These domain
reductions are communicated to appropriate constraints. The process continues until no
more various domains can be reduced or until empty solution is reached.
• CP Search: CP searching generates combinations of values for D.V.s by means of
constructive strategies. These strategies are executed and guided towards optimal
solutions in order to converge rapidly.

CP vs MP:

CP MP

D.V.s are discrete (integer or boolean) Both discrete and continuous

Supports logical constraints (&&, ||, !=, ==), Supports only linear constraints, linearized
modulo, integer division, element logical constraints, quadratic convex
expression constraints

Theoretical ground: Graph theory, logical Theoretical ground: numerical linear


programming, algorithmic algebra

Problem. (Map coloring problem) The problem involves choosing colors for the countries on
a map so that at most four colors are used (e.g, blue, white, yellow, green), and no neighboring
countries are the same color. The object is to find a solution for a map coloring problem with
six countries: Belgium, Denmark, France, Germany, Luxembourg, and the Netherlands. Use
CP Optimizer on CPLEX to solve this problem.

3
#Holland and Netherlands are same country. # The colors shown in the map are just for better
visualization. It has nothing to do with the colors used in the given problem.

From the political map of Europe, we have the following information regarding neighbours:

• Belgium: France, Germany, Luxembourg, Netherlands

• Denmark: Germany

• France: Belgium, Germany, Luxembourg

• Germany: Belgium, Denmark, France, Netherlands, Luxembourg

• Luxembourg: Belgium, France, Germany

• Netherlands: Belgium, Germany

4
Solution.
using CP;

range r = 0..3;

string Names[r] = ["blue", "white", "yellow", "green"];

dvar int Belgium in r;


dvar int Denmark in r;
dvar int France in r;
dvar int Germany in r;
dvar int Luxembourg in r;
dvar int Netherlands in r;

subject to {
Belgium != France;
Belgium != Germany;
Belgium != Netherlands;
Belgium != Luxembourg;
Denmark != Germany;
France != Germany;
France != Luxembourg;
Germany != Luxembourg;
Germany != Netherlands;
}

execute {
writeln("Belgium: ", Names[Belgium]);
writeln("Denmark: ", Names[Denmark]);
writeln("France: ", Names[France]);
writeln("Germany: ", Names[Germany]);
writeln("Luxembourg: ", Names[Luxembourg]);
writeln("Netherlands: ", Names[Netherlands]);
}

tuple resultT {
string name;
string value;
};
{resultT} solution = {};
execute{
solution.add("Belgium", Names[Belgium]);
solution.add("Denmark", Names[Denmark]);
solution.add("France", Names[France]);
solution.add("Germany", Names[Germany]);
solution.add("Luxembourg", Names[Luxembourg]);
solution.add("Netherlands", Names[Netherlands]);
writeln(solution);
}

You might also like