Fixed Fleet Size Constraint Implementation

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.

2 Likes

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.

Am 18/12/15 um 09:47 schrieb Martino Mensio:

You will need to add 16 vehicles and set FleetSize Finite.
A piece of sample codes can be found below:

``````    VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
VehicleTypeImpl vehicleType = ...
vehicleCount = 16;
for (int i = 0; i < vehicleCount; i++) {
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle" + i)
. ...
.setType(vehicleType).build();
}
vrpBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);``````
2 Likes

Now i only need to find a good way of forcing to use all the vehicles, without excluding some good solutions

Just this code or need to add more â€¦ because it is not working.

Hi @freddyfli,

Take a look at this example and see how Stefan added multiple vehicles to vrpBuilder and defined the problem with finite fleet.

Best regards,
He

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?

Hi @stefan â€¦I have a fixed number of vehicles and there arenâ€™t unassigned jobs but the cost is bed â€¦why???

@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.

1 Like

@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.

1 Like

Hey! Have you implemented by forcing all vehicle to utilize?

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!

Martino

Hey! @MartinoMensio Thanks for giving responded.