Optaplanner /时间相关车辆路线/考虑属于活动的客户操作时间窗口列表

时间:2014-10-22 11:44:18

标签: optaplanner

亲爱的OptaPlanner用户,

我使用时间相关的车辆路线示例作为基础。在这里,我删除了所有TimeWindowed类,例如" TimeWindowedActivity.java"的内容被移动并与" Activity.java"等结合......等等......

现在我想为某些活动添加一个客户操作时间窗口列表。这些时间窗口(列表项目的数量)对于每个活动可以是不同的,或者一些活动根本没有这样的标签。 此扩展应该可以考虑只有在满足到达时间位于客户操作时间窗口的特定数量(列表)之间时才能执行活动,该窗口定义为:“customerOperationStartTime”和“customerOperationEndTime”。 / p>

为了解决这个问题,我创建了一个类" 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>

感谢您的建议和帮助。

1 个答案:

答案 0 :(得分:0)

解决方案:

我们在XML输入文件中添加了:

   <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文件了。

相关问题