Exemplo n.º 1
0
    def plot(self, name):
        """
		Plots results, optimizes model first if not done yet
		"""
        if self.m.Status == 1:
            print("Model not yet optimized, now optimizing")
            self.optimize(verbose=True)
        plot(self.location, self.tours, name)
Exemplo n.º 2
0
    def plot(self, name):
        """
		Plots results, optimizes model first if not done yet
		"""
        if not len(self.visits) == self.n:
            print("Model not yet optimized, now optimizing")
            self.optimize(verbose=True)
        plot(self.location, [self.tour], name)
 def plot(self):
     if not test:
         vs.plot(Array.full_array)
Exemplo n.º 4
0
from visualizer import plot, plot_tsp

#Example of how to use visualizer.py

#Print a VRP solution. Locations are pairs of x/y coordinates,
#routes is a 2-d list representing the routes. The variable
#name is used as the title of the graph, and is also the name of the
#output file.

locations = [(1, 2), (2, 3), (5, 0), (4, 8), (5, 9)]
routes = [[0, 1, 2, 0], [0, 3, 4, 0]]
name = "VRP"

plot(locations, routes, name)

#Print a TSP solution. Locations are pairs of x/y coordinates,
#route is a list representing the TSP tour. The variable
#name is used as the title of the graph, and is also the name of the
#output file.

# locations=[(1,2),(2,3),(5,0),(4,8),(5,9)]
# route=[0,1,2,3,4,0]
# name="TSP"
# plot_tsp(locations,route,name)
Exemplo n.º 5
0
Q = 80
r = 4
f = 101

# To hold results, initialize as (list) : list[k] => (ObjValK, xvarsK)
K_optimals = []

# Iterate through loop, initialize model
for K in range(1, 10):
    model = CVRPModel(Q, r, K, f, dist, demand)
    model.optimize()
    K_optimals.append({
        "K": K,
        "Obj": model.m.ObjVal,
        "Tour": model.get_tours()
    })

[result["Tour"] for result in K_optimals]

x = [r["K"] for r in K_optimals]
y = [r["Obj"] for r in K_optimals]

plt.figure(dpi=150), plt.bar(x, y), plt.title(
    "VRP - Vehicle Scaling"), plt.xlabel("K number of vehicles"), plt.ylabel(
        "Profit (revenue, transport and fixed costs)")

# Get best result for all K's
BEST_RESULT = max(K_optimals, key=lambda res: res["Obj"])
print(BEST_RESULT["Obj"])
plot(location, BEST_RESULT["Tour"], "CVRP")