/* Assignment problem in Picat. Marriott & Stuckey "Programming with Constraints", page 266. This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => profit(Profit), NumWorkers = Profit.len, NumProducts = Profit[1].len, X = new_array(NumWorkers,NumProducts), X :: 0..1, SumProfit #= sum([X[W,P]*Profit[W,P] : W in 1..NumWorkers, P in 1..NumProducts]), foreach(W in 1..NumWorkers) sum([X[W,P] : P in 1..NumProducts]) #= 1 end, foreach(P in 1..NumProducts) sum([X[W,P] : W in 1..NumWorkers]) #= 1 end, solve($[max(SumProfit)],X), println(sum_profit=SumProfit), foreach(Row in X) println(Row.to_list) end, nl. profit(Profit) => Profit = [[7,1,3,4], [8,2,5,1], [4,3,7,2], [3,1,6,3]].