| Forum | GitHub | Maps | Blog

How to group related jobs in same vehicle


I would like to group jobs in same vehicle like this cas
group 1: shipment_0, shipment_1
group 2: shipment_2, shipment_3

I have Vehicle_1 and Vehicle_2
the result must be either group1 and group2 in same vehicle
or each group in a vehicke
vehcile1: group1 and group2
vehicle1: group1 or group2
vehicle2: group1 or group2

I implemented the code below but it didn’t worked well
// Preformatted text
public boolean fulfilled(JobInsertionContext context) {
Job thisJob = context.getJob();
if (jobIds.contains(thisJob.getId())) {
for (String jobId : jobIds) {
VehicleRoute route = stateManager.getProblemState(stateManager.createStateId(jobId), VehicleRoute.class);
// if the jobs are assigned to a different route, reject this route
if (route != null && route != context.getRoute()) return false;
return true;

In fact, it groups shipment_0, shipment_1 and shipment_3 in same vehicle
but shipment_2 either in unassignedjobs or in vehicle_2
it seems like it tries to use minimum of vehicles or try to minimize return to start location (vehicles have same start location)