jsprit icon indicating copy to clipboard operation
jsprit copied to clipboard

multiple breaks for vehicles

Open TomekWU3 opened this issue 10 years ago • 39 comments

Hi there!

Just like spoken in the graphhopper-forums i post here an issue for the feature "multiple breaks". This could help people plan routes for multiple days/weeks/months, what is just what I and also may other people need :)

Thanks

Patrick

TomekWU3 avatar Jan 26 '16 16:01 TomekWU3

Would you need an AND or OR connection between multiple breaks. When it comes to multiple time windows, it is an OR connection, e.g. either time window A or time window B.

oblonski avatar Jan 29 '16 07:01 oblonski

Hi!

In my problem I would need an AND connection between the breaks. I would use this in the following context:

Every break is an timewindow that the vehicle dont need to work. I want to plan tours for a long time (week, month, maybe year...) and i get some information about initial routes and about vacation. Normaly vehicles shouldnt work at sunday so i would give this vehicles a 8h(or working time) break. Some could work saturday, some could work a half day and so on. If someone has vacation, i´ll give him also a break so he will not be planed this day.

I thought about making this problem to another. I had an idea that i would make some "dummy" services that represent the "break" and give the vehicle and the service an unique skill so that i have to say "sorry little algorithm, only vehicle2 can make at this day the service2 because the service requires skill "break_mrBean1" and this skill has only vehicle2."

But multiple breaks with and AND connection would be a little bit better :)

TomekWU3 avatar Jan 29 '16 08:01 TomekWU3

Hi, We have a application similar to SolomonWithSkillsExample and i am trying to leverage this example to use in my application. 1 . Is it possible to add multiple breaks for a vehicle in SolomonWithSkillsExample? 2. I was able to add only one break to the vehicles defined in SolomonWithSkillsExample. The results looks like the break was assigned to only one of the vehicle in the example not for all the vehicles in that example even though i am assigning breaks for all the vehicles.

What could be the reason for this?

Attaching the results of that example with the breaks defined.but the break was assigned to only one of the vehicle -skill1_vehicle_2

solomon_with_skills - Copy.txt

Simbu1988 avatar Feb 01 '16 22:02 Simbu1988

@Simbu1988 How did you define your breaks?

oblonski avatar Feb 02 '16 08:02 oblonski

This is how i define my breaks. SolomonReader:

Break sBreak = Break.Builder.newInstance("Lunch") .setTimeWindow(TimeWindow.newInstance(200, 200)).setServiceTime(20).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("solomonVehicle").setEarliestStart(start).setLatestArrival(end) .setStartLocation(Location.Builder.newInstance().setId(customerId) .setCoordinate(coord).build()).setType(vehicleType).setBreak(sBreak).build(); vrpBuilder.addVehicle(vehicle);

SolomonWithSkillsExample:

VehicleImpl skill1Vehicle = VehicleImpl.Builder.newInstance("skill1_vehicle_" + i).addSkill("skill1") .setStartLocation(Location.Builder.newInstance().setId(solomonVehicle.getStartLocation().getId()).setCoordinate(solomonVehicle.getStartLocation().getCoordinate()).build()) .setEarliestStart(solomonVehicle.getEarliestDeparture()) .setBreak(solomonVehicle.getBreak()) .setType(newType).build(); VehicleImpl skill2Vehicle = VehicleImpl.Builder.newInstance("skill2_vehicle_" + i).addSkill("skill2") .setStartLocation(Location.Builder.newInstance().setId(solomonVehicle.getStartLocation().getId()) .setCoordinate(solomonVehicle.getStartLocation().getCoordinate()).build()) .setEarliestStart(solomonVehicle.getEarliestDeparture()) .setBreak(solomonVehicle.getBreak()) .setType(newType).build(); skillProblemBuilder.addVehicle(skill1Vehicle).addVehicle(skill2Vehicle);

Simbu1988 avatar Feb 02 '16 15:02 Simbu1988

hmm. try to assign unique break objects to your vehicles such as "skill1VehicleBreak", "skill2VehicleBreak". probably you just defined one break object and assigned it to several vehicles, however each vehicle requires its own break object.

we should make the problem builder throw an exception in case a single break object is assigned to several vehicles.

oblonski avatar Feb 02 '16 15:02 oblonski

It worked after creating a unique break object.However in the same example , without any breaks all the jobs are assigned to a vehicle.but after adding the breaks to all the vehicle 1 job was unassigned. why does this happening so?

I have a another question also. In our application we define multiple breaks for a vehicle.How to add those?

Simbu1988 avatar Feb 02 '16 16:02 Simbu1988

Maybe your time constraints are too tight (operation time of driver) ?

Multiple breaks are not possible yet (see discussion above).

BTW: Would you mind to ask latter kind of question in the forum? Great. Thanks.

oblonski avatar Feb 02 '16 16:02 oblonski

Hi, I'm trying to solve a problem with AND conditions between multiple breaks for vehicle, is there a way to implement such constraint yet?

t0r0id avatar Jun 08 '16 09:06 t0r0id

Hi, we need this feature as well to model multiple day vehicle routing in which each vehicle has different (multiple) break times during the whole time horizon for rest, maintenance, etc.

Really appreciate it.

61508060 avatar Aug 10 '16 03:08 61508060

Any chance that this feature Driving time dependent break scheduling - beta release will be available in jsprit?

stefan-- avatar Jan 03 '17 14:01 stefan--

We need multiple breaks per vehicle as well.

If it is difficult to program for multiple breaks, would it be easier if you could use a Service with no Location? Does that make sense? @oblonski

seriouscoderone avatar Sep 22 '17 23:09 seriouscoderone

could use a Service with no Location I think this should work when optimizing for single vehicle. When working with multiple vehicles add skill for both service and vehicle unique for each worker. For each break create a service that reflects the time windows in which a break can occur. Set break service as high priority. When the distance matrix is produced add 0 travel times for each break to each non break location.

Let Jsprit optimize this, then remove the no location breaks from the routing request, after the routing request returns add the breaks back and adjust the arrival time to the places where the breaks were inserted in the optimized solution. Any thought on this approach before I give it a try?

peterdn1 avatar Oct 13 '17 17:10 peterdn1

As per the comment above, we are doing the following and it seems to be working:

a. Create a skill for each vehicle called "break" b. Each break would be a service with an empty location (0,0) and a required skill of break c. In the matrix, i.e. whatever extends AbstractForwardVehicleRoutingTransportCosts implements TransportDistance; just return 0 in getDistance, getTransportCost, and getTransportTime when one of the locations is your break service d. If the break is fixed such as lunch give it a high priority e. 2 other floating breaks one in the am one in the pm f. The solution produced looks good actually and seems to make sense g. When submitting to the router, remove the dummy services and just add the break time to the stopover time

here is an example solution result with the above breaks:

+--------------------------------------------------------------------------------------------------------------------------------+ | detailed solution | +---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+ | route | vehicle | activity | job | arrTime | endTime | costs | +---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+ | 1 | 56 | start | - | undef | 0 | 0 | | 1 | 56 | service | 255918 | 21 | 41 | 21 | | 1 | 56 | service | 255924 | 45 | 65 | 25 | | 1 | 56 | service | break:56:floating_am | 65 | 80 | 25 | | 1 | 56 | service | 255937 | 80 | 100 | 25 | | 1 | 56 | service | 255936 | 101 | 121 | 26 | | 1 | 56 | service | 255929 | 124 | 144 | 29 | | 1 | 56 | service | 255921 | 155 | 175 | 40 | | 1 | 56 | service | 255837 | 178 | 198 | 43 | | 1 | 56 | service | 255926 | 200 | 220 | 45 | | 1 | 56 | service | 255932 | 224 | 244 | 49 | | 1 | 56 | service | 255834 | 250 | 270 | 55 | | 1 | 56 | service | break:56:lunch | 270 | 300 | 55 | | 1 | 56 | service | 255831 | 300 | 320 | 55 | | 1 | 56 | service | 255946 | 352 | 372 | 87 | | 1 | 56 | service | 255943 | 372 | 392 | 87 | | 1 | 56 | service | break:56:floating_pm | 392 | 407 | 87 | | 1 | 56 | service | 255803 | 407 | 427 | 87 | | 1 | 56 | end | - | 455 | undef | 115 | +--------------------------------------------------------------------------------------------------------------------------------+

Again once the breaks are removed and the it is routed, the gpx produced is valid and reasonable!

mikeppp avatar Oct 13 '17 21:10 mikeppp

Doesn't this mean you can teleport between locations by going via a break? I suspect this would distort routes in the optimiser.

PGWelch avatar Oct 13 '17 21:10 PGWelch

Yes that is correct actually. However until jsprit supports more than one break its the best solution...

mikeppp avatar Oct 13 '17 22:10 mikeppp

Also in our case distances are fairly all close together and time windows are not that long. our HARD requirements are: a. floating break am; b. fixed lunch; c. floating pm break

If anyone has a better solution please ket me know!

mikeppp avatar Oct 13 '17 22:10 mikeppp

PGWelch -agree.

What if costing function added an additional argument that was the previous service.
So 3 services A- service B- break C -service The time from the A to B would be 0 The time from B to C would time from A to C

I think this would address your observation of teleportation using breaks, but unfortunately would involve changing core. Any other suggestions?

peterdn1 avatar Oct 13 '17 23:10 peterdn1

This is huge for us. +1

If you only needed to route for one vehicle, would it be possible to string along "fictional" vehicles to pick up where the previous vehicle left off, as a temporary hack?

CalebRoyer avatar Nov 09 '17 01:11 CalebRoyer

Has anyone found a solution for this?

LCenteleghe avatar Feb 23 '18 17:02 LCenteleghe