CVRP | Capacitated Vehicle Routing Problem Solution | Machine Learning library
kandi X-RAY | CVRP Summary
kandi X-RAY | CVRP Summary
Capacitated Vehicle Routing Problem (CVRP) Solution using Evolutionary/Genetic Algorithms.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Runs the QR algorithm
- Performs the prx operation
- Renders the results in the graph
- Performs the genetic algorithm
CVRP Key Features
CVRP Examples and Code Snippets
Community Discussions
Trending Discussions on CVRP
QUESTION
I'm very new to OR-Tools and I'm trying to solve a modified VRP with capacity constraints from Google's guide.
In my problem vehicles transport multiple types of items. Some types can be transported together and others cannot.
What I triedIn the following code the types are A and B (they should not be transported together).
First I defined the two callbacks for demands and added the dimensions to the routing model
...ANSWER
Answered 2021-Dec-08 at 09:23I fixed the problem.
The issue was that the number of nodes was 3 (noDeliveries), however the number of indices was 6, so I only set the constraint on half of them.
Fixed code:
QUESTION
Context: I'm working on a warehouse simulation that supports different floor designs and simulates one or multiple agents that are tasked with order picking. One order can consist of more than one product. The routing for picking products is solved as a capacitated vehicle routing problem (CVRP). This requires a distance matrix between product locations, for which the A* algorithm is used. Currently, distance matrices are generated per order, just before picking on that order is started. Many simulation runs are desired for accurate measures, so computational efficiency is of high importance. For completeness, I included a screenshot of the simulation below, with product locations (dark), an agent (white), products in the current order (blue), and the products being picked in the current route (green/red). Note that the white lines represent the current picking priority, not the exact paths.
Problem: The size of the distance matrix grows quadratically with the number of products per order. Therefore, the time for computing it with A* quickly becomes unacceptable.
Question: I need a method that makes the computation of distance matrices more efficient. This can be either an exact method or a heuristic, as long as not too much accuracy is sacrificed. I am not looking for implementations or specific code snippets, but for ideas and/or methods that are used for similar problems that I can implement myself.
Attempted methods/ideas: Here are some approaches I've considered or tried to implement with no success:
- Distance matrix for the full warehouse: unfeasible, as the number of product locations is simply too large.
- Using Euclidean distance: not good enough. This would assume that products on opposite sides of a warehouse row are close together when in reality an agent would have to take a long detour between the two.
- Using a clustering algorithm to identify areas that are close together and base a distance matrix on clusters instead of individual locations: this would reduce the total matrix size, making it possible to pre-compute it completely. However, this would greatly reduce accuracy and I've yet to find a clustering algorithm that reliably works for this problem with different floor layouts.
Layout examples: White pixels indicate floor cells, black pixels indicate product locations. Products within an order are randomly selected from all possible locations. More floor layouts (any floor layout!) should be supported by the chosen method.
Here is a pasteable array for layout 1 if anyone wants to mess around with it:
...ANSWER
Answered 2021-Aug-25 at 08:41I know link-only answers are usually discouraged, but "what algorithms can make A* faster" is a hugely complicated topic that's been an active area of research nonstop for the past 50 years. So it's not really possible to give anything more than a vague summary in a Stackoverflow answer.
For 2D grids like your own, there are two common techniques that give huge speedups:
- JPS (Jump Point Search) is a variant of A* that exploits the symmetries in 2D grids that contain lots of open space to avoid queuing/dequeuing huge numbers of extraneous nodes.
- RSR (Rectangular Symmetry Reduction) is a preprocessing algorithm that reduces a map into "rooms" (or in your case, "hallways") to form a sort of navigation mesh for your map, reducing the size of the graph.
Additionally, since you mentioned it does not need be optimal,
- HPA* (Hierarchical Pathfinding A*) can be used to break a map into smaller chunks, sacrificing accuracy for speed.
- Flow fields can be used to precompute the best paths for multiple agents
Finally, if your grid changes over time, there is a whole field of incremental algorithms that perform better than A*.
QUESTION
I am working on a CVRP and have gotten to the point where I have a list of vehicle fleets, where each fleet is made up of a homogeneous vehicle type, and the amount of goods that should be in each fleet. The corresponding dataframe looks like this:
...ANSWER
Answered 2021-Aug-24 at 17:03I think the problem lies in the way you access your data, especially with "x.Quantity_Employed". This works, so the problem is probably in the lambda function:
QUESTION
I am modeling a Time-constrained CVRP. The problem is to minimize the total travel time (not including the package dropping time) subject to vehicle (delivery) capacity and total time spent (per vehicle) constraints. The package dropping time refers to an additional time to be spent at each node, and the total time spent equals to the travel time plus this additional time. I have the below model that works for a single vehicle-type case. I would like to introduce two-vehicle type concept in there, meaning that I have a set of V1
type vehicles and another set of V2
type vehicles. The only difference of the vehicle-types is the per time cost of travel. Let x
denote the per time unit cost of travel by V1
, and y
denote the per time unit travel cost of V2
. How can I design the model so that it incorporates this additional aspect?
ANSWER
Answered 2021-Jun-13 at 13:34Simply register two transits callbacks (i.e. one per vehicle type)
Then use the overload of AddDimension() to pass an array of registered transit callback index.
QUESTION
I have tried to create a CVRPTW solution by combining CVRP and VRPTW from examples provided in the official documentation.
Since the code is big I cannot paste it here, so I am sharing a colab notebook demonstrating a short example reproducing the problem: https://colab.research.google.com/drive/1YN-6kABqGqSkQKxOtWD6YA2ZDlP8RfqD?usp=sharing
The quantities to deliver at each node are [0, 80, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1]
I have 22 vehicles, 21 vehicles with capacity 25 and 1 vehicle with capacity 600. If the vehicles are sorted in ascending order the example with 14 nodes take more than 200 seconds to solve and if they are sorted in descending order the same example gets solved in less than a second.
I am using Google OR Tools for the first time so I don't know if this was expected or not. I have tried adding Guided Local Search also but when I add a time limit to stop it stops without giving a solution.
I created an issue in the repo but it was converted to a Discussion.
https://github.com/google/or-tools/discussions/2554
I have also asked this question in the official mailing list.
...ANSWER
Answered 2021-May-17 at 16:09This is a well known property of OR solvers. Because they include lots of heuristics, they are very sensitive to the order of variables or constraints in the model.
QUESTION
Please help me on my periodic capacitated vehicle routing problem.
Find the same question here on google-groups.
What I am trying to model:
1 depot
multiple customers (let's assume 4)
multiple days (let's assume 3)
Multiple vehicle types with price per km and specific capacity
Every customer has: delivery frequency and demand per delivery
Every customer has to be assigned to a delivery pattern. Multiple delivery patterns are possible for each frequency. The pattern indicates if a delivery is possible on that day or not. For a frequency of 1 and 3 working days:
[[1,0,0],[0,1,0],[0,0,1]]
, a frequency of 2[[1,1,0],[1,0,1],[1,1,0]]
, a frequency of 3:[1,1,1]
these are the possible patterns.
The demand of each customer per delivery is the same, for every day a delivery is performed
So we have a set of customers that have to be delivered by one depo. Multiple Vehicle Types are available for the job. The day of service is flexible because only the frequency is fixed to a customer, but there are multiple possibilities to fulfill the demand.
What I did so far:
I copied every node by the number of working days.
I restrict the start and end to the depo nodes of each day.
I multiply the vehicles by the number of days.
Furthermore, I handle the days as different kinds of cargo. I do assign a capacity of zero to the vehicle when it should not be used on that day.
...
ANSWER
Answered 2021-Apr-20 at 08:37So I found a solution for my problem.
The solving time for problems greater than 40 customers could be better.
I would appreciate improvement suggestions.
QUESTION
I am using the OR-tools code to optimize bus routes with distance and capacity constraints. This is the output that I got:
...ANSWER
Answered 2021-Apr-15 at 07:13By default, the arc cost for empty route aka Start -> End
is zero.
So your last two vehicle routes, being empty, will return 0 when using routing.GetArcCostForVehicle(previous_index, index, vehicle_id)
.
You can enable the cost using RoutingModel::ConsiderEmptyRouteCostsForVehicle(bool consider_costs, int vehicle)
.
Something like this should work IMHO:
QUESTION
How does one get googleortools to give back the actual cost of a vrp? This example only returns distance and loads but if I add more cost elements I would like it to show me cheapest outcome. https://developers.google.com/optimization/routing/cvrp
Thanks.
...ANSWER
Answered 2021-Apr-11 at 08:17You can retrieve it using assignment.ObjectiveValue()
(in Python)
ps: on master all VRP samples should have the objective cost in the print function ;)
QUESTION
I'm currently using Python and the Google-Or-Tools to solve an VRP problem, that I am not sure how exactly to model. (If someone has a solution with another library/tool, absolutely interested as well)
Problem Statement:
I have basically the classical CVRP problem also described and modelled on the documentation page, but with one addition. So the basic CVRP problem is, I have a depot where cargo is loaded and vehicles start from / end at. Also I have locations where goods are to be delivered to, e.g. they have a demand. Now the addition is, that I not only dropoff goods at the specific locations but also want to pickup goods at the same locations, and eventually dropping them off at the depot again.
Since it is possible for a location to have more goods to pickup than to dropoff, I need to explicitly check this, too ... but I can't find a way so far to do this.
Example: So say I have one Depot node 0 and two location nodes (A,B).
- At location A I need to dropoff 10 units and pickup 11.
- At location B I need to dropoff 10 units and pickup 9.
Now for a vehicle with max capcity 20 the possible solution would be:
- 0 --> B --> A --> 0
First visiting A and then B would not work, since it would violate the capacity constraint in A.
What I've tried:
So to consider the basic dropoff capacity constraint I have the standard
...ANSWER
Answered 2021-Apr-09 at 07:55IIRC, already answered on the mailing list.
Here a gist with a sample: Mizux/vrp_collect_deliver.py
Basically you'll need two dimensions.
- One to track only deliveries goods
- One to track the total load (pickup and delivery)
- One constraint on start nodes to make both dimension cumul vars equals.
Main idea: Having two dimensions instead of one, will avoid the solver to use pickup goods to perform deliveries.
Field Start A B End Deliveries 0 -10 -10 0 Total 0 -10+11 -10+9 0QUESTION
I'm trying to use OR-Tools' Routing Solver to solve a Multi Trip Capacitated VRP. What I need is
- one depot, route starts and ends here.
- one unloading location (different from the depot)
- set time window and demand for each node
So the vehicles should pick up the goods from each node until the capacity is filled. Then go to "unloading location", unload all their weight and keep collecting the demand from nodes until a time limit is reached or all the goods are collected. Then return back to the depot.
CVRP Reload Example seems very close but in my case, at the end of the route vehicles should visit the unloading location before the depot. In other words a vehicle can not go to the depot (starting, ending location) with load.
Example:
...ANSWER
Answered 2021-Mar-17 at 10:50Simply add
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install CVRP
You can use CVRP like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the CVRP component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page