/* Blending problem in Picat. From http://www.math.ohiou.edu/~vardges/math443/homeworks/homework1.doc """ Problem 2. Blending problem. A farmer is raising pigs for market and wishes to determine the quantities of the available types of feed (corn, tankage, and alfalfa) that should be given to each pig. Since pigs will eat any mix of these feed types, the objective is to determine which mix will meet certain nutritional requirements at a minimum cost. The number of units of each type of basic nutritional ingredient contained within 1 kilogram of each feed type is given in the following table, along with the daily nutritional requirements and feed costs. [hakank: This is slighly edited by skipping "Kg of" for the feeds] Nutritional ingredient Corn Tankage Alfalfa Min daily requirement Carbohydrates 90 20 40 200 Protein 30 80 60 180 Vitamins 10 20 60 150 --------------- Cost (cent) 84 72 60 1. Formulate an integer program for this problem. 2. Suppose the farmer wants to have at most 2 feed types in the mix. Modify the model of part (a) to take the new restriction into account. 3. The farmer thinks that satisfying all the nutritional requirements costs him too much. He wants to keep only two of the three requirements. Modify the model of part (a) to minimize the cost while satisfying only two (any two) of the three nutritional requirements. """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => NumIngredients = 3, NumFeeds = 3, IngredientsPerFeed = [[90, 20, 40], [30, 80, 60], [10, 20, 60]], FeedCost = [84,72,60], % in cents MinDailyRequirements = [200, 180,150], % mix of feeds Mix = new_list(NumFeeds), Mix :: 0..100, % which daily requirements are met? DailyReqMet = new_list(NumIngredients), DailyReqMet :: 0..1, % total cost TotCost :: 0..1000, % daily requirements foreach(I in 1..NumIngredients) % hard constraint version % sum([Mix[J]*IngredientsPerFeed[I,J]) : J in 1..NumFeeds]) #>= MinDailyRequirements[I] % soft constraint version according to requirement 3. sum([Mix[J]*IngredientsPerFeed[I,J] : J in 1..NumFeeds]) #>= MinDailyRequirements[I] #<=> DailyReqMet[I] #= 1 end, TotCost #= sum([Mix[J]*FeedCost[J] : J in 1..NumFeeds]), % 2. Suppose the farmer wants to have at most 2 feed types in the mix. % Modify the model of part (a) to take the new restriction into account. sum([Mix[J] #> 0 : J in 1..NumFeeds]) #<= 2, % 3. The farmer thinks that satisfying all the nutritional requirements costs him % too much. He wants to keep only two of the three requirements. Modify the model % of part (a) to minimize the cost while satisfying only two (any two) of the % three nutritional requirements. sum(DailyReqMet) #= 2, Vars = Mix ++ DailyReqMet, solve($[min(TotCost)],Vars), println(totCost=TotCost), println(mix=Mix), println(dailyReqMet=DailyReqMet), nl.