Ejemplo n.º 1
0
    50695, 50698, 50699, 50700, 50701, 50702, 50703, 50704, 50705, 50706,
    24196, 50707, 50708, 50709, 50710, 50711, 50712, 73303, 73304, 73298,
    73299, 73300, 14245, 73301, 73302, 834596, 834597, 834598, 59132, 834599,
    834600, 834601, 834602, 834603, 834604, 834605, 834606, 834607, 834608,
    834609, 10876, 10877, 10845, 10846, 10847, 10848, 10849, 10850, 10851,
    10852, 10865, 10866, 97261, 97262, 97263, 97196, 97264, 97265, 97266,
    97267, 97268, 97269, 97270, 97271, 97247, 97249, 617117, 97287, 97288,
    97289, 72317, 72318, 72319, 72320, 72321, 72322, 72323, 72324, 72325,
    72326, 72327, 72328, 72329, 72330, 68505, 68506, 68507, 68508, 68509,
    68500, 68510, 68511, 68512, 68450, 68513, 68514, 68459, 617116, 617115,
    69265, 68711, 617114, 617113, 68713, 617112, 617111, 617110, 617109, 68593,
    68592, 68591, 68590, 68589, 68588, 68587, 68586, 68585, 68584, 68583,
    68582, 68581, 68464, 68465, 68466, 68467, 20186, 20187, 20188, 20189,
    20172, 28144, 28145, 28146, 28147, 28148, 28149, 28150, 28151, 28152,
    28153, 28154, 20107, 29247, 29248, 29249
])

# Plot the orders
plotOrders(roads, prob.orders)
plt.title("Showing orders. Click to show path")
plt.show(block=False)
plt.waitforbuttonpress()

# Plot the path
plotPath(examplePath)
plt.title("Showing path")
plt.show()

# TODO : Print the path's length/distance in kilometers.
print("Path length: {:.2f}km".format(examplePath.getDistance() / 1000))
# Plot the orders
plotOrders(roads, prob.orders)
plt.title("Showing orders. Click to show path")
plt.title("Showing orders. Click to show path")
plt.show(block=False)
plt.waitforbuttonpress()

colors = ['red', 'blue', 'green', 'orange', 'grey']

plt.title("Showing paths")

totalDistance = 0
# Plot each order at a time
for i,order in enumerate(prob.orders):
    # Create a sub-problem to solve with A* (getting the optimal path for each order separately)
    subProblem = MapProblem(roads, order[0], order[1])

    subPath, distance, _, _ = mapAstar.run(subProblem)

    print("Shortest distance for order from #{} to #{}: {:.2f}km".format(order[0], order[1], distance / 1000))
    totalDistance += distance

    # Plot the path
    plotPath(Path(roads, [s.junctionIdx for s in subPath]), color=colors[i])
    plt.show(block=False)
    plt.waitforbuttonpress()

print("Total distance: {:.2f}km".format(totalDistance / 1000    ))