繁体   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