G53CLP Constraint Logic Programming Constraint Optimisation Problems – Demos in OPL Studio Dr Rong Qu
2 SEND MORE MONEY - model S E N D + M O R E = M O N E Y Variables: Domain: G53CLP – Constraint Logic ProgrammingDr R. Qu
3 SEND MORE MONEY - model //.mod file //declaration //variables enum Letters {S, E, N, D, M, O, R, Y}; //domain var int l[Letters] in 0..9; … G53CLP – Constraint Logic ProgrammingDr R. Qu
4 SEND MORE MONEY - model //.mod file //declaration … //problem - constraints solve { alldifferent(l) onDomain; l[S] <> 0; l[M] <> 0;... }; G53CLP – Constraint Logic ProgrammingDr R. Qu
5 SEND MORE MONEY - model //.mod file //declaration … //problem - constraints solve { *l[S] + 100*l[E] + 10*l[N] + l[D] *l[M] + 100*l[O] + 10*l[R] + l[E] = 10000*l[M] *l[O] + 100*l[N] + 10*l[E] + l[Y]; }; G53CLP – Constraint Logic ProgrammingDr R. Qu
G52AIP – AI Programming 6 SEND MORE MONEY - model
G52AIP – AI Programming 7 SEND MORE MONEY – decision tree
8 SEND MOST MONEY – model S E N D + M O S T = M O N E Y Variables: Domain: G53CLP – Constraint Logic ProgrammingDr R. Qu
9 Smuggler’s Knapsack Problem A smuggler has a knapsack of capacity 9 He can only make one trip He can smuggle Bottles of whiskysize 4profit 15 Bottles of perfumesize 3profit 10 Cartons of cigarettessize 2profit 7 He wants At least a profit of 30 Maximise the profit G53CLP – Constraint Logic ProgrammingDr R. Qu
10 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 15 Bottles of perfume size 3 profit 10 Cartons of cigarettes size 2 profit 7 G53CLP – Constraint Logic ProgrammingDr R. Qu
11 Knapsack Problems Which items should be put in the bag to maximise the profit G53CLP – Constraint Logic ProgrammingDr R. Qu
12 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 ProgrammingDr R. Qu
13 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 p1p2p3p4 w17134 w28251 w34372 w43163 G53CLP – Constraint Logic ProgrammingDr R. Qu
14 Simple Assignment Problem Variables l i,j : worker i assigned to product j Domain 0, 1 Constraints sum (l i ) = 1, i={..4} sum (weight i,j * l i,j ) >= 19 G53CLP – Constraint Logic ProgrammingDr R. Qu