Skip to content

Commit

Permalink
Fix CI issues
Browse files Browse the repository at this point in the history
Temporarily removing Matplotlib as it was raising errors when running tests on ubuntu-22.04.
  • Loading branch information
tuliotoffolo committed Jan 19, 2024
1 parent bd880a2 commit 2b682aa
Showing 1 changed file with 1 addition and 34 deletions.
35 changes: 1 addition & 34 deletions examples/plant_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@

import sys

# Workaround for issues with python not being installed as a framework on mac
# by using a different backend.
if sys.platform == "darwin": # OS X
import matplotlib as mpl

mpl.use("Agg")
del mpl

import matplotlib.pyplot as plt
from math import sqrt, log
from itertools import product
from mip import Model, xsum, minimize, OptimizationStatus
Expand Down Expand Up @@ -53,20 +44,6 @@
# demands
d = {1: 302, 2: 273, 3: 275, 4: 266, 5: 287, 6: 296, 7: 297, 8: 310, 9: 302, 10: 309}

# plotting possible plant locations
for i, p in pf.items():
plt.scatter((p[0]), (p[1]), marker="^", color="purple", s=50)
plt.text((p[0]), (p[1]), "$f_%d$" % i)

# plotting location of clients
for i, p in pc.items():
plt.scatter((p[0]), (p[1]), marker="o", color="black", s=15)
plt.text((p[0]), (p[1]), "$c_{%d}$" % i)

plt.text((20), (78), "Region 1")
plt.text((70), (78), "Region 2")
plt.plot((50, 50), (0, 80))

dist = {
(f, c): round(sqrt((pf[f][0] - pc[c][0]) ** 2 + (pf[f][1] - pc[c][1]) ** 2), 1)
for (f, c) in product(F, C)
Expand Down Expand Up @@ -116,26 +93,16 @@

m.optimize()

plt.savefig("location.pdf")

if m.num_solutions:
print("Solution with cost {} found.".format(m.objective_value))
print("Facilities capacities: {} ".format([z[f].x for f in F]))
print("Facilities cost: {}".format([y[f].x for f in F]))

# plotting allocations
for i, j in [(i, j) for (i, j) in product(F, C) if x[(i, j)].x >= 1e-6]:
plt.plot(
(pf[i][0], pc[j][0]), (pf[i][1], pc[j][1]), linestyle="--", color="darkgray"
)

plt.savefig("location-sol.pdf")

# sanity checks
opt = 99733.94905406
if m.status == OptimizationStatus.OPTIMAL:
assert abs(m.objective_value - opt) <= 0.01
elif m.status == OptimizationStatus.FEASIBLE:
assert m.objective_value >= opt - 0.01
else:
assert m.status not in [OptimizationStatus.INFEASIBLE, OptimizationStatus.UNBOUNDED]
assert m.status not in [OptimizationStatus.INFEASIBLE, OptimizationStatus.UNBOUNDED]

0 comments on commit 2b682aa

Please sign in to comment.