{"action":"created","issue":{"url":"https://api.github.com/repos/google/or-tools/issues/261","repository_url":"https://api.github.com/repos/google/or-tools","labels_url":"https://api.github.com/repos/google/or-tools/issues/261/labels{/name}","comments_url":"https://api.github.com/repos/google/or-tools/issues/261/comments","events_url":"https://api.github.com/repos/google/or-tools/issues/261/events","html_url":"https://github.com/google/or-tools/issues/261","id":184025698,"number":261,"title":"Vehicle routing with minimum locations per route.","user":{"login":"keerthys","id":827657,"avatar_url":"https://avatars.githubusercontent.com/u/827657?v=3","gravatar_id":"","url":"https://api.github.com/users/keerthys","html_url":"https://github.com/keerthys","followers_url":"https://api.github.com/users/keerthys/followers","following_url":"https://api.github.com/users/keerthys/following{/other_user}","gists_url":"https://api.github.com/users/keerthys/gists{/gist_id}","starred_url":"https://api.github.com/users/keerthys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keerthys/subscriptions","organizations_url":"https://api.github.com/users/keerthys/orgs","repos_url":"https://api.github.com/users/keerthys/repos","events_url":"https://api.github.com/users/keerthys/events{/privacy}","received_events_url":"https://api.github.com/users/keerthys/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-19T17:29:21Z","updated_at":"2016-10-20T03:00:06Z","closed_at":null,"body":"Hi,\r\nI have been trying to use the or-tools routing model for generating routes with the following constraints,\r\n\r\n1. Time window constraint for customer to visit.\r\n2. Maximum capacity for a vehicle.\r\n3. Penalty for critical customer to be included in the route.\r\n4. Minimum capacity for a vehicle to ensure that we don't operate vehicles which are under capacity.\r\n\r\nI am able to implement (1), (2) and (3) following the wiki docs and code samples. But not sure how to achieve (4). I tried to use SetEndCumulVarSoftLowerBound on capacity dimension but results to be not optimal. As I change the value of the cumulVar parameter in the method, results varies a lot and skips entries for certain cumulVar. \r\n\r\nAny pointers and help on implementing (4) along with 1..3 would be really helpful.\r\n\r\nI am pasting the code I use for creating model below for reference.\r\n\r\n\r\n`\r\n           num_vehicles = 3\r\n           routing = pywrapcp.RoutingModel(num_locations, num_vehicles)\r\n\r\n            parameters = routing.DefaultSearchParameters()\r\n            parameters.first_solution_strategy = (routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC)\r\n            parameters.time_limit_ms = 5 * 1000  # 5 seconds search time limit\r\n            parameters.use_light_propagation = False\r\n            parameters.log_search = True\r\n\r\n            # Set the depot.\r\n            routing.SetDepot(depot)\r\n\r\n            # Put callbacks to the distance function and travel time functions here.\r\n            dist_between_locations = CreateDistanceCallback(locations)\r\n            dist_callback = dist_between_locations.Distance\r\n            routing.SetArcCostEvaluatorOfAllVehicles(dist_callback)\r\n\r\n            # Adding capacity dimension constraints.\r\n            demands_at_locations = CreateDemandCallback(demands)\r\n            demands_callback = demands_at_locations.Demand\r\n            vehicle_capacity = vehicle_capacity  # Maximum number of demands vehicle can carry\r\n            null_capacity_slack = 0\r\n            fix_start_cumul_to_zero = True\r\n            capacity = \"Capacity\"\r\n            routing.AddDimension(demands_callback, null_capacity_slack, vehicle_capacity, fix_start_cumul_to_zero,\r\n                                 capacity)\r\n\r\n            capacity_dimension = routing.GetDimensionOrDie(capacity)\r\n            for vehicle in range(0, num_vehicles):\r\n                capacity_dimension.SetEndCumulVarSoftLowerBound(vehicle, 2, 1000)\r\n\r\n            # Adding time dimension constraints.\r\n            time_per_demand_unit = serviceable_duration_seconds  # seconds to service a customer\r\n            horizon = self.__get_offset_from_start_of_day(vehicle_report_back_time)\r\n            time = \"Time\"\r\n            speed_kmph = vehicle_speed_kmph  # speed of vehicle in mk per hour assumed to be constant\r\n\r\n            service_times = CreateServiceTimeCallback(demands, time_per_demand_unit)\r\n            service_time_callback = service_times.ServiceTime\r\n\r\n            total_times = CreateTotalTimeCallback(service_time_callback, dist_callback, speed_kmph)\r\n            total_time_callback = total_times.TotalTime\r\n\r\n            # Add a dimension for time-window constraints and limits on the start times and end times.\r\n            routing.AddDimension(total_time_callback,  # total time function callback\r\n                                 horizon,\r\n                                 horizon,\r\n                                 fix_start_cumul_to_zero,\r\n                                 time)\r\n\r\n            # Add limit on size of the time windows.\r\n            time_dimension = routing.GetDimensionOrDie(time)\r\n            for order in range(1, num_locations):\r\n                start = start_times[order]\r\n                end = end_times[order]\r\n                time_dimension.CumulVar(order).SetRange(start, end)\r\n    \r\n            #Adding penalty for dropping order. Only first three locations are made critical here\r\n            non_depot = set(range(1,3))\r\n            penalty = 10  # The cost for dropping a node from the plan.\r\n            nodes = [routing.AddDisjunction([int(c)], penalty) for c in non_depot]\r\n\r\n            # Solve displays a solution if any.\r\n            assignment = routing.SolveWithParameters(parameters)\r\n`"},"comment":{"url":"https://api.github.com/repos/google/or-tools/issues/comments/254996843","html_url":"https://github.com/google/or-tools/issues/261#issuecomment-254996843","issue_url":"https://api.github.com/repos/google/or-tools/issues/261","id":254996843,"user":{"login":"keerthys","id":827657,"avatar_url":"https://avatars.githubusercontent.com/u/827657?v=3","gravatar_id":"","url":"https://api.github.com/users/keerthys","html_url":"https://github.com/keerthys","followers_url":"https://api.github.com/users/keerthys/followers","following_url":"https://api.github.com/users/keerthys/following{/other_user}","gists_url":"https://api.github.com/users/keerthys/gists{/gist_id}","starred_url":"https://api.github.com/users/keerthys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keerthys/subscriptions","organizations_url":"https://api.github.com/users/keerthys/orgs","repos_url":"https://api.github.com/users/keerthys/repos","events_url":"https://api.github.com/users/keerthys/events{/privacy}","received_events_url":"https://api.github.com/users/keerthys/received_events","type":"User","site_admin":false},"created_at":"2016-10-20T03:00:05Z","updated_at":"2016-10-20T03:00:05Z","body":"Thanks for the quick reply Martin.\n\nBasically we have a requirement like vehicle should be operated only if the\nroute had more than X orders and also want to make sure that heavy weight\norders gets first picked up in the routes.\n\nBy setting up penalty as weight of order, we are able to make sure heavy\nweight are included in the routes. But those heavy weight order may end up\nfalling in a route which has less than X orders(minimum criteria for van).\nIn order to avoid this case we need a hook to specify the minimum capacity\nfor a vehicle as well so that both our above requirement will be met.\n\nHope this clarifies.\n\nOn 19 Oct 2016 11:12 pm, \"Martin West\" <notifications@github.com> wrote:\n\n> I'm not quite sure what you want by point 4. Setting a cost of a vehicle\n> maybe the way to do it?\n> You can do that with\n> \"\"\"\n> # Create a set of vehicles, the number set by the length of capacity.\n> vehicles = Vehicles(capacity=capacity, cost=cost)\n> \"\"\"\n> See cvrptw_plot.py for an example. If I understand things correctly, doing\n> it this way, a vehicle cost will be added if the vehicle is used. Setting\n> this cost high will prevent vehicle 'under use'\n>\n> —\n> You are receiving this because you authored the thread.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/google/or-tools/issues/261#issuecomment-254886866>,\n> or mute the thread\n> <https://github.com/notifications/unsubscribe-auth/AAyhCTzk-_LyrBkrKZNM_8mHGU48ugCEks5q1lZxgaJpZM4KbPvR>\n> .\n>\n"}}
{"actor":{"display_login":"keerthys"}}