Exemple #1
0
def generate_solution(locations, solution, vehicles, routing, manager):
    # Create route solution string and gather data for the graph
    route_graph = []
    solution_str = "Vehicle Routing with Time Windows Solution<br><br>"
    time_dimension = routing.GetDimensionOrDie('Time')
    total_time = 0
    for vehicle_id in range(vehicles):
        index = routing.Start(vehicle_id)
        plan_output = 'Route for vehicle {}:<br>'.format(vehicle_id) + "&nbsp;"
        while not routing.IsEnd(index):
            time_var = time_dimension.CumulVar(index)
            plan_output += '{0} Time({1},{2}) -> '.format(
                manager.IndexToNode(index), solution.Min(time_var),
                solution.Max(time_var))
            index = solution.Value(routing.NextVar(index))
        time_var = time_dimension.CumulVar(index)
        plan_output += '{0} Time({1},{2})<br>'.format(
            manager.IndexToNode(index), solution.Min(time_var),
            solution.Max(time_var))
        route_graph.append(plan_output.split(":<br>&nbsp;")[1][:-14])
        plan_output += 'Time of the route: {} min<br>'.format(
            solution.Min(time_var))
        solution_str += plan_output + '<br>'
        total_time += solution.Min(time_var)
    solution_str += 'Total time of all routes: {} min'.format(
        total_time) + "<br><br>"
    solution_str += "The VRP with Time Windows with Resource Constrains is a variation of this problem. <br>Select and run the VRPTW with Resource Constraints to see the route obtained from it."
    return (solution_str,
            getGraphCoords(locations, parseTimeWindows(route_graph)))
def generate_solution(locations, solution, routing, manager, vehicles, demands):
    # Create route solution string and gather data for the graph
    route_graph = []
    total_distance = 0
    total_load = 0
    solution_str = "Capacitated Vehicle Routing Solution<br><br>"
    for vehicle_id in range(vehicles):
        index = routing.Start(vehicle_id)
        plan_output = 'Route for vehicle {}:\n'.format(vehicle_id) + "<br>" + "&nbsp;"
        route_distance = 0
        route_load = 0
        while not routing.IsEnd(index):
            node_index = manager.IndexToNode(index)
            route_load += demands[node_index]
            plan_output += ' {0} Load({1}) -> '.format(node_index, route_load)
            previous_index = index
            index = solution.Value(routing.NextVar(index))
            route_distance += routing.GetArcCostForVehicle(
                previous_index, index, vehicle_id)
        plan_output += ' {0} Load({1})\n'.format(manager.IndexToNode(index), route_load) + "<br>"
        route_graph.append(plan_output.split(":\n<br>&nbsp; ")[1][:-13])
        plan_output += 'Distance of the route: {}m\n'.format(route_distance) + "<br>"
        plan_output += 'Load of the route: {}\n'.format(route_load) + "<br>"
        solution_str += plan_output + "<br>"
        total_distance += route_distance
        total_load += route_load
    solution_str += 'Total distance of all routes: {}m'.format(total_distance) + "<br>"
    solution_str += 'Total load of all routes: {}'.format(total_load) + "<br><br>"
    solution_str += "The Capacitated VRP with Penalties has the same parameters. <br>Select and run the CVRP with Penalties to see the route obtained from it."
    return(solution_str, getGraphCoords(locations, parseCapacitated(route_graph)))
def generate_solution(locations, solution, manager, routing, vehicles):
    # Create route solution string and gather data for the graph

    route_graph = []
    max_route_distance = 0
    solution_str = "Open Vehicle Routing Solution<br><br>"
    for vehicle_id in range(vehicles):
        index = routing.Start(vehicle_id)
        solution_str += 'Route for vehicle {}:<br>'.format(
            vehicle_id) + "&nbsp;"
        plan_output = ""
        route_distance = 0
        while not routing.IsEnd(index):
            plan_output += ' {} -> '.format(manager.IndexToNode(index) - 1)
            previous_index = index
            index = solution.Value(routing.NextVar(index))
            route_distance += routing.GetArcCostForVehicle(
                previous_index, index, vehicle_id)
        plan_output += '{}\n'.format(manager.IndexToNode(index))
        plan_output = plan_output[7:len(plan_output) - 5] + "<br>"
        route_graph.append(plan_output.split(" <br>")[0])
        plan_output += 'Distance of the route: {}m<br>'.format(route_distance)
        solution_str += plan_output
        max_route_distance = max(route_distance, max_route_distance)
        solution_str += '<br>'
    solution_str += 'Maximum of the route distances: {}m'.format(
        max_route_distance) + "<br><br>"
    solution_str += "The Basic VRP has the same parameters. <br>Select and run the Basic VRP to see the route obtained from it."
    return (solution_str, getGraphCoords(locations, route_graph))
def generate_solution(locations, solution, routing, manager, vehicles, demands):    
    # Create route solution string and gather data for the graph
    solution_str = "Capacitated Vehicle Routing with Penalties Solution<br><br>"

    # Display dropped nodes.
    dropped_nodes = 'Dropped nodes:'
    for node in range(routing.Size()):
        if routing.IsStart(node) or routing.IsEnd(node):
            continue
        if solution.Value(routing.NextVar(node)) == node:
            dropped_nodes += ' {}'.format(manager.IndexToNode(node))
    if (dropped_nodes == 'Dropped nodes:'):
        solution_str += dropped_nodes + " No nodes were dropped" + '<br><br>'
    else:
        solution_str += dropped_nodes + '<br><br>'
    
    route_graph = []

    # Display routes
    total_distance = 0
    total_load = 0
    for vehicle_id in range(vehicles):
        index = routing.Start(vehicle_id)
        plan_output = 'Route for vehicle {}:\n'.format(vehicle_id) + "<br> &nbsp;"
        route_distance = 0
        route_load = 0
        while not routing.IsEnd(index):
            node_index = manager.IndexToNode(index)
            route_load += demands[node_index]
            plan_output += ' {0} Load({1}) -> '.format(node_index, route_load)
            previous_index = index
            index = solution.Value(routing.NextVar(index))
            route_distance += routing.GetArcCostForVehicle(
                previous_index, index, vehicle_id)
        plan_output += ' {0} Load({1})\n'.format(manager.IndexToNode(index), route_load) + "<br>"
        route_graph.append(plan_output.split(":\n<br> &nbsp; ")[1][:-13])
        plan_output += 'Distance of the route: {}m\n'.format(route_distance) + "<br>"
        plan_output += 'Load of the route: {}\n'.format(route_load) + "<br><br>"
        solution_str += plan_output
        total_distance += route_distance
        total_load += route_load
    solution_str += 'Total Distance of all routes: {}m'.format(total_distance) + "<br>"
    solution_str += 'Total Load of all routes: {}'.format(total_load) + "<br><br>"
    solution_str += "The Capacitated VRP has the same parameters. <br>Select and run the Capacitated VRP to see the route obtained from it."
    return(solution_str, getGraphCoords(locations, parseCapacitated(route_graph)))
Exemple #5
0
def inital_solution_algorithm(locations, distance_matrix, initial_routes):
    # Calculate the distances of the routes entered by the user
    route_graph = []
    inital_solution = []
    solution_string = ""

    for r in range(len(initial_routes)):
        solution_string += "Route for vehicle " + str(r) + ":<br>" + "&nbsp;"
        route = list(initial_routes[r])
        sum = 0
        solution_string += " " + " -> ".join(str(x) for x in route) + '<br>'
        route_graph.append(" -> ".join(str(x) for x in route))
        for i in range(len(route) - 1):
            sum += (distance_matrix[route[i]][route[i + 1]])
        solution_string += "Distance of the route: " + str(sum) + 'm<br><br>'
        inital_solution.append(sum)

    solution_string += "Maximum of the route distances: " + str(
        max(inital_solution)) + "m<br>"
    return (solution_string, getGraphCoords(locations, route_graph))
def generate_solution(locations, solution, vehicles, routing, manager):
    # Create route solution string and gather data for the graph
    route_graph = []
    solution_str = "Pickups and Deliveries Vehicle Routing Solution<br><br>"
    total_distance = 0
    for vehicle_id in range(vehicles):
        index = routing.Start(vehicle_id)
        plan_output = 'Route for vehicle {}:<br>'.format(vehicle_id) + "&nbsp;"
        route_distance = 0
        while not routing.IsEnd(index):
            plan_output += ' {} -> '.format(manager.IndexToNode(index))
            previous_index = index
            index = solution.Value(routing.NextVar(index))
            route_distance += routing.GetArcCostForVehicle(previous_index, index, vehicle_id)
        plan_output += '{}<br>'.format(manager.IndexToNode(index))
        route_graph.append(plan_output.split(":<br>&nbsp; ")[1][:-4])
        plan_output += 'Distance of the route: {}m<br>'.format(route_distance)
        solution_str += plan_output + '<br>'
        total_distance += route_distance
    solution_str += 'Total Distance of all routes: {}m'.format(total_distance)
    return(solution_str, getGraphCoords(locations, route_graph))