У меня возникла проблема, решение которой для экземпляра OR-Tools VRP не найдено.
Я новичок в OR-Tools. После ознакомления с документами я понимаю, что если первое решение не найдено, то решение вообще не будет найдено. Чтобы помочь этому, мне следует каким-то образом ослабить ограничения на поиск первого решения. Однако я безуспешно пытался сделать ограничения расстояния на уровне транспортного средства массивными.
Вот код, который я использую
def solve_or_tools_routing(self, data):
"""
Solves an OR tools routing problem. Documentation here: https://developers.google.com/optimizat ... p_delivery
"""
def print_solution(data, manager, routing, solution):
"""HELPER FUNC. Prints solution on console."""
print(f"Objective: {solution.ObjectiveValue()}")
print(f"data in print solution {data}")
total_distance = 0
for vehicle_id in range(data["num_vehicles"]):
index = routing.Start(vehicle_id)
plan_output = f"Route for vehicle {vehicle_id}:\n"
route_distance = 0
while not routing.IsEnd(index):
plan_output += f" {manager.IndexToNode(index)} -> "
previous_index = index
index = solution.Value(routing.NextVar(index))
distance = routing.GetArcCostForVehicle(previous_index, index, vehicle_id)
route_distance += distance
plan_output += f"{manager.IndexToNode(index)}\n"
plan_output += f"Distance of the route: {route_distance}m\n"
print(plan_output)
total_distance += route_distance
print(f"Total Distance of all routes: {total_distance}m")
# Create the routing index manager.
manager = pywrapcp.RoutingIndexManager(len(data["distance_matrix"]), data["num_vehicles"], data["depot"])
# Create Routing Model.
routing = pywrapcp.RoutingModel(manager)
# Define cost of each arc.
def distance_callback(from_index, to_index):
"""Returns the distance between the two nodes."""
from_node = manager.IndexToNode(from_index)
to_node = manager.IndexToNode(to_index)
return data["distance_matrix"][from_node][to_node]
transit_callback_index = routing.RegisterTransitCallback(distance_callback)
routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)
# Add Distance constraint.
dimension_name = "Distance"
routing.AddDimension(
transit_callback_index,
1000, # no slack
50000, # max vehicle distance travelled
True, # start cumul to zero
dimension_name,
)
distance_dimension = routing.GetDimensionOrDie(dimension_name)
distance_dimension.SetGlobalSpanCostCoefficient(100)
# Define Transportation Requests.
print(f'PRINTING NUMBER OF PICKUPS/DELIVERIES: {(data["pickups_deliveries"])}')
for request in data["pickups_deliveries"]:
pickup_index = manager.NodeToIndex(request[0])
delivery_index = manager.NodeToIndex(request[1])
routing.AddPickupAndDelivery(pickup_index, delivery_index)
routing.solver().Add(
routing.VehicleVar(pickup_index) == routing.VehicleVar(delivery_index)
)
routing.solver().Add(
distance_dimension.CumulVar(pickup_index)
Подробнее здесь: https://stackoverflow.com/questions/790 ... -tools-vrp
Решение не найдено OR-Tools VRP ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как обеспечить максимальное время езды на пассажир как мягкое ограничение в VRP или Tools?
Anonymous » » в форуме Python - 0 Ответы
- 2 Просмотры
-
Последнее сообщение Anonymous
-
-
-
ИЛИ Tools cp sat гибкая мастерская с гибкими сроками оптимальное решение не найдено
Anonymous » » в форуме Python - 0 Ответы
- 14 Просмотры
-
Последнее сообщение Anonymous
-