I’m trying to use Jsprit constraints to ensure that a solution route has a specific set of services… Given the services [S1, S2, S3, ..., S10]
, I want to ensure that services [S2, S4, S6]
occur in the same route…
For this, I am using HardRouteConstraint
…
@Override
public boolean fulfilled(JobInsertionContext context) {
// jobIds = [S2, S4, S6]
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;
}
This works partially fine… If S2
, S4
and S6
are part of the solution, they appear in a single route, and are not split between different routes…
The problem is that if I have a limited vehicle capacity (say, 3), Jsprit can possibly return a solution like:
Routes: [
[S1, S2, S3]
[S5, S7, S8]
[S9, S10]
]
Unassigned Jobs: [S4, S6]
This is understandable, but not what I want… I want that if a route includes S2
, it should also include S4
and S6
, in any order…
How can I ensure that a valid solution does not contain such routes: [X, S2, Y]
or [S2, X, S4]
…
Thanks,
Asim