I'm trying to implement soft time windows (e.g. penalizing for early/lateness instead of disallowing it, so that jobs never go unassigned).
- A SoftActivityConstraint and adding it to the ConstraintManager
- A SolutionCostCalculator that tacks on the penalties to the total objective function and using setObjectiveFunction()
I've attached what I have so far. Basically, I check if the newAct being inserted violates the time windows I specified. I don't check newAct against prevAct or nextAct (I shouldn't have to?) If there's a violation, the penalty I assign is of the form c*n^2 where n is how many time units early/late. I do this for both vehicle and job time windows.
Unfortunately, the included example gives an unoptimal solution. There are two Services, one of which is closeby, but whose time window starts later, and one of which is far away, but whose time window starts now. Instead of having the vehicle go to the far away service, then to the nearby service (thus incurring no lateness penalty), the outputted solution has the vehicle go to the nearby service, wait until its time window starts, service it, then head to the far service and service it late. Thus, a huge lateness penalty is incurred which should have been avoided.