带有多个Time Windows的Jsprit VRP

时间:2014-08-28 11:20:01

标签: window jsprit

我尝试使用jsprit来解决多个TimeWindows的VRP。因此,我创建了一个新的Constraint-Class,它包含一个Map,它将“TimeWindowsNotAvailable”类与服务相关联。

“TimeWindowsNotAvailable”类包含无法完成服务的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;
    }
}

1 个答案:

答案 0 :(得分:1)

您无法立即对多个时间窗口进行建模,但它将会实施。目前,您可以实施自己的。假设您有一个服务的以下两个时间窗口:(e1,l1),(e2,l2)其中e表示最早的操作开始,l表示最新的操作。如果l1&lt; e2,它是相对容易的&#34;容易&#34;实施。看看我是如何实现单个硬时间窗口的。看看哪个是TimeWindowConstraintwhich is the practical time window state updater。您可能只需要对这些类进行少量修改,因此只需复制它们并添加多个时间窗口,并将这两个新类添加到State-和ConstraintManager中(不要忘记取消激活默认时间窗口约束/ stateUpdater)。

newAct没有任何arrTime,因为它尚未插入到路径中,并且仍然需要确定最佳插入位置(通过检查约束和计算边际插入成本)。但您可以按如下方式轻松计算:

double newActArrTime = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), prevActDepTime,iFacts.getNewDriver(),iFacts.getNewVehicle);
相关问题