0

Dear OptaPlanner users,

I am using as basis the time dependent vehicle routing example. Here I have removed all TimeWindowed classes, e.g. the content of "TimeWindowedActivity.java" is moved and combined with "Activity.java", and so on ...

Now I would like to add a list of customer operation time windows to certain activities. These time windows (number of List items) can be different for each activity or some activities do not have such tags at all. This extension should make it possible to consider that activities can only be performed if they are fulfilling that the arrival time is lying between a certain number (a List) of customer operation time windows, defined by: “customerOperationStartTime” and “customerOperationEndTime”.

For solving this problem I created a class "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;
    }
}

In Activity.java I added:

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;
}

For testing I created a xml file with a single activity:

…
    <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>
…

!!! This file cannot be read and produces an exception.

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)
...

As you see, the error occurs in the file: XStreamSolutionDao.java, when trying to read the xml input file:

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

!!! But what runs is the following xml content (no list, and “only” 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>

Thank you for your suggestions and help.

len
  • 749
  • 1
  • 8
  • 23
  • 1
    What's the chained exception of that exception? I believe it will be an XStream unmarshalling error, because your domain java classes might not be in sync with your XML file elements. – Geoffrey De Smet Oct 22 '14 at 13:15

1 Answers1

0

Solution:

We added in the XML Input file:

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

Then we added a class: 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;
    }           
}

In Activity.java we added:

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;
}    

This way we can read the XML file.

len
  • 749
  • 1
  • 8
  • 23