我尝试使用jsprit来解决多个TimeWindows的VRP问题。因此,我创建了一个新的约束类,它包含一个映射,该映射将"TimeWindowsNotAvailable"-class与服务相关联。
"TimeWindowsNotAvailable"-class包含无法完成服务的TimeWindows列表(例如,客户不在家等)。主要的问题是,newAct.getArrTime()始终是0.0,尽管在VRP的解决方案中可以看到arrTime不是0.0。
有人知道我如何解决这个问题吗?还是多个TimeWindows更难实现?
public class TimeConstraint implements HardActivityStateLevelConstraint {
private Map<Service, TimeWindowsNotAvailable> notAvailableMap;
private RouteAndActivityStateGetter states;
private VehicleRoutingTransportCosts routingCosts;
public TimeConstraint() {
super();
}
public boolean checkDepTime(Service service, Double depTime){
TimeWindowsNotAvailable timeWindowsNotAvailable = notAvailableMap.get(service);
if(timeWindowsNotAvailable == null) return true;
System.out.println(depTime);
return timeWindowsNotAvailable.isAvailable(depTime);
}
public void setNotAvailableMap(Map<Service, TimeWindowsNotAvailable> notAvailableMap){
this.notAvailableMap = notAvailableMap;
}
@Override
public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
Service currentService = (Service)iFacts.getJob();
if(checkDepTime(currentService, **newAct.getArrTime()**)) return ConstraintsStatus.FULFILLED;
return ConstraintsStatus.NOT_FULFILLED;
}
}发布于 2014-09-05 06:46:25
您还不能对多个时间窗口进行开箱即用的建模,但它将被实现。目前,您可以实现您自己的。例如,假设服务有以下两个时间窗口:(e1,l1),(e2,l2),其中e表示最早的操作开始和l最新操作。如果l1 < e2,则实现起来相当“容易”。看看我是如何实现单一硬时间窗口的。看看哪个是TimeWindowConstraint和哪个是实用的时间窗口状态更新器?。您可能只需要对这些类进行轻微的修改,所以只需复制它们并添加多个时间窗口,并将这两个新类添加到您的状态-和ConstraintManager (不要忘记禁用默认的时间窗口约束/状态更新程序)。
newAct没有任何arrTime,因为它还没有插入到路由中,最佳插入位置仍有待确定(通过检查约束和计算边际插入成本)。但是,您可以轻松地按以下方式计算它:
double newActArrTime = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), prevActDepTime,iFacts.getNewDriver(),iFacts.getNewVehicle);https://stackoverflow.com/questions/25547563
复制相似问题