mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
#347 - Custom properties
This commit is contained in:
parent
b9da9b9a06
commit
c109fe676f
16 changed files with 583 additions and 263 deletions
|
|
@ -26,7 +26,9 @@ import com.graphhopper.jsprit.core.problem.job.Job;
|
||||||
public abstract class AbstractJob implements Job {
|
public abstract class AbstractJob implements Job {
|
||||||
|
|
||||||
private int index;
|
private int index;
|
||||||
|
private Object userData;
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getIndex() {
|
public int getIndex() {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
@ -35,4 +37,15 @@ public abstract class AbstractJob implements Job {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return User-specific domain data associated by the job
|
||||||
|
*/
|
||||||
|
public Object getUserData() {
|
||||||
|
return userData;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setUserData(Object userData) {
|
||||||
|
this.userData = userData;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ public abstract class AbstractVehicle implements Vehicle {
|
||||||
|
|
||||||
private int index;
|
private int index;
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getIndex() {
|
public int getIndex() {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
@ -44,19 +45,35 @@ public abstract class AbstractVehicle implements Vehicle {
|
||||||
|
|
||||||
private VehicleTypeKey vehicleIdentifier;
|
private VehicleTypeKey vehicleIdentifier;
|
||||||
|
|
||||||
public int getIndex() {
|
private Object userData;
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setIndex(int index) {
|
/**
|
||||||
this.index = index;
|
* @return User-specific domain data associated with the vehicle
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
|
public Object getUserData() {
|
||||||
|
return userData;
|
||||||
|
}
|
||||||
|
|
||||||
public VehicleTypeKey getVehicleTypeIdentifier() {
|
protected void setUserData(Object userData) {
|
||||||
return vehicleIdentifier;
|
this.userData = userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setVehicleIdentifier(VehicleTypeKey vehicleTypeIdentifier) {
|
@Override
|
||||||
this.vehicleIdentifier = vehicleTypeIdentifier;
|
public int getIndex() {
|
||||||
}
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setIndex(int index) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VehicleTypeKey getVehicleTypeIdentifier() {
|
||||||
|
return vehicleIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setVehicleIdentifier(VehicleTypeKey vehicleTypeIdentifier) {
|
||||||
|
this.vehicleIdentifier = vehicleTypeIdentifier;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,10 +66,30 @@ public final class Location implements HasIndex, HasId {
|
||||||
|
|
||||||
private String name = "";
|
private String name = "";
|
||||||
|
|
||||||
|
private Object userData;
|
||||||
|
|
||||||
public static Builder newInstance() {
|
public static Builder newInstance() {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets user specific domain data associated with the object.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The user data is a black box for the framework, it only stores it,
|
||||||
|
* but never interacts with it in any way.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param userData
|
||||||
|
* any object holding the domain specific user data
|
||||||
|
* associated with the object.
|
||||||
|
* @return builder
|
||||||
|
*/
|
||||||
|
public Builder setUserData(Object userData) {
|
||||||
|
this.userData = userData;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets location index
|
* Sets location index
|
||||||
*
|
*
|
||||||
|
|
@ -140,13 +160,23 @@ public final class Location implements HasIndex, HasId {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
private Object userData;
|
||||||
|
|
||||||
private Location(Builder builder) {
|
private Location(Builder builder) {
|
||||||
|
this.userData = builder.userData;
|
||||||
this.index = builder.index;
|
this.index = builder.index;
|
||||||
this.coordinate = builder.coordinate;
|
this.coordinate = builder.coordinate;
|
||||||
this.id = builder.id;
|
this.id = builder.id;
|
||||||
this.name = builder.name;
|
this.name = builder.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return User-specific domain data associated by the job
|
||||||
|
*/
|
||||||
|
public Object getUserData() {
|
||||||
|
return userData;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
*/
|
*/
|
||||||
package com.graphhopper.jsprit.core.problem.job;
|
package com.graphhopper.jsprit.core.problem.job;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import com.graphhopper.jsprit.core.problem.AbstractJob;
|
import com.graphhopper.jsprit.core.problem.AbstractJob;
|
||||||
import com.graphhopper.jsprit.core.problem.Capacity;
|
import com.graphhopper.jsprit.core.problem.Capacity;
|
||||||
import com.graphhopper.jsprit.core.problem.Location;
|
import com.graphhopper.jsprit.core.problem.Location;
|
||||||
|
|
@ -26,8 +28,6 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindows;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindowsImpl;
|
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindowsImpl;
|
||||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service implementation of a job.
|
* Service implementation of a job.
|
||||||
* <p>
|
* <p>
|
||||||
|
|
@ -86,15 +86,16 @@ public class Service extends AbstractJob {
|
||||||
|
|
||||||
protected TimeWindowsImpl timeWindows;
|
protected TimeWindowsImpl timeWindows;
|
||||||
|
|
||||||
private boolean twAdded = false;
|
private boolean twAdded = false;
|
||||||
|
|
||||||
private int priority = 2;
|
private int priority = 2;
|
||||||
|
protected Object userData;
|
||||||
|
|
||||||
Builder(String id){
|
Builder(String id){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
timeWindows = new TimeWindowsImpl();
|
timeWindows = new TimeWindowsImpl();
|
||||||
timeWindows.add(timeWindow);
|
timeWindows.add(timeWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Protected method to set the type-name of the service.
|
* Protected method to set the type-name of the service.
|
||||||
|
|
@ -137,6 +138,24 @@ public class Service extends AbstractJob {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets user specific domain data associated with the object.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The user data is a black box for the framework, it only stores it,
|
||||||
|
* but never interacts with it in any way.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param userData
|
||||||
|
* any object holding the domain specific user data
|
||||||
|
* associated with the object.
|
||||||
|
* @return builder
|
||||||
|
*/
|
||||||
|
public Builder<T> setUserData(Object userData) {
|
||||||
|
this.userData = userData;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds capacity dimension.
|
* Adds capacity dimension.
|
||||||
*
|
*
|
||||||
|
|
@ -247,7 +266,8 @@ public class Service extends AbstractJob {
|
||||||
|
|
||||||
private final int priority;
|
private final int priority;
|
||||||
|
|
||||||
Service(Builder builder) {
|
Service(Builder<?> builder) {
|
||||||
|
setUserData(builder.userData);
|
||||||
id = builder.id;
|
id = builder.id;
|
||||||
serviceTime = builder.serviceTime;
|
serviceTime = builder.serviceTime;
|
||||||
timeWindow = builder.timeWindow;
|
timeWindow = builder.timeWindow;
|
||||||
|
|
@ -256,13 +276,13 @@ public class Service extends AbstractJob {
|
||||||
skills = builder.skills;
|
skills = builder.skills;
|
||||||
name = builder.name;
|
name = builder.name;
|
||||||
location = builder.location;
|
location = builder.location;
|
||||||
timeWindowManager = builder.timeWindows;
|
timeWindowManager = builder.timeWindows;
|
||||||
priority = builder.priority;
|
priority = builder.priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<TimeWindow> getTimeWindows(){
|
public Collection<TimeWindow> getTimeWindows(){
|
||||||
return timeWindowManager.getTimeWindows();
|
return timeWindowManager.getTimeWindows();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
|
@ -367,6 +387,7 @@ public class Service extends AbstractJob {
|
||||||
*
|
*
|
||||||
* @return priority
|
* @return priority
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int getPriority() {
|
public int getPriority() {
|
||||||
return priority;
|
return priority;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
*/
|
*/
|
||||||
package com.graphhopper.jsprit.core.problem.job;
|
package com.graphhopper.jsprit.core.problem.job;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import com.graphhopper.jsprit.core.problem.AbstractJob;
|
import com.graphhopper.jsprit.core.problem.AbstractJob;
|
||||||
import com.graphhopper.jsprit.core.problem.Capacity;
|
import com.graphhopper.jsprit.core.problem.Capacity;
|
||||||
import com.graphhopper.jsprit.core.problem.Location;
|
import com.graphhopper.jsprit.core.problem.Location;
|
||||||
|
|
@ -24,8 +26,6 @@ import com.graphhopper.jsprit.core.problem.Skills;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindowsImpl;
|
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindowsImpl;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shipment is an implementation of Job and consists of a pickup and a delivery of something.
|
* Shipment is an implementation of Job and consists of a pickup and a delivery of something.
|
||||||
|
|
@ -89,6 +89,8 @@ public class Shipment extends AbstractJob {
|
||||||
|
|
||||||
private int priority = 2;
|
private int priority = 2;
|
||||||
|
|
||||||
|
public Object userData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns new instance of this builder.
|
* Returns new instance of this builder.
|
||||||
*
|
*
|
||||||
|
|
@ -108,10 +110,29 @@ public class Shipment extends AbstractJob {
|
||||||
deliveryTimeWindows.add(deliveryTimeWindow);
|
deliveryTimeWindows.add(deliveryTimeWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets user specific domain data associated with the object.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The user data is a black box for the framework, it only stores it,
|
||||||
|
* but never interacts with it in any way.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param userData
|
||||||
|
* any object holding the domain specific user data
|
||||||
|
* associated with the object.
|
||||||
|
* @return builder
|
||||||
|
*/
|
||||||
|
public Builder setUserData(Object userData) {
|
||||||
|
this.userData = userData;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets pickup location.
|
* Sets pickup location.
|
||||||
*
|
*
|
||||||
* @param pickupLocation pickup location
|
* @param pickupLocation
|
||||||
|
* pickup location
|
||||||
* @return builder
|
* @return builder
|
||||||
*/
|
*/
|
||||||
public Builder setPickupLocation(Location pickupLocation) {
|
public Builder setPickupLocation(Location pickupLocation) {
|
||||||
|
|
@ -311,6 +332,7 @@ public class Shipment extends AbstractJob {
|
||||||
private final int priority;
|
private final int priority;
|
||||||
|
|
||||||
Shipment(Builder builder) {
|
Shipment(Builder builder) {
|
||||||
|
setUserData(builder.userData);
|
||||||
this.id = builder.id;
|
this.id = builder.id;
|
||||||
this.pickupServiceTime = builder.pickupServiceTime;
|
this.pickupServiceTime = builder.pickupServiceTime;
|
||||||
this.pickupTimeWindow = builder.pickupTimeWindow;
|
this.pickupTimeWindow = builder.pickupTimeWindow;
|
||||||
|
|
@ -438,6 +460,7 @@ public class Shipment extends AbstractJob {
|
||||||
*
|
*
|
||||||
* @return priority
|
* @return priority
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int getPriority() {
|
public int getPriority() {
|
||||||
return priority;
|
return priority;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,14 @@ public interface Vehicle extends HasId, HasIndex {
|
||||||
public abstract VehicleTypeKey getVehicleTypeIdentifier();
|
public abstract VehicleTypeKey getVehicleTypeIdentifier();
|
||||||
|
|
||||||
public abstract Skills getSkills();
|
public abstract Skills getSkills();
|
||||||
|
/**
|
||||||
|
* @return User-specific domain data associated with the vehicle
|
||||||
|
*/
|
||||||
|
public Object getUserData();
|
||||||
|
|
||||||
public abstract Break getBreak();
|
public abstract Break getBreak();
|
||||||
|
// Switch to this as soon as we switct to Java 8:
|
||||||
|
// default Object getUserData() {
|
||||||
|
// return null;
|
||||||
|
// };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,13 @@
|
||||||
*/
|
*/
|
||||||
package com.graphhopper.jsprit.core.problem.vehicle;
|
package com.graphhopper.jsprit.core.problem.vehicle;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.graphhopper.jsprit.core.problem.AbstractVehicle;
|
import com.graphhopper.jsprit.core.problem.AbstractVehicle;
|
||||||
import com.graphhopper.jsprit.core.problem.Location;
|
import com.graphhopper.jsprit.core.problem.Location;
|
||||||
import com.graphhopper.jsprit.core.problem.Skills;
|
import com.graphhopper.jsprit.core.problem.Skills;
|
||||||
import com.graphhopper.jsprit.core.problem.job.Break;
|
import com.graphhopper.jsprit.core.problem.job.Break;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -130,6 +131,8 @@ public class VehicleImpl extends AbstractVehicle {
|
||||||
|
|
||||||
private Break aBreak;
|
private Break aBreak;
|
||||||
|
|
||||||
|
private Object userData;
|
||||||
|
|
||||||
private Builder(String id) {
|
private Builder(String id) {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
@ -148,16 +151,39 @@ public class VehicleImpl extends AbstractVehicle {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets user specific domain data associated with the object.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The user data is a black box for the framework, it only stores it,
|
||||||
|
* but never interacts with it in any way.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param userData
|
||||||
|
* any object holding the domain specific user data
|
||||||
|
* associated with the object.
|
||||||
|
* @return builder
|
||||||
|
*/
|
||||||
|
public Builder setUserData(Object userData) {
|
||||||
|
this.userData = userData;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the flag whether the vehicle must return to depot or not.
|
* Sets the flag whether the vehicle must return to depot or not.
|
||||||
* <p>
|
* <p>
|
||||||
* <p>If returnToDepot is true, the vehicle must return to specified end-location. If you
|
|
||||||
* omit specifying the end-location, vehicle returns to start-location (that must to be set). If
|
|
||||||
* you specify it, it returns to specified end-location.
|
|
||||||
* <p>
|
* <p>
|
||||||
* <p>If returnToDepot is false, the end-location of the vehicle is endogenous.
|
* If returnToDepot is true, the vehicle must return to specified
|
||||||
|
* end-location. If you omit specifying the end-location, vehicle
|
||||||
|
* returns to start-location (that must to be set). If you specify it,
|
||||||
|
* it returns to specified end-location.
|
||||||
|
* <p>
|
||||||
|
* <p>
|
||||||
|
* If returnToDepot is false, the end-location of the vehicle is
|
||||||
|
* endogenous.
|
||||||
*
|
*
|
||||||
* @param returnToDepot true if vehicle need to return to depot, otherwise false
|
* @param returnToDepot
|
||||||
|
* true if vehicle need to return to depot, otherwise false
|
||||||
* @return this builder
|
* @return this builder
|
||||||
*/
|
*/
|
||||||
public Builder setReturnToDepot(boolean returnToDepot) {
|
public Builder setReturnToDepot(boolean returnToDepot) {
|
||||||
|
|
@ -234,14 +260,13 @@ public class VehicleImpl extends AbstractVehicle {
|
||||||
if (startLocation != null && endLocation != null) {
|
if (startLocation != null && endLocation != null) {
|
||||||
if (!startLocation.getId().equals(endLocation.getId()) && !returnToDepot)
|
if (!startLocation.getId().equals(endLocation.getId()) && !returnToDepot)
|
||||||
throw new IllegalArgumentException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
|
throw new IllegalArgumentException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
|
||||||
"if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified.");
|
"if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified.");
|
||||||
}
|
}
|
||||||
if (startLocation != null && endLocation == null) {
|
if (startLocation != null && endLocation == null) {
|
||||||
endLocation = startLocation;
|
endLocation = startLocation;
|
||||||
}
|
}
|
||||||
if (startLocation == null && endLocation == null) {
|
if (startLocation == null && endLocation == null)
|
||||||
throw new IllegalArgumentException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set");
|
throw new IllegalArgumentException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set");
|
||||||
}
|
|
||||||
skills = skillBuilder.build();
|
skills = skillBuilder.build();
|
||||||
return new VehicleImpl(this);
|
return new VehicleImpl(this);
|
||||||
}
|
}
|
||||||
|
|
@ -297,6 +322,7 @@ public class VehicleImpl extends AbstractVehicle {
|
||||||
private final Break aBreak;
|
private final Break aBreak;
|
||||||
|
|
||||||
private VehicleImpl(Builder builder) {
|
private VehicleImpl(Builder builder) {
|
||||||
|
setUserData(builder.userData);
|
||||||
id = builder.id;
|
id = builder.id;
|
||||||
type = builder.type;
|
type = builder.type;
|
||||||
earliestDeparture = builder.earliestStart;
|
earliestDeparture = builder.earliestStart;
|
||||||
|
|
@ -306,7 +332,7 @@ public class VehicleImpl extends AbstractVehicle {
|
||||||
endLocation = builder.endLocation;
|
endLocation = builder.endLocation;
|
||||||
startLocation = builder.startLocation;
|
startLocation = builder.startLocation;
|
||||||
aBreak = builder.aBreak;
|
aBreak = builder.aBreak;
|
||||||
// setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(),startLocation.getId(),endLocation.getId(),earliestDeparture,latestArrival,skills));
|
// setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(),startLocation.getId(),endLocation.getId(),earliestDeparture,latestArrival,skills));
|
||||||
setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(), startLocation.getId(), endLocation.getId(), earliestDeparture, latestArrival, skills, returnToDepot));
|
setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(), startLocation.getId(), endLocation.getId(), earliestDeparture, latestArrival, skills, returnToDepot));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -318,11 +344,11 @@ public class VehicleImpl extends AbstractVehicle {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[id=" + id + "]" +
|
return "[id=" + id + "]" +
|
||||||
"[type=" + type + "]" +
|
"[type=" + type + "]" +
|
||||||
"[startLocation=" + startLocation + "]" +
|
"[startLocation=" + startLocation + "]" +
|
||||||
"[endLocation=" + endLocation + "]" +
|
"[endLocation=" + endLocation + "]" +
|
||||||
"[isReturnToDepot=" + isReturnToDepot() + "]" +
|
"[isReturnToDepot=" + isReturnToDepot() + "]" +
|
||||||
"[skills=" + skills + "]";
|
"[skills=" + skills + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -346,6 +372,7 @@ public class VehicleImpl extends AbstractVehicle {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isReturnToDepot() {
|
public boolean isReturnToDepot() {
|
||||||
return returnToDepot;
|
return returnToDepot;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,4 +56,13 @@ public interface VehicleType {
|
||||||
|
|
||||||
public String getProfile();
|
public String getProfile();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return User-specific domain data associated with the vehicle type
|
||||||
|
*/
|
||||||
|
public Object getUserData();
|
||||||
|
|
||||||
|
// Switch to this as soon as we switct to Java 8:
|
||||||
|
// default Object getUserData() {
|
||||||
|
// return null;
|
||||||
|
// };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -116,16 +116,39 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
|
|
||||||
private boolean dimensionAdded = false;
|
private boolean dimensionAdded = false;
|
||||||
|
|
||||||
|
private Object userData;
|
||||||
|
|
||||||
private Builder(String id) {
|
private Builder(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the maximum velocity this vehicle-type can go [in meter per seconds].
|
* Sets user specific domain data associated with the object.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The user data is a black box for the framework, it only stores it,
|
||||||
|
* but never interacts with it in any way.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param userData
|
||||||
|
* any object holding the domain specific user data
|
||||||
|
* associated with the object.
|
||||||
|
* @return builder
|
||||||
|
*/
|
||||||
|
public Builder setUserData(Object userData) {
|
||||||
|
this.userData = userData;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the maximum velocity this vehicle-type can go [in meter per
|
||||||
|
* seconds].
|
||||||
*
|
*
|
||||||
* @param inMeterPerSeconds
|
* @param inMeterPerSeconds
|
||||||
* @return this builder
|
* @return this builder
|
||||||
* @throws IllegalArgumentException if velocity is smaller than zero
|
* @throws IllegalArgumentException
|
||||||
|
* if velocity is smaller than zero
|
||||||
*/
|
*/
|
||||||
public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) {
|
public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) {
|
||||||
if (inMeterPerSeconds < 0.0) throw new IllegalArgumentException("velocity cannot be smaller than zero");
|
if (inMeterPerSeconds < 0.0) throw new IllegalArgumentException("velocity cannot be smaller than zero");
|
||||||
|
|
@ -240,8 +263,8 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative");
|
if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative");
|
||||||
if (capacityDimensions != null)
|
if (capacityDimensions != null)
|
||||||
throw new IllegalArgumentException("either build your dimension with build your dimensions with " +
|
throw new IllegalArgumentException("either build your dimension with build your dimensions with " +
|
||||||
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
|
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
|
||||||
"You used both methods.");
|
"You used both methods.");
|
||||||
dimensionAdded = true;
|
dimensionAdded = true;
|
||||||
capacityBuilder.addDimension(dimIndex, dimVal);
|
capacityBuilder.addDimension(dimIndex, dimVal);
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -261,8 +284,8 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
public Builder setCapacityDimensions(Capacity capacity) {
|
public Builder setCapacityDimensions(Capacity capacity) {
|
||||||
if (dimensionAdded)
|
if (dimensionAdded)
|
||||||
throw new IllegalArgumentException("either build your dimension with build your dimensions with " +
|
throw new IllegalArgumentException("either build your dimension with build your dimensions with " +
|
||||||
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
|
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
|
||||||
"You used both methods.");
|
"You used both methods.");
|
||||||
this.capacityDimensions = capacity;
|
this.capacityDimensions = capacity;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -278,7 +301,7 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result
|
result = prime * result
|
||||||
+ ((typeId == null) ? 0 : typeId.hashCode());
|
+ ((typeId == null) ? 0 : typeId.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -314,12 +337,15 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
|
|
||||||
private final double maxVelocity;
|
private final double maxVelocity;
|
||||||
|
|
||||||
|
private Object userData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* priv constructor constructing vehicle-type
|
* priv constructor constructing vehicle-type
|
||||||
*
|
*
|
||||||
* @param builder
|
* @param builder
|
||||||
*/
|
*/
|
||||||
private VehicleTypeImpl(VehicleTypeImpl.Builder builder) {
|
private VehicleTypeImpl(VehicleTypeImpl.Builder builder) {
|
||||||
|
this.userData = builder.userData;
|
||||||
typeId = builder.id;
|
typeId = builder.id;
|
||||||
capacity = builder.capacity;
|
capacity = builder.capacity;
|
||||||
maxVelocity = builder.maxVelo;
|
maxVelocity = builder.maxVelo;
|
||||||
|
|
@ -328,6 +354,14 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
profile = builder.profile;
|
profile = builder.profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return User-specific domain data associated with the vehicle
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Object getUserData() {
|
||||||
|
return userData;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see basics.route.VehicleType#getTypeId()
|
* @see basics.route.VehicleType#getTypeId()
|
||||||
*/
|
*/
|
||||||
|
|
@ -347,8 +381,8 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[typeId=" + typeId + "]" +
|
return "[typeId=" + typeId + "]" +
|
||||||
"[capacity=" + capacityDimensions + "]" +
|
"[capacity=" + capacityDimensions + "]" +
|
||||||
"[costs=" + vehicleCostParams + "]";
|
"[costs=" + vehicleCostParams + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,18 @@
|
||||||
|
|
||||||
package com.graphhopper.jsprit.core.problem;
|
package com.graphhopper.jsprit.core.problem;
|
||||||
|
|
||||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by schroeder on 16.12.14.
|
* Created by schroeder on 16.12.14.
|
||||||
*/
|
*/
|
||||||
|
|
@ -82,7 +89,7 @@ public class LocationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCoordinateSetWithFactory_returnCorrectLocation() {
|
public void whenCoordinateSetWithFactory_returnCorrectLocation() {
|
||||||
// Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10,20)).build();
|
// Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10,20)).build();
|
||||||
Location l = Location.newInstance(10, 20);
|
Location l = Location.newInstance(10, 20);
|
||||||
Assert.assertEquals(10., l.getCoordinate().getX(),0.001);
|
Assert.assertEquals(10., l.getCoordinate().getX(),0.001);
|
||||||
Assert.assertEquals(20., l.getCoordinate().getY(),0.001);
|
Assert.assertEquals(20., l.getCoordinate().getY(),0.001);
|
||||||
|
|
@ -90,4 +97,16 @@ public class LocationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingUserData_itIsAssociatedWithTheLocation() {
|
||||||
|
Location one = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 20))
|
||||||
|
.setUserData(new HashMap<String, Object>()).build();
|
||||||
|
Location two = Location.Builder.newInstance().setIndex(1).setUserData(42).build();
|
||||||
|
Location three = Location.Builder.newInstance().setIndex(2).build();
|
||||||
|
|
||||||
|
assertTrue(one.getUserData() instanceof Map);
|
||||||
|
assertEquals(42, two.getUserData());
|
||||||
|
assertNull(three.getUserData());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,18 @@
|
||||||
*/
|
*/
|
||||||
package com.graphhopper.jsprit.core.problem.job;
|
package com.graphhopper.jsprit.core.problem.job;
|
||||||
|
|
||||||
import com.graphhopper.jsprit.core.problem.Location;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import com.graphhopper.jsprit.core.problem.Location;
|
||||||
|
|
||||||
public class DeliveryTest {
|
public class DeliveryTest {
|
||||||
|
|
||||||
|
|
@ -33,9 +40,9 @@ public class DeliveryTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||||
Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||||
.addSizeDimension(0, 2)
|
.addSizeDimension(0, 2)
|
||||||
.addSizeDimension(1, 4)
|
.addSizeDimension(1, 4)
|
||||||
.build();
|
.build();
|
||||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||||
assertEquals(2, one.getSize().get(0));
|
assertEquals(2, one.getSize().get(0));
|
||||||
assertEquals(4, one.getSize().get(1));
|
assertEquals(4, one.getSize().get(1));
|
||||||
|
|
@ -45,7 +52,7 @@ public class DeliveryTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||||
Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||||
.build();
|
.build();
|
||||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||||
assertEquals(0, one.getSize().get(0));
|
assertEquals(0, one.getSize().get(0));
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +60,7 @@ public class DeliveryTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||||
Delivery one = Delivery.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
Delivery one = Delivery.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
||||||
.build();
|
.build();
|
||||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||||
assertEquals(1, one.getSize().get(0));
|
assertEquals(1, one.getSize().get(0));
|
||||||
}
|
}
|
||||||
|
|
@ -61,7 +68,7 @@ public class DeliveryTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +76,7 @@ public class DeliveryTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||||
}
|
}
|
||||||
|
|
@ -77,7 +84,7 @@ public class DeliveryTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.addRequiredSkill("screwDriver").build();
|
.addRequiredSkill("screwDriver").build();
|
||||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||||
}
|
}
|
||||||
|
|
@ -85,23 +92,35 @@ public class DeliveryTest {
|
||||||
@Test
|
@Test
|
||||||
public void nameShouldBeAssigned() {
|
public void nameShouldBeAssigned() {
|
||||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.setName("name").build();
|
.setName("name").build();
|
||||||
assertEquals("name", s.getName());
|
assertEquals("name", s.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.setPriority(3).build();
|
.setPriority(3).build();
|
||||||
Assert.assertEquals(3, s.getPriority());
|
Assert.assertEquals(3, s.getPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenNotSettingPriorities_defaultShouldBe(){
|
public void whenNotSettingPriorities_defaultShouldBe(){
|
||||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.build();
|
.build();
|
||||||
Assert.assertEquals(2, s.getPriority());
|
Assert.assertEquals(2, s.getPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||||
|
Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
|
.setUserData(new HashMap<String, Object>()).build();
|
||||||
|
Delivery two = Delivery.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42)
|
||||||
|
.build();
|
||||||
|
Delivery three = Delivery.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build();
|
||||||
|
|
||||||
|
assertTrue(one.getUserData() instanceof Map);
|
||||||
|
assertEquals(42, two.getUserData());
|
||||||
|
assertNull(three.getUserData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,18 @@
|
||||||
*/
|
*/
|
||||||
package com.graphhopper.jsprit.core.problem.job;
|
package com.graphhopper.jsprit.core.problem.job;
|
||||||
|
|
||||||
import com.graphhopper.jsprit.core.problem.Location;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import com.graphhopper.jsprit.core.problem.Location;
|
||||||
|
|
||||||
public class PickupTest {
|
public class PickupTest {
|
||||||
|
|
||||||
|
|
@ -33,9 +40,9 @@ public class PickupTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||||
Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||||
.addSizeDimension(0, 2)
|
.addSizeDimension(0, 2)
|
||||||
.addSizeDimension(1, 4)
|
.addSizeDimension(1, 4)
|
||||||
.build();
|
.build();
|
||||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||||
assertEquals(2, one.getSize().get(0));
|
assertEquals(2, one.getSize().get(0));
|
||||||
assertEquals(4, one.getSize().get(1));
|
assertEquals(4, one.getSize().get(1));
|
||||||
|
|
@ -45,7 +52,7 @@ public class PickupTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||||
Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||||
.build();
|
.build();
|
||||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||||
assertEquals(0, one.getSize().get(0));
|
assertEquals(0, one.getSize().get(0));
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +60,7 @@ public class PickupTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||||
Pickup one = Pickup.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
Pickup one = Pickup.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
||||||
.build();
|
.build();
|
||||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||||
assertEquals(1, one.getSize().get(0));
|
assertEquals(1, one.getSize().get(0));
|
||||||
}
|
}
|
||||||
|
|
@ -61,7 +68,7 @@ public class PickupTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||||
|
|
@ -70,7 +77,7 @@ public class PickupTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||||
}
|
}
|
||||||
|
|
@ -78,7 +85,7 @@ public class PickupTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.addRequiredSkill("screwDriver").build();
|
.addRequiredSkill("screwDriver").build();
|
||||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +93,7 @@ public class PickupTest {
|
||||||
@Test
|
@Test
|
||||||
public void nameShouldBeAssigned() {
|
public void nameShouldBeAssigned() {
|
||||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.setName("name").build();
|
.setName("name").build();
|
||||||
assertEquals("name", s.getName());
|
assertEquals("name", s.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,15 +101,26 @@ public class PickupTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.setPriority(3).build();
|
.setPriority(3).build();
|
||||||
Assert.assertEquals(3, s.getPriority());
|
Assert.assertEquals(3, s.getPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenNotSettingPriorities_defaultShouldBe(){
|
public void whenNotSettingPriorities_defaultShouldBe(){
|
||||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.build();
|
.build();
|
||||||
Assert.assertEquals(2, s.getPriority());
|
Assert.assertEquals(2, s.getPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||||
|
Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
|
.setUserData(new HashMap<String, Object>()).build();
|
||||||
|
Pickup two = Pickup.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42).build();
|
||||||
|
Pickup three = Pickup.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build();
|
||||||
|
|
||||||
|
assertTrue(one.getUserData() instanceof Map);
|
||||||
|
assertEquals(42, two.getUserData());
|
||||||
|
assertNull(three.getUserData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,17 +17,25 @@
|
||||||
*/
|
*/
|
||||||
package com.graphhopper.jsprit.core.problem.job;
|
package com.graphhopper.jsprit.core.problem.job;
|
||||||
|
|
||||||
import com.graphhopper.jsprit.core.problem.Location;
|
import static org.hamcrest.core.Is.is;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import com.graphhopper.jsprit.core.problem.Location;
|
||||||
import java.util.Set;
|
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||||
|
|
||||||
import static org.hamcrest.core.Is.is;
|
|
||||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
public class ServiceTest {
|
public class ServiceTest {
|
||||||
|
|
||||||
|
|
@ -53,7 +61,7 @@ public class ServiceTest {
|
||||||
Service one = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("foo")).build();
|
Service one = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("foo")).build();
|
||||||
Service two = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("fo")).build();
|
Service two = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("fo")).build();
|
||||||
serviceSet.add(one);
|
serviceSet.add(one);
|
||||||
// assertTrue(serviceSet.contains(two));
|
// assertTrue(serviceSet.contains(two));
|
||||||
serviceSet.remove(two);
|
serviceSet.remove(two);
|
||||||
assertTrue(serviceSet.isEmpty());
|
assertTrue(serviceSet.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
@ -67,16 +75,16 @@ public class ServiceTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||||
Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||||
.addSizeDimension(0, 2)
|
.addSizeDimension(0, 2)
|
||||||
.addSizeDimension(1, 4)
|
.addSizeDimension(1, 4)
|
||||||
.build();
|
.build();
|
||||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||||
Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||||
.build();
|
.build();
|
||||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||||
assertEquals(0, one.getSize().get(0));
|
assertEquals(0, one.getSize().get(0));
|
||||||
}
|
}
|
||||||
|
|
@ -84,7 +92,7 @@ public class ServiceTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||||
Service one = Service.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
Service one = Service.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
||||||
.build();
|
.build();
|
||||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||||
assertEquals(1, one.getSize().get(0));
|
assertEquals(1, one.getSize().get(0));
|
||||||
}
|
}
|
||||||
|
|
@ -116,71 +124,71 @@ public class ServiceTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSettingLocationCoord_itShouldBeSetCorrectly(){
|
public void whenSettingLocationCoord_itShouldBeSetCorrectly(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance(1, 2)).build();
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance(1, 2)).build();
|
||||||
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
|
|
||||||
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
|
||||||
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
|
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
|
||||||
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
||||||
}
|
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
|
||||||
|
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void whenSettingNeitherLocationIdNorCoord_throwsException(){
|
public void whenSettingNeitherLocationIdNorCoord_throwsException(){
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Service s = Service.Builder.newInstance("s").build();
|
Service s = Service.Builder.newInstance("s").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void whenServiceTimeSmallerZero_throwIllegalStateException(){
|
public void whenServiceTimeSmallerZero_throwIllegalStateException(){
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(-1).build();
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(-1).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSettingServiceTime_itShouldBeSetCorrectly(){
|
public void whenSettingServiceTime_itShouldBeSetCorrectly(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(1).build();
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(1).build();
|
||||||
assertEquals(1.0,s.getServiceDuration(),0.01);
|
assertEquals(1.0,s.getServiceDuration(),0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void whenTimeWindowIsNull_throwException(){
|
public void whenTimeWindowIsNull_throwException(){
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(null).build();
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(null).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSettingTimeWindow_itShouldBeSetCorrectly(){
|
public void whenSettingTimeWindow_itShouldBeSetCorrectly(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||||
assertEquals(1.0,s.getTimeWindow().getStart(),0.01);
|
assertEquals(1.0,s.getTimeWindow().getStart(),0.01);
|
||||||
assertEquals(2.0,s.getTimeWindow().getEnd(),0.01);
|
assertEquals(2.0,s.getTimeWindow().getEnd(),0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkills_theyShouldBeAddedCorrectly(){
|
public void whenAddingSkills_theyShouldBeAddedCorrectly(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){
|
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSeveralTimeWindows_itShouldBeSetCorrectly(){
|
public void whenAddingSeveralTimeWindows_itShouldBeSetCorrectly(){
|
||||||
TimeWindow tw1 = TimeWindow.newInstance(1.0, 2.0);
|
TimeWindow tw1 = TimeWindow.newInstance(1.0, 2.0);
|
||||||
TimeWindow tw2 = TimeWindow.newInstance(3.0, 5.0);
|
TimeWindow tw2 = TimeWindow.newInstance(3.0, 5.0);
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.addTimeWindow(tw1)
|
.addTimeWindow(tw1)
|
||||||
.addTimeWindow(tw2)
|
.addTimeWindow(tw2)
|
||||||
.build();
|
.build();
|
||||||
assertEquals(2, s.getTimeWindows().size());
|
assertEquals(2, s.getTimeWindows().size());
|
||||||
assertThat(s.getTimeWindows(),hasItem(is(tw1)));
|
assertThat(s.getTimeWindows(),hasItem(is(tw1)));
|
||||||
assertThat(s.getTimeWindows(),hasItem(is(tw2)));
|
assertThat(s.getTimeWindows(),hasItem(is(tw2)));
|
||||||
|
|
@ -189,7 +197,7 @@ public class ServiceTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingTimeWindow_itShouldBeSetCorrectly(){
|
public void whenAddingTimeWindow_itShouldBeSetCorrectly(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.addTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
.addTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||||
assertEquals(1.0, s.getTimeWindow().getStart(), 0.01);
|
assertEquals(1.0, s.getTimeWindow().getStart(), 0.01);
|
||||||
assertEquals(2.0, s.getTimeWindow().getEnd(), 0.01);
|
assertEquals(2.0, s.getTimeWindow().getEnd(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
@ -200,7 +208,7 @@ public class ServiceTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.addRequiredSkill("screwDriver").build();
|
.addRequiredSkill("screwDriver").build();
|
||||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||||
}
|
}
|
||||||
|
|
@ -208,74 +216,87 @@ public class ServiceTest {
|
||||||
@Test
|
@Test
|
||||||
public void nameShouldBeAssigned() {
|
public void nameShouldBeAssigned() {
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.setName("name").build();
|
.setName("name").build();
|
||||||
assertEquals("name", s.getName());
|
assertEquals("name", s.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldKnowMultipleTimeWindows(){
|
public void shouldKnowMultipleTimeWindows(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.addTimeWindow(TimeWindow.newInstance(0., 10.)).addTimeWindow(TimeWindow.newInstance(20., 30.))
|
.addTimeWindow(TimeWindow.newInstance(0., 10.)).addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||||
.setName("name").build();
|
.setName("name").build();
|
||||||
assertEquals(2,s.getTimeWindows().size());
|
assertEquals(2,s.getTimeWindows().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void whenMultipleTWOverlap_throwEx(){
|
public void whenMultipleTWOverlap_throwEx(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.addTimeWindow(TimeWindow.newInstance(0.,10.))
|
.addTimeWindow(TimeWindow.newInstance(0.,10.))
|
||||||
.addTimeWindow(TimeWindow.newInstance(5., 30.))
|
.addTimeWindow(TimeWindow.newInstance(5., 30.))
|
||||||
.setName("name").build();
|
.setName("name").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void whenMultipleTWOverlap2_throwEx(){
|
public void whenMultipleTWOverlap2_throwEx(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.addTimeWindow(TimeWindow.newInstance(20., 30.))
|
.addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||||
.addTimeWindow(TimeWindow.newInstance(0., 25.))
|
.addTimeWindow(TimeWindow.newInstance(0., 25.))
|
||||||
.setName("name").build();
|
.setName("name").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.setPriority(1).build();
|
.setPriority(1).build();
|
||||||
Assert.assertEquals(1, s.getPriority());
|
Assert.assertEquals(1, s.getPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSettingPriorities_itShouldBeSetCorrectly2(){
|
public void whenSettingPriorities_itShouldBeSetCorrectly2(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.setPriority(3).build();
|
.setPriority(3).build();
|
||||||
Assert.assertEquals(3, s.getPriority());
|
Assert.assertEquals(3, s.getPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSettingPriorities_itShouldBeSetCorrectly3() {
|
public void whenSettingPriorities_itShouldBeSetCorrectly3() {
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.setPriority(10).build();
|
.setPriority(10).build();
|
||||||
Assert.assertEquals(10, s.getPriority());
|
Assert.assertEquals(10, s.getPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenNotSettingPriorities_defaultShouldBe2(){
|
public void whenNotSettingPriorities_defaultShouldBe2(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.build();
|
.build();
|
||||||
Assert.assertEquals(2, s.getPriority());
|
Assert.assertEquals(2, s.getPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void whenSettingIncorrectPriorities_itShouldThrowException(){
|
public void whenSettingIncorrectPriorities_itShouldThrowException(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.setPriority(30).build();
|
.setPriority(30).build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void whenSettingIncorrectPriorities_itShouldThrowException2(){
|
public void whenSettingIncorrectPriorities_itShouldThrowException2(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
.setPriority(0).build();
|
.setPriority(0).build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||||
|
Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||||
|
.setUserData(new HashMap<String, Object>()).build();
|
||||||
|
Service two = Service.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42)
|
||||||
|
.build();
|
||||||
|
Service three = Service.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build();
|
||||||
|
|
||||||
|
assertTrue(one.getUserData() instanceof Map);
|
||||||
|
assertEquals(42, two.getUserData());
|
||||||
|
assertNull(three.getUserData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,25 +17,34 @@
|
||||||
*/
|
*/
|
||||||
package com.graphhopper.jsprit.core.problem.job;
|
package com.graphhopper.jsprit.core.problem.job;
|
||||||
|
|
||||||
|
import static org.hamcrest.core.Is.is;
|
||||||
|
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.graphhopper.jsprit.core.problem.Location;
|
import com.graphhopper.jsprit.core.problem.Location;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||||
import com.graphhopper.jsprit.core.util.TestUtils;
|
import com.graphhopper.jsprit.core.util.TestUtils;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.hamcrest.core.Is.is;
|
|
||||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
public class ShipmentTest {
|
public class ShipmentTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenTwoShipmentsHaveTheSameId_theyReferencesShouldBeUnEqual() {
|
public void whenTwoShipmentsHaveTheSameId_theyReferencesShouldBeUnEqual() {
|
||||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||||
Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||||
|
|
||||||
assertTrue(one != two);
|
assertTrue(one != two);
|
||||||
}
|
}
|
||||||
|
|
@ -43,9 +52,9 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenTwoShipmentsHaveTheSameId_theyShouldBeEqual() {
|
public void whenTwoShipmentsHaveTheSameId_theyShouldBeEqual() {
|
||||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||||
Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||||
|
|
||||||
assertTrue(one.equals(two));
|
assertTrue(one.equals(two));
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +62,7 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenShipmentIsInstantiatedWithASizeOf10_theSizeShouldBe10() {
|
public void whenShipmentIsInstantiatedWithASizeOf10_theSizeShouldBe10() {
|
||||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||||
assertEquals(10, one.getSize().get(0));
|
assertEquals(10, one.getSize().get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,24 +70,24 @@ public class ShipmentTest {
|
||||||
public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException() {
|
public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException() {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10)
|
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10)
|
||||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException_v2() {
|
public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException_v2() {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10)
|
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10)
|
||||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void whenIdIsNull_itShouldThrowException() {
|
public void whenIdIsNull_itShouldThrowException() {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Shipment one = Shipment.Builder.newInstance(null).addSizeDimension(0, 10)
|
Shipment one = Shipment.Builder.newInstance(null).addSizeDimension(0, 10)
|
||||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -115,7 +124,7 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenPickupCoordIsSet_itShouldBeDoneCorrectly() {
|
public void whenPickupCoordIsSet_itShouldBeDoneCorrectly() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s")
|
Shipment s = Shipment.Builder.newInstance("s")
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").setCoordinate(Coordinate.newInstance(1, 2)).build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").setCoordinate(Coordinate.newInstance(1, 2)).build()).build();
|
||||||
assertEquals(1.0, s.getPickupLocation().getCoordinate().getX(), 0.01);
|
assertEquals(1.0, s.getPickupLocation().getCoordinate().getX(), 0.01);
|
||||||
assertEquals(2.0, s.getPickupLocation().getCoordinate().getY(), 0.01);
|
assertEquals(2.0, s.getPickupLocation().getCoordinate().getY(), 0.01);
|
||||||
assertEquals(1.0, s.getPickupLocation().getCoordinate().getX(), 0.01);
|
assertEquals(1.0, s.getPickupLocation().getCoordinate().getX(), 0.01);
|
||||||
|
|
@ -126,7 +135,7 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenDeliveryLocationIdIsSet_itShouldBeDoneCorrectly() {
|
public void whenDeliveryLocationIdIsSet_itShouldBeDoneCorrectly() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s")
|
Shipment s = Shipment.Builder.newInstance("s")
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals("delLoc", s.getDeliveryLocation().getId());
|
assertEquals("delLoc", s.getDeliveryLocation().getId());
|
||||||
assertEquals("delLoc", s.getDeliveryLocation().getId());
|
assertEquals("delLoc", s.getDeliveryLocation().getId());
|
||||||
}
|
}
|
||||||
|
|
@ -135,8 +144,8 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenDeliveryCoordIsSet_itShouldBeDoneCorrectly() {
|
public void whenDeliveryCoordIsSet_itShouldBeDoneCorrectly() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(1, 2)))
|
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(1, 2)))
|
||||||
.setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build())
|
.setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build())
|
||||||
.build();
|
.build();
|
||||||
assertEquals(1.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01);
|
assertEquals(1.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01);
|
||||||
assertEquals(2.0, s.getDeliveryLocation().getCoordinate().getY(), 0.01);
|
assertEquals(2.0, s.getDeliveryLocation().getCoordinate().getY(), 0.01);
|
||||||
assertEquals(1.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01);
|
assertEquals(1.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01);
|
||||||
|
|
@ -146,22 +155,22 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenPickupServiceTimeIsNotSet_itShouldBeZero() {
|
public void whenPickupServiceTimeIsNotSet_itShouldBeZero() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s")
|
Shipment s = Shipment.Builder.newInstance("s")
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals(0.0, s.getPickupServiceTime(), 0.01);
|
assertEquals(0.0, s.getPickupServiceTime(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenDeliveryServiceTimeIsNotSet_itShouldBeZero() {
|
public void whenDeliveryServiceTimeIsNotSet_itShouldBeZero() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s")
|
Shipment s = Shipment.Builder.newInstance("s")
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals(0.0, s.getDeliveryServiceTime(), 0.01);
|
assertEquals(0.0, s.getDeliveryServiceTime(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenPickupServiceTimeIsSet_itShouldBeDoneCorrectly() {
|
public void whenPickupServiceTimeIsSet_itShouldBeDoneCorrectly() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s")
|
Shipment s = Shipment.Builder.newInstance("s")
|
||||||
.setPickupServiceTime(2.0)
|
.setPickupServiceTime(2.0)
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals(2.0, s.getPickupServiceTime(), 0.01);
|
assertEquals(2.0, s.getPickupServiceTime(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,13 +178,13 @@ public class ShipmentTest {
|
||||||
public void whenPickupServiceIsSmallerThanZero_itShouldThrowException() {
|
public void whenPickupServiceIsSmallerThanZero_itShouldThrowException() {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setPickupServiceTime(-2.0)
|
Shipment s = Shipment.Builder.newInstance("s").setPickupServiceTime(-2.0)
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenDeliveryServiceTimeIsSet_itShouldBeDoneCorrectly() {
|
public void whenDeliveryServiceTimeIsSet_itShouldBeDoneCorrectly() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryServiceTime(2.0)
|
Shipment s = Shipment.Builder.newInstance("s").setDeliveryServiceTime(2.0)
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals(2.0, s.getDeliveryServiceTime(), 0.01);
|
assertEquals(2.0, s.getDeliveryServiceTime(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,7 +210,7 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenPickupTimeWindowIsSet_itShouldBeDoneCorrectly() {
|
public void whenPickupTimeWindowIsSet_itShouldBeDoneCorrectly() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
Shipment s = Shipment.Builder.newInstance("s").setPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
@ -222,7 +231,7 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenDeliveryTimeWindowIsSet_itShouldBeDoneCorrectly() {
|
public void whenDeliveryTimeWindowIsSet_itShouldBeDoneCorrectly() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryTimeWindow(TimeWindow.newInstance(1, 2))
|
Shipment s = Shipment.Builder.newInstance("s").setDeliveryTimeWindow(TimeWindow.newInstance(1, 2))
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
@ -230,7 +239,7 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingAddDeliveryTimeWindow_itShouldBeDoneCorrectly() {
|
public void whenUsingAddDeliveryTimeWindow_itShouldBeDoneCorrectly() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(TimeWindow.newInstance(1, 2))
|
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(TimeWindow.newInstance(1, 2))
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
@ -238,7 +247,7 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingAddDeliveryTimeWindow2_itShouldBeDoneCorrectly() {
|
public void whenUsingAddDeliveryTimeWindow2_itShouldBeDoneCorrectly() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 2)
|
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 2)
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
@ -248,7 +257,7 @@ public class ShipmentTest {
|
||||||
TimeWindow tw1 = TimeWindow.newInstance(1,2);
|
TimeWindow tw1 = TimeWindow.newInstance(1,2);
|
||||||
TimeWindow tw2 = TimeWindow.newInstance(4,5);
|
TimeWindow tw2 = TimeWindow.newInstance(4,5);
|
||||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(tw1).addDeliveryTimeWindow(tw2)
|
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(tw1).addDeliveryTimeWindow(tw2)
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals(s.getDeliveryTimeWindows().size(),2);
|
assertEquals(s.getDeliveryTimeWindows().size(),2);
|
||||||
assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw1)));
|
assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw1)));
|
||||||
assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw2)));
|
assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw2)));
|
||||||
|
|
@ -257,7 +266,7 @@ public class ShipmentTest {
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void whenAddingMultipleOverlappingDeliveryTimeWindows_itShouldThrowException() {
|
public void whenAddingMultipleOverlappingDeliveryTimeWindows_itShouldThrowException() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 3).addDeliveryTimeWindow(2,5)
|
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 3).addDeliveryTimeWindow(2,5)
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
@ -267,7 +276,7 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingAddPickupTimeWindow_itShouldBeDoneCorrectly() {
|
public void whenUsingAddPickupTimeWindow_itShouldBeDoneCorrectly() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
@ -275,7 +284,7 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingAddPickupTimeWindow2_itShouldBeDoneCorrectly() {
|
public void whenUsingAddPickupTimeWindow2_itShouldBeDoneCorrectly() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 2)
|
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 2)
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
@ -285,7 +294,7 @@ public class ShipmentTest {
|
||||||
TimeWindow tw1 = TimeWindow.newInstance(1,2);
|
TimeWindow tw1 = TimeWindow.newInstance(1,2);
|
||||||
TimeWindow tw2 = TimeWindow.newInstance(4,5);
|
TimeWindow tw2 = TimeWindow.newInstance(4,5);
|
||||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(tw1).addPickupTimeWindow(tw2)
|
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(tw1).addPickupTimeWindow(tw2)
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals(s.getPickupTimeWindows().size(),2);
|
assertEquals(s.getPickupTimeWindows().size(),2);
|
||||||
assertThat(s.getPickupTimeWindows(), hasItem(is(tw1)));
|
assertThat(s.getPickupTimeWindows(), hasItem(is(tw1)));
|
||||||
assertThat(s.getPickupTimeWindows(), hasItem(is(tw2)));
|
assertThat(s.getPickupTimeWindows(), hasItem(is(tw2)));
|
||||||
|
|
@ -294,7 +303,7 @@ public class ShipmentTest {
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void whenAddingMultipleOverlappingPickupTimeWindows_itShouldThrowException() {
|
public void whenAddingMultipleOverlappingPickupTimeWindows_itShouldThrowException() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 3).addPickupTimeWindow(2,5)
|
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 3).addPickupTimeWindow(2,5)
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
@ -305,26 +314,26 @@ public class ShipmentTest {
|
||||||
public void whenShipmentHasNegativeCapacityVal_throwIllegalStateExpception() {
|
public void whenShipmentHasNegativeCapacityVal_throwIllegalStateExpception() {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||||
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
||||||
.addSizeDimension(0, -2)
|
.addSizeDimension(0, -2)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||||
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
||||||
.addSizeDimension(0, 2)
|
.addSizeDimension(0, 2)
|
||||||
.addSizeDimension(1, 4)
|
.addSizeDimension(1, 4)
|
||||||
.build();
|
.build();
|
||||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||||
Shipment one = Shipment.Builder.newInstance("s")
|
Shipment one = Shipment.Builder.newInstance("s")
|
||||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||||
assertEquals(0, one.getSize().get(0));
|
assertEquals(0, one.getSize().get(0));
|
||||||
}
|
}
|
||||||
|
|
@ -332,8 +341,8 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 1)
|
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 1)
|
||||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||||
assertEquals(1, one.getSize().get(0));
|
assertEquals(1, one.getSize().get(0));
|
||||||
}
|
}
|
||||||
|
|
@ -341,8 +350,8 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||||
.setDeliveryLocation(TestUtils.loc("delLoc"))
|
.setDeliveryLocation(TestUtils.loc("delLoc"))
|
||||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||||
|
|
@ -351,9 +360,9 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s")
|
Shipment s = Shipment.Builder.newInstance("s")
|
||||||
.setPickupLocation(Location.Builder.newInstance().setId("pick").build())
|
.setPickupLocation(Location.Builder.newInstance().setId("pick").build())
|
||||||
.setDeliveryLocation(TestUtils.loc("del"))
|
.setDeliveryLocation(TestUtils.loc("del"))
|
||||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||||
}
|
}
|
||||||
|
|
@ -361,8 +370,8 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||||
.setDeliveryLocation(TestUtils.loc("del"))
|
.setDeliveryLocation(TestUtils.loc("del"))
|
||||||
.addRequiredSkill("screwDriver").build();
|
.addRequiredSkill("screwDriver").build();
|
||||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||||
}
|
}
|
||||||
|
|
@ -370,15 +379,15 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void nameShouldBeAssigned() {
|
public void nameShouldBeAssigned() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||||
.setDeliveryLocation(TestUtils.loc("del"))
|
.setDeliveryLocation(TestUtils.loc("del"))
|
||||||
.setName("name").build();
|
.setName("name").build();
|
||||||
assertEquals("name", s.getName());
|
assertEquals("name", s.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSettingLocation_itShouldWork() {
|
public void whenSettingLocation_itShouldWork() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||||
.setDeliveryLocation(Location.Builder.newInstance().setId("del").build()).build();
|
.setDeliveryLocation(Location.Builder.newInstance().setId("del").build()).build();
|
||||||
assertEquals("loc", s.getPickupLocation().getId());
|
assertEquals("loc", s.getPickupLocation().getId());
|
||||||
assertEquals("loc", s.getPickupLocation().getId());
|
assertEquals("loc", s.getPickupLocation().getId());
|
||||||
assertEquals("del", s.getDeliveryLocation().getId());
|
assertEquals("del", s.getDeliveryLocation().getId());
|
||||||
|
|
@ -388,49 +397,62 @@ public class ShipmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||||
.setDeliveryLocation(Location.newInstance("loc"))
|
.setDeliveryLocation(Location.newInstance("loc"))
|
||||||
.setPriority(1).build();
|
.setPriority(1).build();
|
||||||
Assert.assertEquals(1, s.getPriority());
|
Assert.assertEquals(1, s.getPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSettingPriorities_itShouldBeSetCorrectly2(){
|
public void whenSettingPriorities_itShouldBeSetCorrectly2(){
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||||
.setDeliveryLocation(Location.newInstance("loc"))
|
.setDeliveryLocation(Location.newInstance("loc"))
|
||||||
.setPriority(3).build();
|
.setPriority(3).build();
|
||||||
Assert.assertEquals(3, s.getPriority());
|
Assert.assertEquals(3, s.getPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSettingPriorities_itShouldBeSetCorrectly3() {
|
public void whenSettingPriorities_itShouldBeSetCorrectly3() {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||||
.setDeliveryLocation(Location.newInstance("loc"))
|
.setDeliveryLocation(Location.newInstance("loc"))
|
||||||
.setPriority(10).build();
|
.setPriority(10).build();
|
||||||
Assert.assertEquals(10, s.getPriority());
|
Assert.assertEquals(10, s.getPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenNotSettingPriorities_defaultShouldBe2(){
|
public void whenNotSettingPriorities_defaultShouldBe2(){
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||||
.setDeliveryLocation(Location.newInstance("loc"))
|
.setDeliveryLocation(Location.newInstance("loc"))
|
||||||
.build();
|
.build();
|
||||||
Assert.assertEquals(2, s.getPriority());
|
Assert.assertEquals(2, s.getPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void whenSettingIncorrectPriorities_itShouldThrowException(){
|
public void whenSettingIncorrectPriorities_itShouldThrowException(){
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||||
.setDeliveryLocation(Location.newInstance("loc"))
|
.setDeliveryLocation(Location.newInstance("loc"))
|
||||||
.setPriority(30).build();
|
.setPriority(30).build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void whenSettingIncorrectPriorities_itShouldThrowException2(){
|
public void whenSettingIncorrectPriorities_itShouldThrowException2(){
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||||
.setDeliveryLocation(Location.newInstance("loc"))
|
.setDeliveryLocation(Location.newInstance("loc"))
|
||||||
.setPriority(0).build();
|
.setPriority(0).build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||||
|
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||||
|
.setDeliveryLocation(Location.newInstance("loc")).setUserData(new HashMap<String, Object>()).build();
|
||||||
|
Shipment two = Shipment.Builder.newInstance("s2").setPickupLocation(Location.newInstance("loc"))
|
||||||
|
.setDeliveryLocation(Location.newInstance("loc")).setUserData(42).build();
|
||||||
|
Shipment three = Shipment.Builder.newInstance("s3").setPickupLocation(Location.newInstance("loc"))
|
||||||
|
.setDeliveryLocation(Location.newInstance("loc")).build();
|
||||||
|
|
||||||
|
assertTrue(one.getUserData() instanceof Map);
|
||||||
|
assertEquals(42, two.getUserData());
|
||||||
|
assertNull(three.getUserData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,20 @@
|
||||||
package com.graphhopper.jsprit.core.problem.vehicle;
|
package com.graphhopper.jsprit.core.problem.vehicle;
|
||||||
|
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.graphhopper.jsprit.core.problem.Location;
|
import com.graphhopper.jsprit.core.problem.Location;
|
||||||
import com.graphhopper.jsprit.core.problem.job.Break;
|
import com.graphhopper.jsprit.core.problem.job.Break;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class VehicleImplTest {
|
public class VehicleImplTest {
|
||||||
|
|
@ -39,10 +47,10 @@ public class VehicleImplTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingDriverBreak_itShouldBeAddedCorrectly() {
|
public void whenAddingDriverBreak_itShouldBeAddedCorrectly() {
|
||||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||||
Break aBreak = (Break) Break.Builder.newInstance("break").setTimeWindow(TimeWindow.newInstance(100, 200)).setServiceTime(30).build();
|
Break aBreak = Break.Builder.newInstance("break").setTimeWindow(TimeWindow.newInstance(100, 200)).setServiceTime(30).build();
|
||||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start"))
|
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start"))
|
||||||
.setType(type1).setEndLocation(Location.newInstance("start"))
|
.setType(type1).setEndLocation(Location.newInstance("start"))
|
||||||
.setBreak(aBreak).build();
|
.setBreak(aBreak).build();
|
||||||
assertNotNull(v.getBreak());
|
assertNotNull(v.getBreak());
|
||||||
assertEquals(100., v.getBreak().getTimeWindow().getStart(), 0.1);
|
assertEquals(100., v.getBreak().getTimeWindow().getStart(), 0.1);
|
||||||
assertEquals(200., v.getBreak().getTimeWindow().getEnd(), 0.1);
|
assertEquals(200., v.getBreak().getTimeWindow().getEnd(), 0.1);
|
||||||
|
|
@ -54,7 +62,7 @@ public class VehicleImplTest {
|
||||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
||||||
.addSkill("drill").addSkill("screwdriver").build();
|
.addSkill("drill").addSkill("screwdriver").build();
|
||||||
assertTrue(v.getSkills().containsSkill("drill"));
|
assertTrue(v.getSkills().containsSkill("drill"));
|
||||||
assertTrue(v.getSkills().containsSkill("drill"));
|
assertTrue(v.getSkills().containsSkill("drill"));
|
||||||
assertTrue(v.getSkills().containsSkill("screwdriver"));
|
assertTrue(v.getSkills().containsSkill("screwdriver"));
|
||||||
|
|
@ -64,7 +72,7 @@ public class VehicleImplTest {
|
||||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
||||||
.addSkill("drill").addSkill("screwdriver").build();
|
.addSkill("drill").addSkill("screwdriver").build();
|
||||||
assertTrue(v.getSkills().containsSkill("drill"));
|
assertTrue(v.getSkills().containsSkill("drill"));
|
||||||
assertTrue(v.getSkills().containsSkill("dRill"));
|
assertTrue(v.getSkills().containsSkill("dRill"));
|
||||||
assertTrue(v.getSkills().containsSkill("ScrewDriver"));
|
assertTrue(v.getSkills().containsSkill("ScrewDriver"));
|
||||||
|
|
@ -233,9 +241,23 @@ public class VehicleImplTest {
|
||||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
||||||
.addSkill("drill").build();
|
.addSkill("drill").build();
|
||||||
assertFalse(v.getSkills().containsSkill("ScrewDriver"));
|
assertFalse(v.getSkills().containsSkill("ScrewDriver"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingUserData_itIsAssociatedWithTheVehicle() {
|
||||||
|
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||||
|
Vehicle one = VehicleImpl.Builder.newInstance("v").setType(type1)
|
||||||
|
.setStartLocation(Location.newInstance("start")).setUserData(new HashMap<String, Object>()).build();
|
||||||
|
Vehicle two = VehicleImpl.Builder.newInstance("v").setType(type1)
|
||||||
|
.setStartLocation(Location.newInstance("start")).setUserData(42).build();
|
||||||
|
Vehicle three = VehicleImpl.Builder.newInstance("v").setType(type1)
|
||||||
|
.setStartLocation(Location.newInstance("start")).build();
|
||||||
|
|
||||||
|
assertTrue(one.getUserData() instanceof Map);
|
||||||
|
assertEquals(42, two.getUserData());
|
||||||
|
assertNull(three.getUserData());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,15 @@
|
||||||
*/
|
*/
|
||||||
package com.graphhopper.jsprit.core.problem.vehicle;
|
package com.graphhopper.jsprit.core.problem.vehicle;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class VehicleTypeImplTest {
|
public class VehicleTypeImplTest {
|
||||||
|
|
||||||
|
|
@ -32,18 +38,18 @@ public class VehicleTypeImplTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t")
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t")
|
||||||
.addCapacityDimension(0, 2)
|
.addCapacityDimension(0, 2)
|
||||||
.addCapacityDimension(1, 4)
|
.addCapacityDimension(1, 4)
|
||||||
.build();
|
.build();
|
||||||
assertEquals(2, type.getCapacityDimensions().getNuOfDimensions());
|
assertEquals(2, type.getCapacityDimensions().getNuOfDimensions());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingTwoCapDimension_dimValuesMustBeCorrect() {
|
public void whenAddingTwoCapDimension_dimValuesMustBeCorrect() {
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t")
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t")
|
||||||
.addCapacityDimension(0, 2)
|
.addCapacityDimension(0, 2)
|
||||||
.addCapacityDimension(1, 4)
|
.addCapacityDimension(1, 4)
|
||||||
.build();
|
.build();
|
||||||
assertEquals(2, type.getCapacityDimensions().get(0));
|
assertEquals(2, type.getCapacityDimensions().get(0));
|
||||||
assertEquals(4, type.getCapacityDimensions().get(1));
|
assertEquals(4, type.getCapacityDimensions().get(1));
|
||||||
}
|
}
|
||||||
|
|
@ -152,4 +158,15 @@ public class VehicleTypeImplTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingUserData_itIsAssociatedWithTheVehicleType() {
|
||||||
|
VehicleType one = VehicleTypeImpl.Builder.newInstance("type").setUserData(new HashMap<String, Object>())
|
||||||
|
.build();
|
||||||
|
VehicleType two = VehicleTypeImpl.Builder.newInstance("type").setUserData(42).build();
|
||||||
|
VehicleType three = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||||
|
|
||||||
|
assertTrue(one.getUserData() instanceof Map);
|
||||||
|
assertEquals(42, two.getUserData());
|
||||||
|
assertNull(three.getUserData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue