From 6b8e4c8a7991632710cc85305b01403d80acee7b Mon Sep 17 00:00:00 2001 From: oblonski <4sschroeder@gmail.com> Date: Wed, 16 Oct 2013 09:24:23 +0200 Subject: [PATCH] modeling shipment --- .../src/main/java/basics/Shipment.java | 198 ++++++++++++++++++ .../src/test/java/basics/ServiceTest.java | 4 +- .../src/test/java/basics/ShipmentTest.java | 5 + 3 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 jsprit-core/src/main/java/basics/Shipment.java create mode 100644 jsprit-core/src/test/java/basics/ShipmentTest.java diff --git a/jsprit-core/src/main/java/basics/Shipment.java b/jsprit-core/src/main/java/basics/Shipment.java new file mode 100644 index 00000000..2e89396f --- /dev/null +++ b/jsprit-core/src/main/java/basics/Shipment.java @@ -0,0 +1,198 @@ +package basics; + +import util.Coordinate; +import basics.route.TimeWindow; + +public class Shipment implements Job{ + + public static class Builder { + + private int demand; + + private String id; + + private String pickupLocation; + + private Coordinate pickupCoord; + + private double pickupServiceTime = 0.0; + + private String deliveryLocation; + + private Coordinate deliveryCoord; + + private double deliveryServiceTime = 0.0; + + private TimeWindow deliveryTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE); + + private TimeWindow pickupTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE);; + + public static Builder newInstance(String id, int size){ + return new Builder(id,size); + } + + Builder(String id, int size) { + if(size < 0) throw new IllegalArgumentException("size must be greater than or equal to zero"); + this.id = id; + this.demand = size; + } + + public Builder setPickupLocation(String pickupLocation){ + this.pickupLocation = pickupLocation; + return this; + } + + public Builder setPickupCoord(Coordinate pickupCoord){ + this.pickupCoord = pickupCoord; + return this; + } + + public Builder setPickupServiceTime(double serviceTime){ + this.pickupServiceTime = serviceTime; + return this; + } + + public Builder setPickupTimeWindow(TimeWindow timeWindow){ + this.pickupTimeWindow = timeWindow; + return this; + } + + public Builder setDeliveryLocation(String deliveryLocation){ + this.deliveryLocation = deliveryLocation; + return this; + } + + public Builder setDeliveryCoord(Coordinate deliveryCoord){ + this.deliveryCoord = deliveryCoord; + return this; + } + + public Builder setDeliveryServiceTime(double deliveryServiceTime){ + this.deliveryServiceTime = deliveryServiceTime; + return this; + } + + public Builder setDeliveryTimeWindow(TimeWindow timeWindow){ + this.deliveryTimeWindow = timeWindow; + return this; + } + + public Shipment build(){ + if(pickupLocation == null) { + if(pickupCoord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not."); + pickupLocation = pickupCoord.toString(); + } + if(deliveryLocation == null) { + if(deliveryCoord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not."); + deliveryLocation = deliveryCoord.toString(); + } + return new Shipment(this); + } + } + + private int demand; + + private String id; + + private String pickupLocation; + + private Coordinate pickupCoord; + + private double pickupServiceTime; + + private String deliveryLocation; + + private Coordinate deliveryCoord; + + private double deliveryServiceTime; + + private TimeWindow deliveryTimeWindow; + + private TimeWindow pickupTimeWindow; + + Shipment(Builder builder){ + this.id = builder.id; + this.demand = builder.demand; + this.pickupLocation = builder.pickupLocation; + this.pickupCoord = builder.pickupCoord; + this.pickupServiceTime = builder.pickupServiceTime; + this.pickupTimeWindow = builder.pickupTimeWindow; + this.deliveryLocation = builder.deliveryLocation; + this.deliveryCoord = builder.deliveryCoord; + this.deliveryServiceTime = builder.deliveryServiceTime; + this.deliveryTimeWindow = builder.deliveryTimeWindow; + } + + @Override + public String getId() { + return id; + } + + @Override + public int getCapacityDemand() { + return demand; + } + + public int getDemand() { + return demand; + } + + public String getPickupLocation() { + return pickupLocation; + } + + public Coordinate getPickupCoord() { + return pickupCoord; + } + + public double getPickupServiceTime() { + return pickupServiceTime; + } + + public String getDeliveryLocation() { + return deliveryLocation; + } + + public Coordinate getDeliveryCoord() { + return deliveryCoord; + } + + public double getDeliveryServiceTime() { + return deliveryServiceTime; + } + + public TimeWindow getDeliveryTimeWindow() { + return deliveryTimeWindow; + } + + public TimeWindow getPickupTimeWindow() { + return pickupTimeWindow; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Shipment other = (Shipment) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + + +} diff --git a/jsprit-core/src/test/java/basics/ServiceTest.java b/jsprit-core/src/test/java/basics/ServiceTest.java index cdefac07..9b2f39de 100644 --- a/jsprit-core/src/test/java/basics/ServiceTest.java +++ b/jsprit-core/src/test/java/basics/ServiceTest.java @@ -27,7 +27,7 @@ import org.junit.Test; public class ServiceTest { @Test - public void whenTwoServicesHaveTheSameId_theyShouldBeEqual(){ + public void whenTwoServicesHaveTheSameId_theyReferencesShouldBeUnEqual(){ Service one = Service.Builder.newInstance("service", 10).setLocationId("foo").build(); Service two = Service.Builder.newInstance("service", 10).setLocationId("fo").build(); @@ -35,7 +35,7 @@ public class ServiceTest { } @Test - public void whenTwoServicesHaveTheSameId_theyShouldBeEqual2(){ + public void whenTwoServicesHaveTheSameId_theyShouldBeEqual(){ Service one = Service.Builder.newInstance("service", 10).setLocationId("foo").build(); Service two = Service.Builder.newInstance("service", 10).setLocationId("fo").build(); diff --git a/jsprit-core/src/test/java/basics/ShipmentTest.java b/jsprit-core/src/test/java/basics/ShipmentTest.java new file mode 100644 index 00000000..d33cab30 --- /dev/null +++ b/jsprit-core/src/test/java/basics/ShipmentTest.java @@ -0,0 +1,5 @@ +package basics; + +public class ShipmentTest { + +}