Help implementing soft time windows

368 views
Skip to first unread message

hfarkhoor24

unread,
Nov 16, 2014, 11:32:56 PM11/16/14
to jsprit-ma...@googlegroups.com
Hi,

I'm trying to implement soft time windows (e.g. penalizing for early/lateness instead of disallowing it, so that jobs never go unassigned).

I followed the suggestions given in this StackOverflow question by implementing:
  1. SoftActivityConstraint and adding it to the ConstraintManager
  2. 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.

What am I missing in my implementation? Any pointers would be immensely helpful.

Thanks,
Heerad
sample_problem.java
SoftTimeWindowConstraint.java

hfarkhoor24

unread,
Nov 25, 2014, 3:29:19 AM11/25/14
to jsprit-ma...@googlegroups.com
Bumping this. Any help in the right direction would be much appreciated, as I've hit a wall on this!

He Huang

unread,
Oct 1, 2015, 3:30:29 AM10/1/15
to jsprit-mailing-list
A note for myself (as I suppose the OP would not care any more after almost one year):

1) newAct.getArrTime() and newAct.getEndTime() are always 0, and thus the arrival time and end time for newAct should be calculated like arrTimeAtNewAct and endTimeAtNewAct, respectively, in VehicleDependentTimeWindowConstraints;
2) the way that the route end time is calculated is incorrect - actually, route.getEnd().getArrTime() would be it;
3) as Stephan suggested in other posts: "keep in mind that the insertion of a new activity does not only have a local impact, i.e. on the two neighboring activities, but it can have an impact on the whole route since it shifts all subsequent activities".
Reply all
Reply to author
Forward
0 new messages