2014-08-28 321 views
1

我嘗試使用jsprit解決具有多個TimeWindows的VRP。因此,我創建了一個新的約束類,其中包含一個將「TimeWindowsNotAvailable」類與服務關聯的Map。具有多個時間窗口的Jsprit VRP

「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

您現在還不能對多個時間窗口進行建模,但它將被實施。目前,你可以實現你自己的。假設您有一個服務的下列兩個時間窗口:(e1,l1),(e2,l2)其中e表示最早的操作開始和最晚的。如果是e2,則實施起來相當「容易」。只要看看我如何實現單一的硬時間窗口。看看哪個是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); 
+0

非常感謝!我會在考試後嘗試;) – 2014-09-22 23:27:25