I have to solve a VRPTW problem with the constraint that the solution must have a fixed number of vehicles.

I have tried to search inside the library on how to implement this constraint. Through the SolomonReader I tried to insert manually a certain nr of vehicles but this helped only in defining the max number of possible vehicles (but still it was showing solutions with a lower nr of vehicles).

How can I implement a fixed fleet size constraint?

Use this to fix the fleet size and set it to FleetSize.FINITE. This specifies the maximum number of vehicles that can be used.
If you want to specify the max number of vehicle and to use all vehicle, you need to find appropriate constraints, e.g. reduce capacity, reduce the operation time of your drivers (earliestStart and latestArrival) etcâ€¦ The logic to find such constraints is up to you and your problem. jsprit cannot determine this.

When i set FleetSize to FINITE, how can I specify the maximum number of vehicles? For example in problem rc101 i would like to fix the size to 16 routes.

As I wrote, you need to define appropriate constraints. For example,
reduce vehicleâ€™s operation time (earliestStart, latestArrival) so that
you can just serve all your customers with 16 vehicles. This is what you
need to do yourself. If you can make it manually, you should also be
able to automate it.

Thank you for your reply. Very useful sample code.
Now i only need to find a good way of forcing to use all the vehicles, without excluding some good solutions

I implemented this solution and it works! Thank you a lot @stefan
Now i want that if i have to create, for example, 10 vehicles; and i want that all of these cover all the demands so that there arenâ€™t unassigned Jobs. How can i perform it? I have to add more constrains? Or maybe i have to shape better the capacity of each vehicles?

@Hendrix: Whether or not jobs end up being unassigned can depend on many constraints such as capacity, time-window, operation time of drivers, etcâ€¦ For example, if the physical constraints of your vehicle do not allow to serve all your customers, you either need to add more vehicles, reduce the size of service (which should actually be a physical constraint as well) or increase the capacity of your vehicles.

@freddyfli I do not know. Please be more precise and give examples. The best way would be to reduce your case to a very simple one so that we can analyse the reason for your â€śbadâ€ť solution.

Last year we â€śsolvedâ€ť the problem by means of some tricks:

limit on number of vehicles: vrpBuilder.setFleetSize(FleetSize.FINITE) and instantiating the number of desired vehicles as an upper bound

soft constraint: we added penalties to solutions that didnâ€™t use all the desired vehicles. This can converge to wanted solution but could be too slow (because working on finished solutions: selection at the end)

hard constraint: in the isertionContext, we donâ€™t allow some solutions to be generated. The criteria that we followed was to put a limit of jobs per tour. The hard constraint could also have been set on the capacity of the vehicles or by playing with EarliestStart and LatestArrival

If you want to see our â€śdirty tricksâ€ť you can have a look at this repository that contains our school project. The relevant classes are Main.java that contains the soft and hard constraint, while SolomonReader.java contains the change on the fleet size.
You can find more details also in the presentation PDF

Hope this can be helpful for a better designed approach. Good luck!

Hey! @MartinoMensio Thanks for giving responded.
I read your presentation and you and your team done nice work on a project.
Is it work for finite fleet size to forcefully utilize the vehicle? Till then I have to check the code.

Thank you very much!
Yes it worked on all the instances selected in this file, but in order to work it needs a lot of iterations (because the soft constraint is applied on completely built solutions and the hard constraint is not so restricting)