|
18 | 18 | mpl.use('Agg')
|
19 | 19 | del mpl
|
20 | 20 |
|
21 |
| -import matplotlib.pyplot as plt |
22 | 21 | from math import sqrt, log
|
23 | 22 | from itertools import product
|
24 | 23 | from mip import Model, xsum, minimize, OptimizationStatus
|
|
42 | 41 | # demands
|
43 | 42 | d = {1: 302, 2: 273, 3: 275, 4: 266, 5: 287, 6: 296, 7: 297, 8: 310, 9: 302, 10: 309}
|
44 | 43 |
|
45 |
| -# plotting possible plant locations |
46 |
| -for i, p in pf.items(): |
47 |
| - plt.scatter((p[0]), (p[1]), marker="^", color="purple", s=50) |
48 |
| - plt.text((p[0]), (p[1]), "$f_%d$" % i) |
49 |
| - |
50 |
| -# plotting location of clients |
51 |
| -for i, p in pc.items(): |
52 |
| - plt.scatter((p[0]), (p[1]), marker="o", color="black", s=15) |
53 |
| - plt.text((p[0]), (p[1]), "$c_{%d}$" % i) |
54 |
| - |
55 |
| -plt.text((20), (78), "Region 1") |
56 |
| -plt.text((70), (78), "Region 2") |
57 |
| -plt.plot((50, 50), (0, 80)) |
58 |
| - |
59 | 44 | dist = {(f, c): round(sqrt((pf[f][0] - pc[c][0]) ** 2 + (pf[f][1] - pc[c][1]) ** 2), 1)
|
60 | 45 | for (f, c) in product(F, C) }
|
61 | 46 |
|
|
102 | 87 |
|
103 | 88 | m.optimize()
|
104 | 89 |
|
105 |
| -plt.savefig("location.pdf") |
106 |
| - |
107 | 90 | if m.num_solutions:
|
108 | 91 | print("Solution with cost {} found.".format(m.objective_value))
|
109 | 92 | print("Facilities capacities: {} ".format([z[f].x for f in F]))
|
110 | 93 | print("Facilities cost: {}".format([y[f].x for f in F]))
|
111 |
| - |
112 |
| - # plotting allocations |
113 |
| - for (i, j) in [(i, j) for (i, j) in product(F, C) if x[(i, j)].x >= 1e-6]: |
114 |
| - plt.plot( |
115 |
| - (pf[i][0], pc[j][0]), (pf[i][1], pc[j][1]), linestyle="--", color="darkgray" |
116 |
| - ) |
117 |
| - |
118 |
| - plt.savefig("location-sol.pdf") |
119 |
| - |
| 94 | + |
120 | 95 | # sanity checks
|
121 | 96 | opt = 99733.94905406
|
122 | 97 | if m.status == OptimizationStatus.OPTIMAL:
|
|
0 commit comments