/* Smuggler's knapsack problem in Picat. Marriott & Stucker: 'Programming with constraints', page 101f, 115f Smuggler's knapsack. A smuggler has a knapsack with a capacity of 9 units. Unit Profit Whisky: 4 units 15 dollars Perfume: 3 units 10 dollars Cigarettes: 2 units 7 dollars What is the optimal choice? Model created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => smuggler([W,P,C,Profit],9), writeln([W,P,C,Profit]), nl. go2 => List = [2,3,5,7,11,13,17,23,29,31], foreach(L in List) smuggler(X,L), writeln(X) end. smuggler([W,P,C,Profit],Max) => [W,P,C] :: 0..9, % Unit Profit % Whisky: 4 units 15 dollars % Perfume: 3 units 10 dollars % Cigarettes: 2 units 7 dollars % Units 4*W + 3*P + 2*C #=< Max, % Profit. 15*W + 10*P + 7*C #= Profit, solve([$max(Profit)], [Profit, W,P,C]).