mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
mtw
This commit is contained in:
parent
1075e38504
commit
d28471fbda
50 changed files with 753 additions and 796 deletions
|
|
@ -11,7 +11,7 @@
|
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.instance.reader;
|
||||
|
|
@ -35,16 +35,18 @@ import java.io.IOException;
|
|||
|
||||
/**
|
||||
* Reader that reads the well-known solomon-instances.
|
||||
*
|
||||
*
|
||||
* <p>See: <a href="http://neo.lcc.uma.es/vrp/vrp-instances/capacitated-vrp-with-time-windows-instances/">neo.org</a>
|
||||
*
|
||||
*
|
||||
* @author stefan
|
||||
*
|
||||
*/
|
||||
|
||||
public class BelhaizaReader {
|
||||
|
||||
/**
|
||||
private int fixedCosts;
|
||||
|
||||
/**
|
||||
* @param costProjectionFactor the costProjectionFactor to set
|
||||
*/
|
||||
public void setVariableCostProjectionFactor(double costProjectionFactor) {
|
||||
|
|
@ -73,7 +75,7 @@ public class BelhaizaReader {
|
|||
this.vrpBuilder = vrpBuilder;
|
||||
this.fixedCostPerVehicle=fixedCostPerVehicle;
|
||||
}
|
||||
|
||||
|
||||
public void read(String solomonFile){
|
||||
vrpBuilder.setFleetSize(FleetSize.INFINITE);
|
||||
BufferedReader reader = getReader(solomonFile);
|
||||
|
|
@ -95,8 +97,10 @@ public class BelhaizaReader {
|
|||
double serviceTime = Double.parseDouble(tokens[3])*timeProjectionFactor;
|
||||
if(counter == 3){
|
||||
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("solomonType").addCapacityDimension(0, vehicleCapacity);
|
||||
typeBuilder.setCostPerDistance(1.0*variableCostProjectionFactor).setFixedCost(fixedCostPerVehicle);
|
||||
VehicleTypeImpl vehicleType = typeBuilder.build();
|
||||
typeBuilder.setCostPerDistance(1.0*variableCostProjectionFactor).setFixedCost(fixedCostPerVehicle)
|
||||
.setCostPerWaitingTime(0.8);
|
||||
System.out.println("fix: " + fixedCostPerVehicle + "; perDistance: 1.0; perWaitingTime: 0.8");
|
||||
VehicleTypeImpl vehicleType = typeBuilder.build();
|
||||
double end = Double.parseDouble(tokens[8])*timeProjectionFactor;
|
||||
for(int i=0;i<10;i++) {
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("solomonVehicle"+(i+1)).setEarliestStart(0.).setLatestArrival(end)
|
||||
|
|
@ -104,7 +108,7 @@ public class BelhaizaReader {
|
|||
.setCoordinate(coord).build()).setType(vehicleType).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
Service.Builder serviceBuilder = Service.Builder.newInstance(customerId);
|
||||
|
|
@ -146,7 +150,7 @@ public class BelhaizaReader {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Coordinate makeCoord(String xString, String yString) {
|
||||
double x = Double.parseDouble(xString);
|
||||
double y = Double.parseDouble(yString);
|
||||
|
|
@ -167,6 +171,10 @@ public class BelhaizaReader {
|
|||
|
||||
public void setTimeProjectionFactor(double timeProjection) {
|
||||
this.timeProjectionFactor=timeProjection;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void setFixedCosts(int fixedCosts) {
|
||||
this.fixedCostPerVehicle = fixedCosts;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.instance.reader;
|
||||
|
|
@ -36,7 +36,7 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
|
||||
public class BelhaizaReaderTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void whenReadingBelhaizaInstance_nuOfCustomersIsCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -58,7 +58,7 @@ public class BelhaizaReaderTest {
|
|||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(FleetSize.INFINITE,vrp.getFleetSize());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenReadingBelhaizaInstance_vehicleCapacitiesAreCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -68,7 +68,7 @@ public class BelhaizaReaderTest {
|
|||
assertEquals(200,v.getType().getCapacityDimensions().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenReadingBelhaizaInstance_vehicleLocationsAreCorrect_and_correspondToDepotLocation(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -79,7 +79,7 @@ public class BelhaizaReaderTest {
|
|||
assertEquals(50.0,v.getStartLocation().getCoordinate().getY(),0.01);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenReadingBelhaizaInstance_demandOfCustomerOneIsCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -87,7 +87,7 @@ public class BelhaizaReaderTest {
|
|||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(10,vrp.getJobs().get("1").getSize().get(0));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenReadingBelhaizaInstance_serviceDurationOfCustomerTwoIsCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -101,7 +101,7 @@ public class BelhaizaReaderTest {
|
|||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new BelhaizaReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(5,((Service)vrp.getJobs().get("1")).getTimeWindows(0.).size());
|
||||
assertEquals(5,((Service)vrp.getJobs().get("1")).getTimeWindows().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -109,7 +109,7 @@ public class BelhaizaReaderTest {
|
|||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new BelhaizaReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(10,((Service)vrp.getJobs().get("2")).getTimeWindows(0.).size());
|
||||
assertEquals(10,((Service)vrp.getJobs().get("2")).getTimeWindows().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -117,8 +117,8 @@ public class BelhaizaReaderTest {
|
|||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new BelhaizaReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(20.,((Service)vrp.getJobs().get("1")).getTimeWindows(0.).iterator().next().getStart(),0.1);
|
||||
assertEquals(31.,((Service)vrp.getJobs().get("1")).getTimeWindows(0.).iterator().next().getEnd(),0.1);
|
||||
assertEquals(20.,((Service)vrp.getJobs().get("1")).getTimeWindows().iterator().next().getStart(),0.1);
|
||||
assertEquals(31.,((Service)vrp.getJobs().get("1")).getTimeWindows().iterator().next().getEnd(),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -126,7 +126,7 @@ public class BelhaizaReaderTest {
|
|||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new BelhaizaReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
List<TimeWindow> timeWindows = new ArrayList<TimeWindow>(((Service)vrp.getJobs().get("1")).getTimeWindows(0.));
|
||||
List<TimeWindow> timeWindows = new ArrayList<TimeWindow>(((Service)vrp.getJobs().get("1")).getTimeWindows());
|
||||
assertEquals(118.,timeWindows.get(1).getStart(),0.1);
|
||||
assertEquals(148.,timeWindows.get(1).getEnd(),0.1);
|
||||
}
|
||||
|
|
@ -136,7 +136,7 @@ public class BelhaizaReaderTest {
|
|||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new BelhaizaReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
List<TimeWindow> timeWindows = new ArrayList<TimeWindow>(((Service)vrp.getJobs().get("1")).getTimeWindows(0.));
|
||||
List<TimeWindow> timeWindows = new ArrayList<TimeWindow>(((Service)vrp.getJobs().get("1")).getTimeWindows());
|
||||
assertEquals(235.,timeWindows.get(2).getStart(),0.1);
|
||||
assertEquals(258.,timeWindows.get(2).getEnd(),0.1);
|
||||
}
|
||||
|
|
@ -146,7 +146,7 @@ public class BelhaizaReaderTest {
|
|||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new BelhaizaReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
List<TimeWindow> timeWindows = new ArrayList<TimeWindow>(((Service)vrp.getJobs().get("1")).getTimeWindows(0.));
|
||||
List<TimeWindow> timeWindows = new ArrayList<TimeWindow>(((Service)vrp.getJobs().get("1")).getTimeWindows());
|
||||
assertEquals(343.,timeWindows.get(3).getStart(),0.1);
|
||||
assertEquals(355.,timeWindows.get(3).getEnd(),0.1);
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ public class BelhaizaReaderTest {
|
|||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new BelhaizaReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
List<TimeWindow> timeWindows = new ArrayList<TimeWindow>(((Service)vrp.getJobs().get("1")).getTimeWindows(0.));
|
||||
List<TimeWindow> timeWindows = new ArrayList<TimeWindow>(((Service)vrp.getJobs().get("1")).getTimeWindows());
|
||||
assertEquals(441.,timeWindows.get(4).getStart(),0.1);
|
||||
assertEquals(457.,timeWindows.get(4).getEnd(),0.1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue