/
transshipment.pi
67 lines (46 loc) · 1.22 KB
/
transshipment.pi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
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].