-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to add capacity to vehicles? #54
Comments
This inconsistency is because the initial problem is defined with no capacity (zero-length capacity array). On the C++ side, we have a @jonathf will be able to comment further and it looks like he already fired a related PR (#55). |
The canonical way is to pre-define the capacity in the init with I've pushed the changes to version 0.0.11. Let me know if that works for you. |
Thanks for the quick help! Version 0.0.11 works fine for the above code. After setting the vehicle capacity, how can I add the load size for jobs? I tried: problem_instance.add_job(
vroom.Job(id=1414, location=1, delivery=[10])
) But it says:
|
There is a difference between "jobs" and "shipments". Jobs assumes single jobs, and shipments assumes one pickup and one delivery. Pickups are signified by using the This is a bit work in progress, and I am looking into improving this interface, if that makes sense. |
@jonathf Thanks a lot for the kind explanation. It was very helpful to understand the concepts used in vroom. This is what I ended up with: import vroom
problem_instance = vroom.Input()
problem_instance.set_durations_matrix(
profile="car",
matrix_input=[[0, 2104, 197, 1299],
[2103, 0, 2255, 3152],
[197, 2256, 0, 1102],
[1299, 3153, 1102, 0]],
)
problem_instance.add_vehicle(
vroom.Vehicle(0, start=0, end=0, capacity=[25])
)
problem_instance.add_shipment(
vroom.JobPickup(id=101, location=0, amount=vroom.Amount([10])),
vroom.JobDelivery(id=102, location=1, amount=vroom.Amount([10]))
)
problem_instance.add_shipment(
vroom.JobPickup(id=201, location=0, amount=vroom.Amount([12])),
vroom.JobDelivery(id=202, location=2, amount=vroom.Amount([12]))
)
problem_instance.add_shipment(
vroom.JobPickup(id=301, location=0, amount=vroom.Amount([15])),
vroom.JobDelivery(id=302, location=3, amount=vroom.Amount([15]))
)
solution = problem_instance.solve(exploration_level=5, nb_threads=4)
solution.routes Just one more question about |
This way you can input an arbitrary number of restrictions (e.g. weight, volume, number of boxes) and you get to choose which metrics are relevant for your use-case.
Note that the A |
@jcoupey Thanks a lot!! problem_instance.add_shipment(
vroom.Job(id=101, location=0, pickup=vroom.Amount([10])),
vroom.Job(id=102, location=1, delivery=vroom.Amount([10]))
) Is this what you mean? |
I'm not familiar with how the python bindings work but yes, that would be something along those lines. Again it does not make a real difference if you're working with typical academic CVRP (single-depot-delivery-only) benchmarks but the bottom line is that you can define linehauls or backhauls this way. |
That is correct, though the problem_instance.add_shipment(
vroom.Job(id=101, location=0, pickup=[10]),
vroom.Job(id=102, location=1, delivery=[10])
) |
Thanks a lot guys. Well, what about the multi-depot problem, when each shipment's pickup location can be any of the available depots? For example, if we have locations problem_instance.add_shipment(
vroom.Job(id=101, location=0 or 1, pickup=[10]),
vroom.Job(id=102, location=3, delivery=[10])
) |
You only really want to use shipments in a "real" pickup-and-delivery setup (e.g. for PDPTW). It makes sense when pickup and delivery locations are scattered all over the place, but other situations can be modeled with jobs (single-location tasks).
Simply describe the deliveries as |
Good question. I'd like to know if that is possible too. Not my expertice, so I am limited to asking questions on this. I'm not sure I understand your answer @jcoupey. If you add a Also, are you saying that the only way to achieve multi-depot, you need to force the vehicles to start and/or end at the various start depot locations? |
@jcoupey I have this code: import vroom
problem_instance = vroom.Input(amount_size=1)
problem_instance.set_durations_matrix(
profile="car",
matrix_input=[[0, 100, 100, 100],
[100, 0, 100, 1],
[100, 100, 0, 100],
[100, 1, 100, 0]],
)
problem_instance.add_vehicle(
vroom.Vehicle(0, start=0, end=0, capacity=[200])
)
problem_instance.add_vehicle(
vroom.Vehicle(1, start=1, end=1, capacity=[10])
)
problem_instance.add_job(
vroom.Job(id=102, location=2, delivery=[10])
) The last line generates this error:
|
Maybe we have some mismatch between the initial C++ API and the current python binding, but I'm referring to the
Probably there is a confusion here: a
Not the only way but the most efficient. If you define a pickup place at the depot location for each delivery, you're artificially doubling the size of the problem. Plus in that case you end up with the problem from previous comment were you need to pre-assign deliveries to depots. You don't have to do this if you define one
Looks legit AFAICT but again I have no clear visibility on how the definitions work from the python bindings. |
You are right, I made a mistake when creating the bindings for shipment. I'm putting fixing this on the top of my todo-list for pyvroom. |
I've made a new relase version 0.0.14 now. There is a small descrepency between the C++ code and the API, and I've chosen to mimic the API for now. That means shipment = vroom.Shipment(
pickup=vroom.ShipmentStep(id=1, location=1),
delivery=vroom.ShipmentStep(id=2, location=2),
)
problem_instance.add_job(shipment) or for convinience, use problem_instance.add_shipment(
pickup=vroom.ShipmentStep(id=1, location=1),
delivery=vroom.ShipmentStep(id=2, location=2),
) Let me know if it works well. |
Sorry for asking a question here. I couldn't find an appropriate forum. Please let me know if there is a better place for asking questions about pyvroom.
I'm trying to solve CVRP and couldn't figure out how to add the vehicle capacity.
This code generates the following error:
What is the correct way? Thanks for help!
The text was updated successfully, but these errors were encountered: