+ All Categories
Home > Documents > G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint...

G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint...

Date post: 24-Mar-2020
Category:
Upload: others
View: 12 times
Download: 0 times
Share this document with a friend
43
G53CLP Constraint Logic Programming Constraint Optimisation Problems Dr Rong Qu
Transcript
Page 1: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

G53CLPConstraint Logic Programming

Constraint Optimisation Problems

Dr Rong Qu

Page 2: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Constraint Satisfaction Problems

So far All solutions are equally good

In some real world applications, we Not only want feasible solutions, but also good

solutions

We have different preferences on constraints

Problems are too constrained that there is no solution satisfying all constraints

G53CLP – Constraint Logic Programming Dr R. Qu

Page 3: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Constraint Optimisation Problems

Real world problems present to be messy

In some cases a conflict-free solution is needed All constraints must be satisfied

In some cases preferences are given, rather than constraints Hard and soft constraints

In some cases, some constraints are more important than others Constraints with different weights (importance)

G53CLP – Constraint Logic Programming Dr R. Qu

Page 4: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Constraint Optimisation Problems

What are good solutions? Objective function

Problem specific function How much are constraints satisfied

Relatively new research Scheduling Timetabling Resource allocations etc

G53CLP – Constraint Logic Programming Dr R. Qu

Page 5: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Constraint Optimisation Problems

Find feasible solutions with the best value of the objective function

COP (C,f) Constraint Satisfaction Problem (C)

+

Objective function (f)(maps every solution to a numeric value)

G53CLP – Constraint Logic Programming Dr R. Qu

Page 6: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Constraint Optimisation Problems

A solution θ is preferred to solution θ’ If the value of objective function f under θ is less

(or larger in maximisation problem) than θ’

An optimal solution of COP (C,f) A solution θ* of C, such that no other solution of C

is preferred to θ*.

G53CLP – Constraint Logic Programming Dr R. Qu

Page 7: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

G53CLP – Constraint Logic Programming Dr R. Qu

COP - examples

Graph colouring

C: different colour for adjacent vertices

f: Minimum number of colours used

Linear expression

C: constraints for variables in the expression

f: Minimise the result of linear expressions

Page 8: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

G53CLP – Constraint Logic Programming

COP - examples

TSP with time windows

C Each city visited only once

Each city visited within a certain time window

f: shortest route

COP for TSP*

Constraint propagation to remove values of variable which lead to no better solution

*G. Pesant, M. Gendreau , J.Y. Potvin, J.M. Rousseau. An Exact Constraint Logic Programming Algorithm for the TravelingSalesman Problem with Time Windows. Transportation Science 32(1): 12 - 29, 1998*F. Focacci, A. Lodi, M. Milano, "A hybrid exact algorithm for the TSPTW", INFORMS Journal on Computing 14, 403-417, 2002

Page 9: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Branch and Bound (B&B)

General method for optimisation problems Systematically enumerate all candidate solutions Large subsets of fruitless candidates are discarded Use upper and lower estimated bounds of the

quantity being optimized

In COP most widely used CPLEX in ILOG Solver …

G53CLP – Constraint Logic Programming Dr R. Qu

Page 10: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Branch and Bound (B&B)

Based on depth first search Branches pruned during the search by a bound

Keep the best solution so far

During the search if partial solutions (nodes) are proved cannot improve the result Prune the branch under the node

All solutions in branches under the node are abandoned

G53CLP – Constraint Logic Programming Dr R. Qu

Page 11: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Branch and Bound (B&B)

Bestsolution

X

X

Bestsolution

No optimal solutionbelow these branches

G53CLP – Constraint Logic Programming Dr R. Qu

Page 12: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

B & B

Two important factors

A heuristic function, h

Estimated objective values for compound labels of partial solutions

A bound, b

Used to prune branches with no optimal solutions

Updated during the search

G53CLP – Constraint Logic Programming Dr R. Qu

Page 13: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

B & B

During the search in the search tree

Before labelling a variable, a value of the heuristic function is calculated

If the heuristic value is greater than* the bound The whole sub-tree under the node is pruned

If the heuristic value of a solution is less than the existing bound Update the bound Store the newly found solution

* For a minimisation problem

G53CLP – Constraint Logic Programming Dr R. Qu

Page 14: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

B & B – heuristic

Heuristic h

Function maps a partial solution to an estimate of the objective function value

Good estimate of the best values of all branches under the current node

If the best value under the branch is worse than the current bound, then there is no need to explore these branches

Problem specific

G53CLP – Constraint Logic Programming Dr R. Qu

Page 15: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

B & B – heuristic

Use heuristic to prune the search tree There is no solution in the sub-tree (under the

node)

All solutions in the sub-tree are not optimal

So that Solutions can be found earlier

The search space is reduced

Speed up the search

G53CLP – Constraint Logic Programming Dr R. Qu

Page 16: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

B & B – heuristic

A good heuristic h is the key to successful B&B

1. Must underestimate* Admissible Return the lower bound of the heuristic value Otherwise the optimal solution may be

pruned h’ is the actual cost, h <= h’

2. Good heuristics

* For a minimisation problem

G53CLP – Constraint Logic Programming Dr R. Qu

Page 17: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

B & B – heuristic

A good heuristic h is the key to successful B&B

1. Must underestimate

2. Good heuristics The closer the estimation of heuristic, the

larger the part of search tree pruned h’ is the actual cost, the closer h is to h’ the

better

G53CLP – Constraint Logic Programming Dr R. Qu

Page 18: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

B & B – bound

Usually set as infinite value* at the beginning

Updated during the search by recording the best so far heuristic value

* For a minimisation problem

infinite positive*

G53CLP – Constraint Logic Programming Dr R. Qu

Page 19: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

B & B – bound

Better bound, b Helps to find good solutions earlier

In practice, user can provide a bound

Satisfied even the solution is not optimal

v

G53CLP – Constraint Logic Programming Dr R. Qu

Page 20: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

SEND MORE MONEY - Problem

S E N D

+ M O R E

= M O N E Y

Cryptarithmetic problem: mathematical puzzles where digits are replaced by symbols

Find unique digits the letters represent, satisfying the above constraints

G53CLP – Constraint Logic Programming Dr R. Qu

Page 21: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

SEND MORE MONEY - Model

Variables

S, E, N, D, M, O, R, Y

Domain

{0, …, 9}

G53CLP – Constraint Logic Programming Dr R. Qu

Page 22: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

SEND MORE MONEY - Model

Constraints

Distinct variables, S ≠ E, M ≠ S, …

S*1000 + E*100 + N*10 + D

+

M*1000 + O*100 + R*10 + E

=

M*10000 + O*1000 + N*100 + E*10 + Y

G53CLP – Constraint Logic Programming Dr R. Qu

Page 23: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

SEND MORE MONEY – How?

How would you solve the problem using CP techniques? Search tree with backtracking

Constraint propagation

Forward & backward checking

Combination of above?

Different problems may find different techniques more appropriate

G53CLP – Constraint Logic Programming Dr R. Qu

Page 24: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

SEND MORE MONEY - Solution

9 5 6 7

+ 1 0 8 5

= 1 0 6 5 2

Is this the only solution?

Sometimes we want to maximise an objective

S E N D

+ M O R E

= M O N E Y

G53CLP – Constraint Logic Programming Dr R. Qu

Page 25: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

SEND MOST MONEY - Problem

S E N D

+ M O S T

= M O N E Y

Objective: we now want to maximise MONEY

G53CLP – Constraint Logic Programming Dr R. Qu

Page 26: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

SEND MOST MONEY - Problem

Modelling

What does “best” mean

How to find best solution

Search

Assign scores for proposed solution, h

Update the bound, b

G53CLP – Constraint Logic Programming Dr R. Qu

Page 27: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

COP – real world examples

Resource allocation Nurse rostering systems in hospitals BT services

Timetabling University course/exam scheduling systems

Transportation Flight scheduling (ECLiPSe) and Aircraft allocation (ILOG) at

BA ILOG vehicle routing

Scheduling Job shop scheduling

G53CLP – Constraint Logic Programming Dr R. Qu

Page 28: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Summary

Constraint optimisation problem

Branch and bound (B&B)

Heuristic h

Bound b

Examples

SEND + MORE = MONEY (CSP)

SEND + MOST = MONEY (COP)

G53CLP – Constraint Logic Programming Dr R. Qu

Page 29: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

G53CLP – Constraint Logic Programming Dr R. Qu

Constraint Optimisation Problems – Demos in OPL Studio

Page 30: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

SEND MORE MONEY - model

S E N D

+ M O R E

= M O N E Y

Variables:

Domain:

G53CLP – Constraint Logic Programming Dr R. Qu

Page 31: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

SEND MORE MONEY - model

//.mod file//declaration//variablesenum Letters {S, E, N, D, M, O, R, Y};

//domainvar int l[Letters] in 0..9;

G53CLP – Constraint Logic Programming Dr R. Qu

Page 32: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

SEND MORE MONEY - model

//.mod file//declaration…//problem - constraintssolve {

alldifferent(l) onDomain;l[S] <> 0; l[M] <> 0; ...

};

G53CLP – Constraint Logic Programming Dr R. Qu

Page 33: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

SEND MORE MONEY - model

//.mod file//declaration…//problem - constraintssolve {

...1000*l[S] + 100*l[E] + 10*l[N] + l[D] + 1000*l[M] + 100*l[O] + 10*l[R] + l[E]= 10000*l[M] + 1000*l[O] + 100*l[N] + 10*l[E] + l[Y];

};

G53CLP – Constraint Logic Programming Dr R. Qu

Page 34: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

G52AIP – AI Programming

SEND MORE MONEY - model

Page 35: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

G52AIP – AI Programming

SEND MORE MONEY – decision tree

Page 36: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

SEND MOST MONEY – model

S E N D

+ M O S T

= M O N E Y

Variables:

Domain:

G53CLP – Constraint Logic Programming Dr R. Qu

Page 37: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Smuggler’s Knapsack Problem

A smuggler has a knapsack of capacity 9

He can only make one trip

He can smuggle Bottles of whisky size 4 profit 15

Bottles of perfume size 3 profit 10

Cartons of cigarettes size 2 profit 7

He wants At least a profit of 30

Maximise the profit

G53CLP – Constraint Logic Programming Dr R. Qu

Page 38: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Smuggler’s Knapsack Problem

Variables W, P, C

Domain {0, …, 9}

Constraints 4*W + 3*P + 2*C <= 9;

15*W + 10*P + 7*C >=30;

Bottles of whisky size 4 profit 15Bottles of perfume size 3 profit 10Cartons of cigarettes size 2 profit 7

G53CLP – Constraint Logic Programming Dr R. Qu

Page 39: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Knapsack Problems

Which items should be put in the bag to maximise the profit

G53CLP – Constraint Logic Programming Dr R. Qu

Page 40: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Knapsack Problems

General problems

Given a number of items with associated costs and values

Determine the collection of items so that

Total cost is minimised, or within a limit

Total value is maximised

G53CLP – Constraint Logic Programming Dr R. Qu

Page 41: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Simple Assignment Problem

In a factory 4 workers

4 products

Profits of assigning workers to products

Each worker has one product

Each product is assigned to one worker

At least total profit >= 19

p1 p2 p3 p4

w1 7 1 3 4

w2 8 2 5 1

w3 4 3 7 2

w4 3 1 6 3

G53CLP – Constraint Logic Programming Dr R. Qu

Page 42: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Simple Assignment Problem

Variables

li,j: worker i assigned to product j

Domain

0, 1

Constraints

sum (li) = 1, i={..4}

sum (weighti,j * li,j) >= 19

G53CLP – Constraint Logic Programming Dr R. Qu

Page 43: G53CLP Constraint Logic Programming - Nottinghampszrq/files/11CLPOptimisation.pdfConstraint Satisfaction Problems So far All solutions are equally good In some real world applications,

Lab Session Next Week

In IBM ILOG OPL IDE

Build COP models

G53CLP – Constraint Logic Programming Dr R. Qu


Recommended