/* Transportation problem in Picat. This is in princple the same model as in Pascal Van Hentenryck "The OPL Optimization Programming Language", page 116. Data from OPL example transp1.dat This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import mip. main => go. go => capacity(Capacity), supply(Supply), demand(Demand), cost(Cost), NumProducts = Supply.length, NumCities = Supply[1].length, % decision variables Trans = new_array(NumProducts,NumCities,NumCities), % Trans.vars() :: 0.0..1000000.0, % Z :: 0.0..10000000.0, Z #= sum([ Cost[P,O,D] * Trans[P,O,D] : P in 1..NumProducts , O in 1..NumCities, D in 1..NumCities]), foreach(P in 1..NumProducts , O in 1..NumCities) sum([Trans[P,O,D] : D in 1..NumCities]) #= Supply[P,O] end, foreach(P in 1..NumProducts , D in 1..NumCities) sum([Trans[P,O,D] : O in 1..NumCities]) #= Demand[P,D] end, foreach(O in 1..NumCities, D in 1..NumCities) sum([Trans[P,O,D] : P in 1..NumProducts]) #<= Capacity end, solve($[min(Z)],Trans), println(z=Z), println("Trans:"), foreach(T in Trans) foreach(R in T) foreach(S in R) printf("%6.1f ", S) end, nl end end, nl. capacity(Capacity) => Capacity = 625.0. % 1..NumProducts,1..NumCities supply(Supply) => Supply = [ [400.0, 700.0, 800.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [800.0, 1600.0, 1800.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [200.0, 300.0, 300.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] ]. % 1..NumProducts,1..NumCities demand(Demand) => Demand = [ [0, 0, 0,300,300,100, 75,650,225,250], % bands [0, 0, 0,500,750,400,250,950,850,500], % coils [0, 0, 0,100,100, 0, 50,200,100,250] % plate ]. % 1..NumProducts, 1..NumCities,1..NumCities cost(Cost) => Cost = [ % bands [ [0, 0, 0, 30, 10, 8, 10, 11, 71, 6], [0, 0, 0, 22, 7, 10, 7, 21, 82, 13], [0, 0, 0, 19, 11, 12, 10, 25, 83, 15], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ] , % coils [ [0, 0, 0, 39, 14, 11, 14, 16, 82, 8], [0, 0, 0, 27, 9, 12, 9, 26, 95, 17], [0, 0, 0, 24, 14, 17, 13, 28, 99, 20], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ] , % plate [ [0, 0, 0, 41, 15, 12, 16, 17, 86, 8], [0, 0, 0, 29, 9, 13, 9, 28, 99, 18], [0, 0, 0, 26, 14, 17, 13, 31, 104, 20], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ] ].