3 Questions: Endlocation and Multiple Vehicles


ad 1) just add 5 drivers and solve the problem. Each driver can then be assigned to a specific day.

ad 2) set returnToDepot to false, then routes will be open.

Does this solve your problem?


Thanks for the advice I will look if this helps! Would it be somehow possible to build an constraint to tell the vehicle to return to the depot after some time?

I have another question.

Would it be possible to make a “day constant” for the time window calculation in the algorithm?`

For example a day in the progam means 2400 as a number. And there are many services that have timewindows. For example there is a service with the timewindow 1000|1200. So the vehicle could visit this service between 1000 and 1200 but also between 3400 and 3600 (at the next day). So the algorithm should make a new calculation for timewindows with a modulo of 2400.

This should not be so hard i think.

Hi @patrick_wisniewski19 ,

“Multiple time windows” feature has been implemented by Stefan, but needs to be verified. I think you can use your problem to verify it.

See this post.

Best regards,

Try the new multiple time window feature in the master branch. Here you
can just add arbitrary time windows. Thus you should be able to model this.

Am 20/01/16 um 10:27 schrieb patrick_wisniewski19:

Yes stefan thanks this solves some of mine problems and brings me near to the goal :slightly_smiling:

So if you want i can make also an test and can post my results.

So now i have a new question so maybe you can help me with it too :smiley:

In my problems it can be, That i have a service that needs a cuple of days to be done. I will make sure for the programm that the services will be split into multiple services with normal workingdays. So for example i have a service in my database that needs 24H so i will cut them into 3*8H services with fitting timewindows.
So my question is: Is there a possibility to make an constraint or an other way to tell the programm that “these 3 services have to be done from the same vehicle”? Because in my context it does not make sence for vehicle1 to begin with service1_1(First cutted service from service1) and service1_2 is done by vehicle2. Its not necessary to have an feature that fixes but it would help me a little bit :slightly_smiling:

thanks for the help till now :smiley:

Hi @patrick_wisniewski19,

This kind of relationship between jobs (multiple jobs must go to the same route) can be modeled by making use of custom constraints at route level.

Below are a few links which might be helpful:

Stefan’s list of job relationships that can be modeled; and

A few examples on stackoverflow.

Best regards,

1 Like

It would be great if you could test it (multiple tw) and share your experience with us :slightly_smiling:

@jie31best Thank you i will have a look at this sites and try to make it fit to my problem.

@stefan Okay i will try to make a scenairo and help with my tests

1 Like

Hi again :slightly_smiling:
I made some “generators” that create services with random locations and multiple timewindows (for me multiple days). Its not realy realistic because it sets every tw at the same time, but normaly beginning and ending is varius. This is only made to learn a bit from the code and about the performance.

How do you want to share my excperience? Should i post my code? Its quite simple though with random locations and generating multiple tw.

I have different results of the benchmark-time with different algorithm configs.

Hi Patrick,

Great. Share your results here: Need help to verify multiple time window feature. It would be great you shared not only data but also reasoning why you think results are good or bad, and for example hyphothesises that you think multiple tws are not considered appropriately. Thanks so much.


Hi to all!

@stefan thank you some much for the great support of jsprit. It helps me very much with my problems and is very nice implemented!

But now again, I have a question. I am trying to work with costMatrix and this feature is very nice! But somehow I am missing an feature or i can´t see it…
I would like to import an costMatrix that is pre calculated and based on this matrix i would like to have the results. But on the other hand i would like to have after the calculation a plot, some visualisation of this problem. It would be cool if every location/service/vehicle would have its own x and y coordinates and would calculate the routes by the costMatrix. Would this be possible? Or is the algorithm generating its own x and y coordinates and could plot them?

If not it is no problem. Thanks for the answer!


You can assign xy coordinates to vehicle- and job-locations. At the same time, you can consider your own travel times and distances. This way, you should be able to plot your solution. However, if you use lon/lat, you might be better off to transform these coordinates to appropriate x-y coordinates. For example, lon/lat usually comes in WGS84. If you have coodinates in Berlin then project these coordinate for example to DHDN (EPSG:3068). I usually use GeoTools for these kind of projections.
Is this the answer of your question?

This is just how i thought. But I see that if i assign x and y coodinates the location has no ID. And for me it looks like the costMatrix is working with location-id´s or not?


I found out that there is an ID. It is build with the coordinates. I will try out working with this ID´s. But: Would it be possible to change this ID?

try this: Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(x,y)).setId(id).setIndex(index).build();

Ok thanks it worked :slightly_smiling:
I have two new questions:

For which case I need the Index of a Location? And

What is the difference between the VehicleRoutingTransportCostsMatrix
and FastVehicleRoutingTransportCostsMatrix?

VehicleRoutingTransportCostsMatrix references with the ID and
FastVehicleRoutingTransportCostsMatrix references with the Index.
Are there other differences?

Correct. FastMatrix is faster :wink: since it stores times and distances in an array based on location indeces. In contrary, VehicleRoutingTransportCostsMatrix stores data in a map based on ids which is comparably expensive.

Okay thanks :slightly_smiling:

Sorry but again, I have new questions.

In my problems it could be, that whole tours are planed by some user itself. Initial routes would be planed and may not be optimal(even with broken constraints). I thought about to may use jsprit so validate the pre-planed solution. My idea would be to run the algorithm with 0 iterations and then tell in the console: Your planed tours have a distance of 10000. 20 Time window contstraints are broken. 30 Skill constraints are broken…
I dont know the algorithm and its theory but may it be possible to get some functional information about the solution? If yes it would be great. Because then jsprit could make a normal run with no initial routes and the user can see that the calculated solution is better then the own solution.

What do you think?

Use the SolutionAnalyser to get various information such as broken time windows etc. … It should also be easy to calculate your own indicators based on a predefined set of vehicle routes.

Okay. Thanks the examples show me how it works with distances and transporttimes. To make a count how much skill or timewindow constraints are broken i should look. But this is not a high piority problem of mine.

Thanks for the help!