/* Transshipment problem in Picat. From Winston "Operations Research", page 400ff This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import cp. import mip. % 0.01s % import sat. main => go. go => cost(Cost), supply(Supply), demand(Demand), Cities = Cost.length, Delivery = new_array(Cities,Cities), Delivery :: 0..10000, Z #= sum([Cost[I,J]*Delivery[I,J] : I in 1..Cities, J in 1..Cities]), Z :: 0..10000, foreach(I in 1..Cities) sum([Delivery[I,J]: J in 1..Cities]) #<= Supply[I] end, foreach(J in 1..Cities) sum([Delivery[I,J] : I in 1..Cities]) #>= Demand[J] end, solve($[min(Z)], Delivery), println(z=Z), foreach(Row in Delivery) foreach(V in Row) printf("%4d ", V) end, nl end, nl. cost(Cost) => Cost = [ [ 0, 1000, 8, 13, 25, 28], [1000, 0, 15, 12, 26, 25], [1000, 1000, 0, 6, 16, 17], [1000, 1000, 1000, 0, 14, 16], [1000, 1000, 1000, 1000, 0, 1000], [1000, 1000, 1000, 1000, 1000, 0] ]. supply(Supply) => Supply = [150, 200, 9999, 9999, 0, 0]. demand(Demand) => Demand = [0, 0,9999,9999, 130, 130].