/* Make a Good Burger problem in Picat. From https://dmcommunity.wordpress.com/challenge/make-a-good-burger/ """ As the owner of a fast food restaurant with declining sales, you know that your customers are looking for something new and exciting on the menu. Your market research indicates that they want a burger that is loaded with everything as long as it meets certain health requirements. Money is no object to them. The ingredient list in the table below shows what is available to include on the burger: Item Sodium(mg) Fat(g) Calories Item costs ($) BeefPatty 50 17 220 $0.25 Bun 330 9 260 $0.15 Cheese 310 6 70 $0.10 Onions 1 2 10 $0.09 Pickles 260 0 5 $0.03 Lettuce 3 0 4 $0.04 Ketchup 160 0 20 $0.02 Tomato 3 0 9 $0.04 You must include at least one of each item and no more than five of each item. You must use whole items (for example, no half servings of cheese). The final burger must contain less than 3000 mg of sodium, less than 150 grams of fat, and less than 3000 calories. To maintain certain taste quality standards you'll need to keep the servings of ketchup and lettuce the same. Also, you’ll need to keep the servings of pickles and tomatoes the same. Question: Offer several recipes for a good burger. What is the most and the less expensive burger you can make? """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. import cp. main => go. go => problem(1,Items,Limits), N = Items.len, Names = new_map([Items[I,5]=I : I in 1..N]), % decision variables X = new_list(N), X :: 1..5, Total #= sum([X[I]*Items[I,4] : I in 1..N]), % sodium < 3000mg, fat < 150g, calories < 3000 foreach(J in 1..Limits.len) sum([X[I]*Items[I,J] : I in 1..N]) #< Limits[J,2] end, % % keep the serving of ketchup and lettuce the same. X[Names.get("Ketchup")] #= X[Names.get("Lettuce")], % % keep the servings of pickles and tomatoes the same. X[Names.get("Pickles")] #= X[Names.get("Tomato")], % Total #= 280 % maximal solution solve($[max(Total)],X), println(X), printf("Total: %d cent\n", Total), foreach(I in 1..N) printf("%-10w: %2d*%2dcent=%3d cent\n", Items[I,5],X[I],Items[I,4], X[I]*Items[I,4]) end, foreach(J in 1..Limits.len) printf("%-10w: %d (< %d %w)\n", Limits[J,1], sum([X[I]*Items[I,J] : I in 1..N]), Limits[J,2], Limits[J,3]) end, nl. problem(1,Items,Limits) => Items = [% sodium fat calories cost (cent) items [ 50, 17, 220, 25, "Beef Patty"], [330, 9, 260, 15, "Bun"], [310, 6, 70, 10, "Cheese"], [ 1, 2, 10, 9, "Onions"], [260, 0, 5, 3, "Pickles"], [ 3, 0, 4, 4, "Lettuce"], [160, 0, 20, 2, "Ketchup"], [ 3, 0, 9, 4, "Tomato"] ], % sodium fat calories Limits = [ ["Sodium" ,3000,"mg"], ["Fat" ,150, "g"], ["Calories",3000,"kCal"] ].