/* Transportation problem in Picat. Problem and model from ECLiPSe CLP documentation. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import mip. % 0.0s % import cp. main => go. go => Vars = [A1,A2,A3,B1,B2,B3,C1,C2,C3,D1,D2,D3], Vars :: 0..1000, % Obj :: 1..10000, % Obj #> 0, foreach(I in 1..Vars.length) Vars[I] #>= 0 end, A1 + A2 + A3 #= 200, B1 + B2 + B3 #= 400, C1 + C2 + C3 #= 300, D1 + D2 + D3 #= 100, A1 + B1 + C1 + D1 #<= 500, A2 + B2 + C2 + D2 #<= 300, A3 + B3 + C3 + D3 #<= 400, Obj #= 10*A1 + 7*A2 + 11*A3 + 8*B1 + 5*B2 + 10*B3+ 5*C1 + 5*C2 + 8*C3+ 9*D1 + 3*D2 + 7*D3, println(obj=Obj), % solve($[ff,split,min(Obj),report(printf("Obj=%d\n",Obj))], Vars), solve($[min(Obj)], Vars), println(vars=Vars), println(obj=Obj), nl. % general approach go2 => num_plants(NumPlants), num_clients(NumClients), capacity(Capacity), demand(Demand), cost(Cost), X = new_array(NumPlants,NumClients), X :: 0..1000, Z #= sum([X[I,J]* Cost[I,J] : I in 1..NumPlants, J in 1..NumClients]), foreach(I in 1..NumPlants, J in 1..NumClients) X[I,J] #>= 0 end, foreach(I in 1..NumPlants) sum([X[I,J] : J in 1..NumClients]) #<= Capacity[I] end, foreach(J in 1..NumClients) sum([ X[I,J] : I in 1..NumPlants]) #= Demand[J] end, solve($[min(Z)], X), printf("Z: %.0f\n", Z), foreach(Row in X) foreach(R in Row) printf("%6.0f ", R) end, nl end, nl. % % data for go2/0 % num_plants(NumPlants) => NumPlants=3. num_clients(NumClients) => NumClients = 4. capacity(Capacity) => Capacity = [500, 300, 400]. demand(Demand) => Demand = [200, 400, 300, 100]. cost(Cost) => Cost = [[10, 8, 5, 9], [ 7, 5, 5, 3], [11,10, 8, 7]].