Hey guys,
I’m having trouble with my hard constraint not being applied to a solution.
Some background: I’m trying to solve a similar problem to VRP but not exactly so I’m using Jsprit with constraints to model my problem.
Trailers are zero weighted deliveries with a priority of 10 (ie the lowest priority). I have a constraint below that is attempting to prevent two trailers being taken in a row but as you can see in the solution below it, “vehicle2” takes on 3 trailers in a row, namely trailer4, trailer6 and dummy. This constraint is the only one being applied, I removed the others in an attempt to debug.
static class NoTrailersInARow implements HardActivityConstraint {
@Override
public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct,
TourActivity nextAct, double prevActDepTime) {
if(isInstanceOfDelivery(prevAct) && isInstanceOfDelivery(newAct)) {
return ConstraintsStatus.NOT_FULFILLED;
}
if(isInstanceOfDelivery(newAct) && isInstanceOfDelivery(nextAct)) {
return ConstraintsStatus.NOT_FULFILLED;
}
return ConstraintsStatus.FULFILLED;
}
private boolean isInstanceOfDelivery(TourActivity act) {
return act.getName().equals("delivery");
}
}
+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+
| route | vehicle | activity | job | arrTime | endTime | costs |
+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+
| 1 | vehicle | start | - | undef | 0 | 0 |
| 1 | vehicle | delivery | TRAILER1 | 10 | 10 | 10 |
| 1 | vehicle | pickupShipment | JOB1 | 12 | 12 | 12 |
| 1 | vehicle | deliverShipment | JOB1 | 13 | 13 | 13 |
| 1 | vehicle | delivery | TRAILER2 | 29 | 29 | 29 |
| 1 | vehicle | pickupShipment | JOB3 | 38 | 38 | 38 |
| 1 | vehicle | deliverShipment | JOB3 | 42 | 42 | 42 |
| 1 | vehicle | end | - | 47 | undef | 47 |
+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+
| 2 | vehicle2 | start | - | undef | 0 | 0 |
| 2 | vehicle2 | delivery | TRAILER4 | 8 | 8 | 8 |
| 2 | vehicle2 | delivery | TRAILER6 | 18 | 18 | 18 |
| 2 | vehicle2 | delivery | DUMMY | 20 | 20 | 20 |
| 2 | vehicle2 | delivery | TRAILER8 | 24 | 24 | 24 |
| 2 | vehicle2 | pickupShipment | JOB6 | 29 | 29 | 29 |
| 2 | vehicle2 | deliverShipment | JOB6 | 34 | 34 | 34 |
| 2 | vehicle2 | delivery | TRAILER5 | 50 | 50 | 50 |
| 2 | vehicle2 | pickupShipment | JOB5 | 51 | 51 | 51 |
| 2 | vehicle2 | deliverShipment | JOB5 | 57 | 57 | 57 |
| 2 | vehicle2 | delivery | TRAILER7 | 77 | 77 | 77 |
| 2 | vehicle2 | pickupShipment | JOB4 | 84 | 84 | 84 |
| 2 | vehicle2 | deliverShipment | JOB4 | 89 | 89 | 89 |
| 2 | vehicle2 | end | - | 100 | undef | 100 |
+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+
| 3 | vehicle3 | start | - | undef | 0 | 0 |
| 3 | vehicle3 | delivery | TRAILER3 | 21 | 21 | 21 |
| 3 | vehicle3 | pickupShipment | JOB2 | 29 | 29 | 29 |
| 3 | vehicle3 | deliverShipment | JOB2 | 31 | 31 | 31 |
| 3 | vehicle3 | end | - | 53 | undef | 53 |
+--------------------------------------------------------------------------------------------------------------------------------+
Any help on this will be much appreciated!