Hi grantm009 , I am facing the same issue as you mentioned in this thread. I have added the following Hard constraint snippet which solved yours. Please go through the following snippet and response and let me know where i am going wrong.
My Code snippets for hard type constraint are as follows.
static class NoPickupWhenDeliveryInTruck implements HardActivityConstraint {
private StateManager stateManager;
private StateId stateId;
NoPickupWhenDeliveryInTruck(StateManager stateManager) {
this.stateManager = stateManager;
this.stateId = this.stateManager.createStateId("currentVehicleLoad");
}
@Override
public ConstraintsStatus fulfilled(JobInsertionContext jobInsertionContext, TourActivity prevAct,
TourActivity newAct, TourActivity nextAct, double departureTimeAtPrevAct) {
if((newAct instanceof PickupShipment) &&
(!(nextAct instanceof End) &&
!(nextAct instanceof PickupShipment))){
if(isDepot(newAct.getLocation().getId()))
return ConstraintsStatus.NOT_FULFILLED_BREAK;
}
return ConstraintsStatus.FULFILLED;
}
The solution that i still get is as follows
route | vehicle | activity | job | arrTime | endTime | costs |
±--------±---------------------±----------------------±----------------±----------------±----------------±----------------+
| 1 | 10427333 | start | - | undef | 300 | 0 |
| 1 | 10427333 | pickupShipment | 18 | 300 | 300 | 0 |
| 1 | 10427333 | pickupShipment | 15 | 300 | 300 | 0 |
| 1 | 10427333 | pickupShipment | 20 | 300 | 300 | 0 |
| 1 | 10427333 | pickupShipment | 12 | 300 | 300 | 0 |
| 1 | 10427333 | deliverShipment | 12 | 321 | 351 | 21 |
| 1 | 10427333 | deliverShipment | 15 | 374 | 404 | 44 |
| 1 | 10427333 | deliverShipment | 20 | 421 | 451 | 61 |
| 1 | 10427333 | pickupShipment | 32 | 470 | 500 | 80 |
| 1 | 10427333 | deliverShipment | 32 | 521 | 521 | 101 |
| 1 | 10427333 | pickupShipment | 17 | 521 | 521 | 101 |
| 1 | 10427333 | pickupShipment | 27 | 533 | 563 | 113 |
| 1 | 10427333 | pickupShipment | 4 | 574 | 574 | 124 |
If the arrTime & endTime is same, it means the vehicle is at depot as per the logic i have put.
As you can see above, after 4 pickup (18,15,20,12) at depot, It only delivered (12,15,20) and picked up (32 - on the way pickup -Not depot) and returned to the depot to deliver (32) with (18) still inside truck(Vehicle). Any Help would be appreciated.