簡體   English   中英

Optaplanner /時間相關的車輛路線/考慮屬於活動的客戶操作時間窗口列表

[英]Optaplanner / time dependent vehicle routing / considering list of customer operation time windows belonging to activities

尊敬的OptaPlanner用戶,

我將基於時間的車輛路徑示例作為基礎。 在這里,我刪除了所有的TimeWindowed類,例如,移動了“ TimeWindowedActivity.java”的內容,並與“ Activity.java”合並,依此類推...

現在,我想向某些活動添加客戶操作時間窗口的列表。 每個活動的這些時間窗口(列表項的數量)可以不同,或者某些活動根本沒有這樣的標簽。 通過此擴展,可以考慮只有在滿足到達時間在一定數量(列表)的客戶操作時間窗口(由“ customerOperationStartTime”和“ customerOperationEndTime”定義)之間的活動才可以執行。

為了解決這個問題,我創建了一個類“ CustomerOperationTimes.java”:

public class CustomerOperationTimes {

    private Long customerOperationStartTime;
    private Long customerOperationEndTime;

    public Long getCustomerOperationStartTime() {
        return customerOperationStartTime;
    }

    public void setCustomerOperationStartTime(Long customerOperationStartTime) {
        this.customerOperationStartTime = customerOperationStartTime;
    }

    public Long getCustomerOperationEndTime() {
        return customerOperationEndTime;
    }

    public void setCustomerOperationEndTime(Long customerOperationEndTime) {
        this.customerOperationEndTime = customerOperationEndTime;
    }
}

在Activity.java中,我添加了:

private CustomerOperationTimes customerOperationTimes;
private List<CustomerOperationTimes> customerOperationTimesList ;

public CustomerOperationTimes getCustomerOperationTimes() {
    return customerOperationTimes;
}

public void setCustomerOperationTimes(CustomerOperationTimes customerOperationTimes) {
    this.customerOperationTimes = customerOperationTimes;
}

public List<CustomerOperationTimes> getCustomerOperationTimesList() {
    return customerOperationTimesList;
}

public void setCustomerOperationTimesList(List<CustomerOperationTimes> customerOperationTimesList) {
    this.customerOperationTimesList = customerOperationTimesList;
}

為了進行測試,我創建了一個具有單個活動的xml文件:

…
    <activityList id="33">
        <Activity id="34">
            <activityID>1</activityID>
            <activityStatus>101</activityStatus>
            <location reference="7" />
            <appointmentStartTime>1395317700</appointmentStartTime> <!-- Unix time in sec => 2014/03/20 12:15:00 -->
            <appointmentEndTime>1395324900</appointmentEndTime>     <!-- Unix time in sec => 2014/03/20 14:15:00 -->
            <plannedWorkDuration>4500</plannedWorkDuration>         <!-- in sec => 75min duration -->
            <customerOperationTimesList id="100">
                <customerOperationTimes id="101">
                        <customerOperationStartTime>1395317800</customerOperationStartTime>
                        <customerOperationEndTime>1395324700</customerOperationEndTime> 
                </customerOperationTimes>
                <customerOperationTimes id="102">
                        <customerOperationStartTime>1395317800</customerOperationStartTime>
                        <customerOperationEndTime>1395324700</customerOperationEndTime> 
                </customerOperationTimes>
            </customerOperationTimesList>                                
        </Activity>
    </activityList>
…

!!! 無法讀取此文件並產生異常。

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Problem reading inputSolutionFile (data\engineerrouting\unsolved\4es_4e_16a_4_8-18s_cot.xml).
    at org.optaplanner.persistence.xstream.impl.domain.solution.XStreamSolutionFileIO.read(XStreamSolutionFileIO.java:66)
    at org.optaplanner.examples.common.persistence.XStreamSolutionDao.readSolution(XStreamSolutionDao.java:37)
...

如您所見,嘗試讀取xml輸入文件時,該錯誤發生在文件XStreamSolutionDao.java中:

Line 37: Solution solution = xStreamSolutionFileIO.read(inputSolutionFile); 

!!! 但是運行的是以下xml內容(無列表,“僅” 1個customerOperationTimes-tag):

<activityList id="33">
    <Activity id="34">
        <activityID>1</activityID>
        <activityStatus>101</activityStatus>
        <location reference="7" />
        <appointmentStartTime>1395317700</appointmentStartTime> <!-- Unix time in sec => 2014/03/20 12:15:00 -->
        <appointmentEndTime>1395324900</appointmentEndTime>     <!-- Unix time in sec => 2014/03/20 14:15:00 -->
        <plannedWorkDuration>4500</plannedWorkDuration>         <!-- in sec => 75min duration -->
        <customerOperationTimes id="101">
                <customerOperationStartTime>1395317800</customerOperationStartTime>
                <customerOperationEndTime>1395324700</customerOperationEndTime> 
        </customerOperationTimes>
    </Activity>
</activityList>

感謝您的建議和幫助。

解:

我們在XML Input文件中添加了:

   <customerOperationTimesList id="110">
        <CustomerOperationTimes id="111">
                <id>1</id>
                <customerOperationStartTime>1395317800</customerOperationStartTime>
                <customerOperationEndTime>1395324700</customerOperationEndTime> 
        </CustomerOperationTimes>
        <CustomerOperationTimes id="112">
                <id>2</id>
                <customerOperationStartTime>1395317800</customerOperationStartTime>
                <customerOperationEndTime>1395324700</customerOperationEndTime> 
        </CustomerOperationTimes>
    </customerOperationTimesList>  

然后我們添加了一個類: CustomerOperationTime.java

package com.el2.optimization.technicianrouting.domain;

import com.el2.optimization.common.domain.AbstractPersistable;
import com.el2.optimization.technicianrouting.domain.CustomerOperationTimes;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamInclude;

@XStreamAlias("CustomerOperationTimes")
public class CustomerOperationTimes extends AbstractPersistable{

    private Long customerOperationStartTime;
    private Long customerOperationEndTime;


    public Long getCustomerOperationStartTime() {
        return this.customerOperationStartTime;
    }

    public void setCustomerOperationStartTime(Long customerOperationStartTime) {
        this.customerOperationStartTime = customerOperationStartTime;
    }

    public Long getCustomerOperationEndTime() {
        return this.customerOperationEndTime;
    }

    public void setCustomerOperationEndTime(Long customerOperationEndTime) {
        this.customerOperationEndTime = customerOperationEndTime;
    }           
}

Activity.java我們添加了:

private CustomerOperationTimes customerOperationTimes;

// @XmlElement(name = "customerOperationTimesList", type = CustomerOperationTimes.class)
protected List<CustomerOperationTimes> customerOperationTimesList ;

@PlanningEntityCollectionProperty
@ValueRangeProvider(id = "customerOperationTimesRange")
public List<CustomerOperationTimes> getCustomerOperationTimesList() {
    return customerOperationTimesList;
}

public void setCustomerOperationTimesList(List<CustomerOperationTimes> customerOperationTimesList) {
    this.customerOperationTimesList = customerOperationTimesList;
}    

這樣,我們可以讀取XML文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM