1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00
This commit is contained in:
Stefan Schroeder 2013-06-04 10:25:47 +02:00
commit 3581d6e097
435 changed files with 46952 additions and 0 deletions

View file

@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import algorithms.acceptors.AcceptNewRemoveWorstTest;
import algorithms.selectors.SelectBestTest;
import algorithms.selectors.SelectRandomlyTest;
@RunWith(Suite.class)
@Suite.SuiteClasses({
CalcVehicleTypeDependentServiceInsertionTest.class,
// FindCheaperVehicleTest.class,
GendreauPostOptTest.class,
TestAlgorithmReader.class,
// TestAux.class,
TestCalculatesActivityInsertion.class,
TestCalculatesServiceInsertion.class,
TestCalculatesServiceInsertionOnRouteLevel.class,
TestJobDistanceAvgCosts.class,
TestTourStateUpdaterWithService.class,
SelectBestTest.class,
SelectRandomlyTest.class,
AcceptNewRemoveWorstTest.class,
// TestUpdateTourStatesForwardInTime.class
})
public class AlgorithmsSuite {}

View file

@ -0,0 +1,106 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import algorithms.VehicleFleetManager.TypeKey;
import basics.Service;
import basics.route.TimeWindow;
import basics.route.Vehicle;
import basics.route.VehicleImpl;
import basics.route.VehicleRoute;
public class CalcVehicleTypeDependentServiceInsertionTest {
Vehicle veh1;
Vehicle veh2;
VehicleFleetManager fleetManager;
Service service;
VehicleRoute vehicleRoute;
@Before
public void doBefore(){
veh1 = mock(Vehicle.class);
veh2 = mock(Vehicle.class);
when(veh1.getType()).thenReturn(VehicleImpl.VehicleType.Builder.newInstance("type1", 0).build());
when(veh2.getType()).thenReturn(VehicleImpl.VehicleType.Builder.newInstance("type2", 0).build());
when(veh1.getLocationId()).thenReturn("loc1");
when(veh2.getLocationId()).thenReturn("loc2");
fleetManager = mock(VehicleFleetManager.class);
service = mock(Service.class);
vehicleRoute = mock(VehicleRoute.class);
TypeKey typeKey1 = new TypeKey(veh1.getType(),veh1.getLocationId());
TypeKey typeKey2 = new TypeKey(veh2.getType(),veh2.getLocationId());
when(fleetManager.getAvailableVehicleTypes()).thenReturn(Arrays.asList(typeKey1,typeKey2));
when(fleetManager.getEmptyVehicle(typeKey1)).thenReturn(veh1);
when(fleetManager.getEmptyVehicle(typeKey2)).thenReturn(veh2);
when(veh1.getCapacity()).thenReturn(10);
when(veh2.getCapacity()).thenReturn(10);
when(service.getCapacityDemand()).thenReturn(0);
when(service.getTimeWindow()).thenReturn(TimeWindow.newInstance(0.0, Double.MAX_VALUE));
when(vehicleRoute.getDriver()).thenReturn(null);
when(vehicleRoute.getVehicle()).thenReturn(VehicleImpl.createNoVehicle());
}
@Test
public void whenHaving2Vehicle_calcInsertionOfCheapest(){
JobInsertionCalculator calc = mock(JobInsertionCalculator.class);
InsertionData iDataVeh1 = new InsertionData(10.0,InsertionData.NO_INDEX, 1, veh1, null);
InsertionData iDataVeh2 = new InsertionData(20.0,InsertionData.NO_INDEX, 1, veh2, null);
when(calc.calculate(vehicleRoute, service, veh1, veh1.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh1);
when(calc.calculate(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh2);
when(calc.calculate(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, 10.0)).thenReturn(iDataVeh2);
CalculatesVehTypeDepServiceInsertion insertion = new CalculatesVehTypeDepServiceInsertion(fleetManager,calc);
InsertionData iData = insertion.calculate(vehicleRoute, service, null, 0.0, null, Double.MAX_VALUE);
assertThat(iData.getSelectedVehicle(), is(veh1));
}
@Test
public void whenHaving2Vehicle_calcInsertionOfCheapest2(){
JobInsertionCalculator calc = mock(JobInsertionCalculator.class);
InsertionData iDataVeh1 = new InsertionData(20.0,InsertionData.NO_INDEX, 1, veh1, null);
InsertionData iDataVeh2 = new InsertionData(10.0,InsertionData.NO_INDEX, 1, veh2, null);
when(calc.calculate(vehicleRoute, service, veh1, veh1.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh1);
when(calc.calculate(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh2);
when(calc.calculate(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, 20.0)).thenReturn(iDataVeh2);
CalculatesVehTypeDepServiceInsertion insertion = new CalculatesVehTypeDepServiceInsertion(fleetManager,calc);
InsertionData iData = insertion.calculate(vehicleRoute, service, null, 0.0, null, Double.MAX_VALUE);
assertThat(iData.getSelectedVehicle(), is(veh2));
}
}

View file

@ -0,0 +1,94 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms;
import static org.junit.Assert.assertEquals;
import java.util.Collection;
import util.Coordinate;
import util.Solutions;
import algorithms.selectors.SelectBest;
import basics.Service;
import basics.VehicleRoutingAlgorithm;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblem.FleetSize;
import basics.VehicleRoutingProblemSolution;
import basics.costs.VehicleRoutingTransportCosts;
import basics.route.Driver;
import basics.route.Vehicle;
import basics.route.VehicleImpl;
import basics.route.VehicleImpl.VehicleType;
import basics.route.VehicleRoute;
public class CalcWithTimeSchedulingTest {
public void timeScheduler(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("myVehicle").setEarliestStart(0.0).setLatestArrival(100.0).
setLocationCoord(Coordinate.newInstance(0, 0)).setLocationId("0,0")
.setType(VehicleType.Builder.newInstance("myType", 20).setCostPerDistance(1.0).build()).build();
vrpBuilder.addVehicle(vehicle);
vrpBuilder.addService(Service.Builder.newInstance("myService", 2).setLocationId("0,20").setCoord(Coordinate.newInstance(0, 20)).build());
vrpBuilder.setFleetSize(FleetSize.INFINITE);
VehicleRoutingProblem vrp = vrpBuilder.build();
vrp.setTransportCosts(getTpCosts(vrp.getTransportCosts()));
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/testConfig.xml");
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
VehicleRoutingProblemSolution sol = Solutions.getBest(solutions);
assertEquals(40.0,sol.getCost(),0.01);
assertEquals(1, sol.getRoutes().size());
VehicleRoute route = sol.getRoutes().iterator().next();
assertEquals(50.0,route.getStart().getEndTime(),0.01);
}
private VehicleRoutingTransportCosts getTpCosts(final VehicleRoutingTransportCosts baseCosts) {
return new VehicleRoutingTransportCosts() {
@Override
public double getBackwardTransportCost(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
return getTransportCost(fromId, toId, arrivalTime, driver, vehicle);
}
@Override
public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
if(departureTime < 50){
return baseCosts.getTransportCost(fromId, toId, departureTime, driver, vehicle)*2.0;
}
return baseCosts.getTransportCost(fromId, toId, departureTime, driver, vehicle);
}
@Override
public double getBackwardTransportTime(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
return getTransportTime(fromId, toId, arrivalTime, driver, vehicle);
}
@Override
public double getTransportTime(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
return getTransportCost(fromId, toId, departureTime, driver, vehicle);
}
};
}
}

View file

@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms;
import basics.costs.VehicleRoutingActivityCosts;
import basics.costs.VehicleRoutingActivityCosts.Time;
import basics.route.Driver;
import basics.route.TourActivity;
import basics.route.Vehicle;
import basics.route.TourActivity.JobActivity;
public class ExampleActivityCostFunction implements VehicleRoutingActivityCosts{
public ExampleActivityCostFunction() {
super();
}
public double parameter_timeAtAct;
public double parameter_penaltyTooLate;
@Override
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
if(arrivalTime == Time.TOURSTART || arrivalTime == Time.UNDEFINED ){
return 0.0;
}
else{
//waiting + act-time
double endTime = Math.max(arrivalTime, tourAct.getTheoreticalEarliestOperationStartTime()) + tourAct.getOperationTime();
double timeAtAct = endTime - arrivalTime;
double totalCost = timeAtAct * parameter_timeAtAct;
//penalty tooLate
if(tourAct instanceof JobActivity){
if(arrivalTime > tourAct.getTheoreticalLatestOperationStartTime()){
double penTime = arrivalTime - tourAct.getTheoreticalLatestOperationStartTime();
totalCost += penTime * parameter_penaltyTooLate;
}
}
return totalCost;
}
}
}

View file

@ -0,0 +1,259 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
//package algorithms;
//
//import static org.hamcrest.CoreMatchers.is;
//import static org.junit.Assert.assertThat;
//
//import java.util.ArrayList;
//import java.util.Collection;
//
//import org.junit.Before;
//import org.junit.Test;
//
//import util.ManhattanDistanceCalculator;
//import algorithms.FindCheaperVehicleAlgo;
//import algorithms.TourStateUpdater;
//import basics.Coordinate;
//import basics.Driver;
//import basics.Service;
//import basics.TimeWindow;
//import basics.Tour;
//import basics.TourBuilder;
//import basics.Vehicle;
//import basics.VehicleFleetManager;
//import basics.VehicleFleetManagerImpl;
//import basics.VehicleImpl;
//import basics.VehicleRoute;
//import basics.VehicleRoutingCosts;
//import basics.VehicleImpl.Type;
//
//
//public class FindCheaperVehicleTest {
//
// Tour tour;
//
// Vehicle heavyVehicle;
//
// Vehicle lightVehicle;
//
// VehicleRoutingCosts cost;
//
// @Before
// public void setUp(){
//
// cost = new VehicleRoutingCosts() {
//
// @Override
// public double getBackwardTransportTime(String fromId, String toId,
// double arrivalTime, Driver driver, Vehicle vehicle) {
// // TODO Auto-generated method stub
// return 0;
// }
//
// @Override
// public double getBackwardTransportCost(String fromId, String toId,
// double arrivalTime, Driver driver, Vehicle vehicle) {
// // TODO Auto-generated method stub
// return 0;
// }
//
// @Override
// public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
//
// String[] fromTokens = fromId.split(",");
// String[] toTokens = toId.split(",");
// double fromX = Double.parseDouble(fromTokens[0]);
// double fromY = Double.parseDouble(fromTokens[1]);
//
// double toX = Double.parseDouble(toTokens[0]);
// double toY = Double.parseDouble(toTokens[1]);
//
// return vehicle.getType().vehicleCostParams.perDistanceUnit*ManhattanDistanceCalculator.calculateDistance(new Coordinate(fromX, fromY), new Coordinate(toX, toY));
// }
//
// @Override
// public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
// return 0;
// }
// };
//
// Type lightType = VehicleImpl.TypeBuilder.newInstance().setId("light").setCapacity(10).setFixedCost(1.0).setCostPerDistance(1.0).build();
// lightVehicle = VehicleImpl.VehicleBuilder.newInstance("light").setLocationId("0,0").setType(lightType).build();
//
// Type heavyType = VehicleImpl.TypeBuilder.newInstance().setId("heavy").setCapacity(10).setFixedCost(2.0).setCostPerDistance(2.0).build();
// heavyVehicle = VehicleImpl.VehicleBuilder.newInstance("heavy").setLocationId("0,0").setType(heavyType).build();
// }
//
// @Test
// public void runCheaperVehicle_lightIsCheaperThanHeavy_changeVehicle(){
// TourStateUpdater tourStateCalculator = new TourStateUpdater(cost, new ExampleTransportCostFunction());
//
// TourBuilder tourBuilder = new TourBuilder();
// Service firstShipment = getService("10,0");
// tourBuilder.scheduleStart("0,0", 0.0, Double.MAX_VALUE);
// tourBuilder.scheduleDeliveryService(firstShipment);
// tourBuilder.scheduleEnd("0,0", 0.0, Double.MAX_VALUE);
//
// Tour tour = tourBuilder.build();
//
// VehicleRoute route = new VehicleRoute(tour,new Driver(){},heavyVehicle);
// tourStateCalculator.updateTour(route);
//
// Collection<Vehicle> vehicles = new ArrayList<Vehicle>();
// vehicles.add(lightVehicle);
// vehicles.add(heavyVehicle);
// VehicleFleetManager fleetManager = new VehicleFleetManagerImpl(vehicles);
// fleetManager.lock(heavyVehicle);
//
// FindCheaperVehicleAlgo findCheaperVehicle = new FindCheaperVehicleAlgo(fleetManager, tourStateCalculator);
// VehicleRoute newRoute = findCheaperVehicle.runAndGetVehicleRoute(route);
//
// assertThat(lightVehicle, is(newRoute.getVehicle()));
// }
//
// @Test
// public void runCheaperVehicle_costComparisonBetweenHeavyAndLight_keepHeavy(){
//
//
// Type lightType = VehicleImpl.TypeBuilder.newInstance().setId("light").setCapacity(10).setFixedCost(1.0).setCostPerDistance(1.0).build();
// lightVehicle = VehicleImpl.VehicleBuilder.newInstance("light").setLocationId("0,0").setType(lightType).build();
//
// Type heavyType = VehicleImpl.TypeBuilder.newInstance().setId("heavy").setCapacity(10).setFixedCost(2.0).setCostPerDistance(1.0).build();
// heavyVehicle = VehicleImpl.VehicleBuilder.newInstance("heavy").setLocationId("0,0").setType(heavyType).build();
//
//
// TourStateUpdater tourStateCalculator = new TourStateUpdater(cost, new ExampleTransportCostFunction());
//
// TourBuilder tourBuilder = new TourBuilder();
// Service firstShipment = getService("10,0");
// tourBuilder.scheduleStart("0,0", 0.0, Double.MAX_VALUE);
// tourBuilder.scheduleDeliveryService(firstShipment);
// tourBuilder.scheduleEnd("0,0", 0.0, Double.MAX_VALUE);
//
// Tour tour = tourBuilder.build();
//
//
// VehicleRoute route = new VehicleRoute(tour,new Driver(){},heavyVehicle);
// tourStateCalculator.updateTour(route);
//
// Collection<Vehicle> vehicles = new ArrayList<Vehicle>();
// vehicles.add(lightVehicle);
// vehicles.add(heavyVehicle);
// VehicleFleetManager fleetManager = new VehicleFleetManagerImpl(vehicles);
// fleetManager.lock(heavyVehicle);
//
// FindCheaperVehicleAlgo findCheaperVehicle = new FindCheaperVehicleAlgo(fleetManager, tourStateCalculator);
// findCheaperVehicle.setWeightFixCosts(0.0);
// VehicleRoute newRoute = findCheaperVehicle.runAndGetVehicleRoute(route);
//
// assertThat(heavyVehicle, is(newRoute.getVehicle()));
//
// }
//
// @Test
// public void runCheaperVehicle_lightIsTheCheapest_doNotChangeVehicle(){
// TourBuilder tourBuilder = new TourBuilder();
// Service firstShipment = getService("10,0");
// tourBuilder.scheduleStart("0,0", 0.0, Double.MAX_VALUE);
// tourBuilder.scheduleDeliveryService(firstShipment);
// tourBuilder.scheduleEnd("0,0", 0.0, Double.MAX_VALUE);
//
// VehicleRoute route = new VehicleRoute(tourBuilder.build(),new Driver(){},lightVehicle);
//
// Collection<Vehicle> vehicles = new ArrayList<Vehicle>();
// vehicles.add(lightVehicle);
// vehicles.add(heavyVehicle);
// VehicleFleetManager fleetManager = new VehicleFleetManagerImpl(vehicles);
// fleetManager.lock(heavyVehicle);
//
// TourStateUpdater tourStateCalculator = new TourStateUpdater(cost, new ExampleTransportCostFunction());
// FindCheaperVehicleAlgo findCheaperVehicle = new FindCheaperVehicleAlgo(fleetManager, tourStateCalculator);
// VehicleRoute newRoute = findCheaperVehicle.runAndGetVehicleRoute(route);
//
// assertThat(lightVehicle, is(newRoute.getVehicle()));
//
//
// }
//
// @Test
// public void runCheaperVehicle_noAlterativeVehicle_doNotChangeVehicle(){
// TourBuilder tourBuilder = new TourBuilder();
// Service firstShipment = getService("10,0");
// tourBuilder.scheduleStart("0,0", 0.0, Double.MAX_VALUE);
// tourBuilder.scheduleDeliveryService(firstShipment);
// tourBuilder.scheduleEnd("0,0", 0.0, Double.MAX_VALUE);
//
// VehicleRoute route = new VehicleRoute(tourBuilder.build(),new Driver(){},heavyVehicle);
//
// Collection<Vehicle> vehicles = new ArrayList<Vehicle>();
//// vehicles.add(lightVehicle);
// vehicles.add(heavyVehicle);
// VehicleFleetManager fleetManager = new VehicleFleetManagerImpl(vehicles);
// fleetManager.lock(heavyVehicle);
//
// TourStateUpdater tourStateCalculator = new TourStateUpdater(cost, new ExampleTransportCostFunction());
// FindCheaperVehicleAlgo findCheaperVehicle = new FindCheaperVehicleAlgo(fleetManager, tourStateCalculator);
// VehicleRoute newRoute = findCheaperVehicle.runAndGetVehicleRoute(route);
//
//
// assertThat(heavyVehicle, is(newRoute.getVehicle()));
//
// }
//
// @Test
// public void runCheaperVehicle_noTour_throwException(){
// TourBuilder tourBuilder = new TourBuilder();
// Service firstShipment = getService("10,0");
// tourBuilder.scheduleStart("0,0", 0.0, Double.MAX_VALUE);
// tourBuilder.scheduleDeliveryService(firstShipment);
// tourBuilder.scheduleEnd("0,0", 0.0, Double.MAX_VALUE);
//
// VehicleRoute route = new VehicleRoute(null,null,heavyVehicle);
//
// Collection<Vehicle> vehicles = new ArrayList<Vehicle>();
//// vehicles.add(lightVehicle);
// vehicles.add(heavyVehicle);
// VehicleFleetManager fleetManager = new VehicleFleetManagerImpl(vehicles);
// fleetManager.lock(heavyVehicle);
//
// TourStateUpdater tourStateCalculator = new TourStateUpdater(cost, new ExampleTransportCostFunction());
// FindCheaperVehicleAlgo findCheaperVehicle = new FindCheaperVehicleAlgo(fleetManager, tourStateCalculator);
// VehicleRoute newRoute = findCheaperVehicle.runAndGetVehicleRoute(route);
//
// assertThat(heavyVehicle, is(newRoute.getVehicle()));
// }
//
// private Service getService(String to, double serviceTime) {
// Service s = Service.Builder.newInstance("s", 0).setLocationId(to).setServiceTime(serviceTime).setTimeWindow(TimeWindow.newInstance(0.0, 20.0)).build();
// return s;
// }
//
// private Service getService(String to) {
// Service s = getService(to, 0.0);
// return s;
// }
//
//
//
//
//
//}

View file

@ -0,0 +1,285 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import util.Coordinate;
import util.ManhattanDistanceCalculator;
import util.RouteUtils;
import basics.Job;
import basics.Service;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblemSolution;
import basics.costs.VehicleRoutingTransportCosts;
import basics.route.Driver;
import basics.route.DriverImpl;
import basics.route.TimeWindow;
import basics.route.TourActivities;
import basics.route.Vehicle;
import basics.route.VehicleImpl;
import basics.route.VehicleImpl.VehicleType;
import basics.route.VehicleRoute;
public class GendreauPostOptTest {
TourActivities tour;
Vehicle heavyVehicle;
Vehicle lightVehicle1;
Vehicle lightVehicle2;
VehicleRoutingTransportCosts cost;
VehicleRoutingProblem vrp;
Service job1;
Service job2;
Service job3;
private RouteStates states;
private List<Vehicle> vehicles;
private TourStateUpdater updater;
private VehicleFleetManagerImpl fleetManager;
private RouteAlgorithmImpl routeAlgorithm;
@Before
public void setUp(){
cost = new VehicleRoutingTransportCosts() {
@Override
public double getBackwardTransportTime(String fromId, String toId,
double arrivalTime, Driver driver, Vehicle vehicle) {
// TODO Auto-generated method stub
return 0;
}
@Override
public double getBackwardTransportCost(String fromId, String toId,
double arrivalTime, Driver driver, Vehicle vehicle) {
// TODO Auto-generated method stub
return 0;
}
@Override
public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
String[] fromTokens = fromId.split(",");
String[] toTokens = toId.split(",");
double fromX = Double.parseDouble(fromTokens[0]);
double fromY = Double.parseDouble(fromTokens[1]);
double toX = Double.parseDouble(toTokens[0]);
double toY = Double.parseDouble(toTokens[1]);
double costPerDistanceUnit;
if(vehicle != null){
costPerDistanceUnit = vehicle.getType().vehicleCostParams.perDistanceUnit;
}
else{
costPerDistanceUnit = 1;
}
return costPerDistanceUnit*ManhattanDistanceCalculator.calculateDistance(new Coordinate(fromX, fromY), new Coordinate(toX, toY));
}
@Override
public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
return 0;
}
};
VehicleType lightType = VehicleImpl.VehicleType.Builder.newInstance("light", 10).setFixedCost(10).setCostPerDistance(1.0).build();
VehicleType heavyType = VehicleImpl.VehicleType.Builder.newInstance("heavy", 10).setFixedCost(30).setCostPerDistance(2.0).build();
lightVehicle1 = VehicleImpl.VehicleBuilder.newInstance("light").setLocationId("0,0").setType(lightType).build();
lightVehicle2 = VehicleImpl.VehicleBuilder.newInstance("light2").setLocationId("0,0").setType(lightType).build();
heavyVehicle = VehicleImpl.VehicleBuilder.newInstance("heavy").setLocationId("0,0").setType(heavyType).build();
job1 = getService("10,0");
job2 = getService("10,10");
job3 = getService("0,10");
Collection<Job> jobs = new ArrayList<Job>();
jobs.add(job1);
jobs.add(job2);
jobs.add(job3);
vehicles = Arrays.asList(lightVehicle1,lightVehicle2, heavyVehicle);
// Collection<Vehicle> vehicles = Arrays.asList(lightVehicle1,lightVehicle2, heavyVehicle);
fleetManager = new VehicleFleetManagerImpl(vehicles);
states = new RouteStates();
ExampleActivityCostFunction activityCosts = new ExampleActivityCostFunction();
CalculatesServiceInsertion standardServiceInsertion = new CalculatesServiceInsertion(cost, activityCosts);
standardServiceInsertion.setActivityStates(states);
CalculatesServiceInsertionConsideringFixCost withFixCost = new CalculatesServiceInsertionConsideringFixCost(standardServiceInsertion, states);
withFixCost.setWeightOfFixCost(1.2);
final JobInsertionCalculator vehicleTypeDepInsertionCost = new CalculatesVehTypeDepServiceInsertion(fleetManager, withFixCost);
updater = new TourStateUpdater(states, cost, activityCosts);
routeAlgorithm = RouteAlgorithmImpl.newInstance(vehicleTypeDepInsertionCost, updater);
routeAlgorithm.setActivityStates(states);
if(fleetManager != null){
routeAlgorithm.getListeners().add(new RouteAlgorithm.VehicleSwitchedListener() {
@Override
public void vehicleSwitched(Vehicle oldVehicle, Vehicle newVehicle) {
fleetManager.unlock(oldVehicle);
fleetManager.lock(newVehicle);
}
});
}
}
@Test
public void whenPostOpt_splitsTour_oneActiveTourBecomeTwoSeperateActiveTours(){
Collection<Job> jobs = new ArrayList<Job>();
jobs.add(job1);
jobs.add(job2);
states.initialiseStateOfJobs(jobs);
vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addAllVehicles(vehicles).setRoutingCost(cost).build();
TourActivities tour = new TourActivities();
tour.addActivity(states.getActivity(job1, true));
tour.addActivity(states.getActivity(job2, true));
VehicleRoute route = VehicleRoute.newInstance(tour,DriverImpl.noDriver(),heavyVehicle);
updater.updateRoute(route);
fleetManager.lock(heavyVehicle);
Collection<VehicleRoute> routes = new ArrayList<VehicleRoute>();
routes.add(route);
// routes.add(new VehicleRoute(getEmptyTour(),getDriver(),getNoVehicle()));
// routes.add(new VehicleRoute(getEmptyTour(),getDriver(),getNoVehicle()));
VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(routes, route.getCost());
assertEquals(110.0, sol.getCost(), 0.5);
RuinRadial radialRuin = RuinRadial.newInstance(vrp, 0.2, new JobDistanceAvgCosts(vrp.getTransportCosts()), new JobRemoverImpl(), updater);
AbstractInsertionStrategy insertionStrategy = new BestInsertion(routeAlgorithm);
GendreauPostOpt postOpt = new GendreauPostOpt(vrp, radialRuin, insertionStrategy);
postOpt.setFleetManager(fleetManager);
VehicleRoutingProblemSolution newSolution = postOpt.runAndGetSolution(sol);
assertEquals(2,RouteUtils.getNuOfActiveRoutes(newSolution.getRoutes()));
assertEquals(2,newSolution.getRoutes().size());
assertEquals(80.0,newSolution.getCost(),0.5);
}
@Test
public void whenPostOpt_optsRoutesWithMoreThanTwoJobs_oneRouteBecomesTwoRoutes(){
Collection<Job> jobs = new ArrayList<Job>();
jobs.add(job1);
jobs.add(job2);
jobs.add(job3);
states.initialiseStateOfJobs(jobs);
vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addAllVehicles(vehicles).setRoutingCost(cost).build();
TourActivities tour = new TourActivities();
tour.addActivity(states.getActivity(job1, true));
tour.addActivity(states.getActivity(job2, true));
tour.addActivity(states.getActivity(job3, true));
VehicleRoute route = VehicleRoute.newInstance(tour,DriverImpl.noDriver(),heavyVehicle);
updater.updateRoute(route);
fleetManager.lock(heavyVehicle);
Collection<VehicleRoute> routes = new ArrayList<VehicleRoute>();
routes.add(route);
// routes.add(new VehicleRoute(getEmptyTour(),getDriver(),getNoVehicle()));
// routes.add(new VehicleRoute(getEmptyTour(),getDriver(),getNoVehicle()));
VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(routes, route.getCost());
assertEquals(110.0, sol.getCost(), 0.5);
RuinRadial radialRuin = RuinRadial.newInstance(vrp, 0.2, new JobDistanceAvgCosts(vrp.getTransportCosts()), new JobRemoverImpl(), updater);
AbstractInsertionStrategy insertionStrategy = new BestInsertion(routeAlgorithm);
GendreauPostOpt postOpt = new GendreauPostOpt(vrp, radialRuin, insertionStrategy);
postOpt.setShareOfJobsToRuin(1.0);
postOpt.setNuOfIterations(1);
postOpt.setFleetManager(fleetManager);
// postOpt.setWithFix(withFixCost);
VehicleRoutingProblemSolution newSolution = postOpt.runAndGetSolution(sol);
assertEquals(2,RouteUtils.getNuOfActiveRoutes(newSolution.getRoutes()));
assertEquals(2,newSolution.getRoutes().size());
assertEquals(80.0,newSolution.getCost(),0.5);
}
private Vehicle getNoVehicle() {
return new VehicleImpl.NoVehicle();
}
private Driver getDriver() {
return DriverImpl.noDriver();
}
private TourActivities getEmptyTour() {
return new TourActivities();
}
private Service getService(String to, double serviceTime) {
Service s = Service.Builder.newInstance(to, 0).setLocationId(to).setServiceTime(serviceTime).setTimeWindow(TimeWindow.newInstance(0.0, 20.0)).build();
return s;
}
private Service getService(String to) {
Service s = getService(to, 0.0);
return s;
}
}

View file

@ -0,0 +1,289 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.junit.Before;
import org.junit.Test;
import algorithms.VehicleRoutingAlgorithms.ModKey;
import algorithms.VehicleRoutingAlgorithms.TypedMap.AcceptorKey;
import algorithms.VehicleRoutingAlgorithms.TypedMap.RuinStrategyKey;
import algorithms.VehicleRoutingAlgorithms.TypedMap.SelectorKey;
import algorithms.VehicleRoutingAlgorithms.TypedMap.StrategyModuleKey;
import algorithms.acceptors.AcceptNewIfBetterThanWorst;
import algorithms.acceptors.SolutionAcceptor;
import algorithms.selectors.SelectBest;
import algorithms.selectors.SolutionSelector;
import basics.Job;
import basics.VehicleRoutingAlgorithm;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblemSolution;
import basics.algo.SearchStrategy;
import basics.algo.SearchStrategyModule;
import basics.algo.SearchStrategyModuleListener;
import basics.io.VrpXMLReader;
import basics.route.VehicleRoute;
public class TestAlgorithmReader {
XMLConfiguration config;
VehicleRoutingProblem vrp;
Collection<VehicleRoutingProblemSolution> solutions;
@Before
public void doBefore() throws ConfigurationException{
config = new XMLConfiguration("src/test/resources/testConfig.xml");
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
solutions = new ArrayList<VehicleRoutingProblemSolution>();
new VrpXMLReader(vrpBuilder,solutions).read("src/test/resources/finiteVrpForReaderV2Test.xml");
vrp = vrpBuilder.build();
}
@Test
public void testTypedMap(){
algorithms.VehicleRoutingAlgorithms.TypedMap typedMap = new algorithms.VehicleRoutingAlgorithms.TypedMap();
String acceptorName = "acceptor";
String acceptorId = "acceptorId";
ModKey key = new ModKey(acceptorName,acceptorId);
AcceptorKey accKey = new AcceptorKey(key);
SolutionAcceptor acceptor = new AcceptNewIfBetterThanWorst(1);
typedMap.put(accKey, acceptor);
assertEquals(acceptor,typedMap.get(accKey));
}
@Test
public void testTypedMap2(){
algorithms.VehicleRoutingAlgorithms.TypedMap typedMap = new algorithms.VehicleRoutingAlgorithms.TypedMap();
String acceptorName = "acceptor";
String acceptorId = "acceptorId";
String selectorName = "selector";
String selectorId = "selectorId";
ModKey key = new ModKey(acceptorName,acceptorId);
AcceptorKey accKey = new AcceptorKey(key);
SolutionAcceptor acceptor = new AcceptNewIfBetterThanWorst(1);
SelectorKey selKey = new SelectorKey(new ModKey(selectorName,selectorId));
SolutionSelector selector = new SelectBest();
typedMap.put(accKey, acceptor);
typedMap.put(selKey, selector);
assertEquals(acceptor,typedMap.get(accKey));
assertEquals(selector, typedMap.get(selKey));
}
@Test
public void testTypedMap3(){
algorithms.VehicleRoutingAlgorithms.TypedMap typedMap = new algorithms.VehicleRoutingAlgorithms.TypedMap();
String acceptorName = "acceptor";
String acceptorId = "acceptorId";
String acceptorName2 = "acceptor2";
String acceptorId2 = "acceptorId2";
String selectorName = "selector";
String selectorId = "selectorId";
ModKey key = new ModKey(acceptorName,acceptorId);
AcceptorKey accKey = new AcceptorKey(key);
SolutionAcceptor acceptor = new AcceptNewIfBetterThanWorst(1);
SelectorKey selKey = new SelectorKey(new ModKey(selectorName,selectorId));
SolutionSelector selector = new SelectBest();
AcceptorKey accKey2 = new AcceptorKey(new ModKey(acceptorName2,acceptorId2));
SolutionAcceptor acceptor2 = new AcceptNewIfBetterThanWorst(1);
typedMap.put(accKey, acceptor);
typedMap.put(selKey, selector);
typedMap.put(accKey2, acceptor2);
assertEquals(acceptor,typedMap.get(accKey));
assertEquals(selector, typedMap.get(selKey));
assertEquals(acceptor2,typedMap.get(accKey2));
}
@Test
public void testTypedMap4(){
algorithms.VehicleRoutingAlgorithms.TypedMap typedMap = new algorithms.VehicleRoutingAlgorithms.TypedMap();
String acceptorName = "acceptor";
String acceptorId = "acceptorId";
String moduleName = "acceptor";
String moduleId = "acceptorId";
ModKey key = new ModKey(acceptorName,acceptorId);
RuinStrategyKey accKey = new RuinStrategyKey(key);
RuinStrategy acceptor = new RuinStrategy(){
@Override
public Collection<Job> ruin(Collection<VehicleRoute> vehicleRoutes) {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Job> ruin(Collection<VehicleRoute> vehicleRoutes,
Job targetJob, int nOfJobs2BeRemoved) {
// TODO Auto-generated method stub
return null;
}
};
StrategyModuleKey moduleKey = new StrategyModuleKey(key);
SearchStrategyModule stratModule = new SearchStrategyModule() {
@Override
public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) {
return null;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public void addModuleListener(
SearchStrategyModuleListener moduleListener) {
// TODO Auto-generated method stub
}
};;;
typedMap.put(accKey, acceptor);
typedMap.put(moduleKey, stratModule);
typedMap.put(moduleKey, stratModule);
assertEquals(acceptor,typedMap.get(accKey));
assertEquals(stratModule, typedMap.get(moduleKey));
}
@Test
public void initialiseConstructionAlgoCorrectly(){
VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, config);
assertTrue(true);
}
@Test
public void whenCreatingAlgorithm_nOfStrategiesIsCorrect(){
VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, config);
assertEquals(3, algo.getSearchStrategyManager().getStrategies().size());
}
@Test
public void whenCreatingAlgorithm_nOfIterationsIsReadCorrectly(){
VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, config);
assertEquals(10, algo.getNuOfIterations());
}
@Test
public void whenCreatingAlgorithm_nOfStrategyModulesIsCorrect(){
VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, config);
int nOfModules = 0;
for(SearchStrategy strat : algo.getSearchStrategyManager().getStrategies()){
nOfModules += strat.getSearchStrategyModules().size();
}
assertEquals(6, nOfModules);
}
@Test
public void whenCreatingAlgorithm_nOfUniqueInstancesOfInsertionModulesIsCorrect(){
VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, config);
int nOfBestInsertions = 0;
Set<SearchStrategyModule> uniqueStrategies = new HashSet<SearchStrategyModule>();
for(SearchStrategy strat : algo.getSearchStrategyManager().getStrategies()){
for(SearchStrategyModule module : strat.getSearchStrategyModules()){
if(module.getName().equals("bestInsertion")){
nOfBestInsertions++;
uniqueStrategies.add(module);
}
}
}
assertEquals(3, nOfBestInsertions);
assertEquals(2, uniqueStrategies.size());
}
@Test
public void whenCreatingAlgorithm_nOfUniqueInstancesOfRuinModulesIsCorrect(){
VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, config);
int nOfRuinModules = 0;
Set<SearchStrategyModule> uniqueStrategies = new HashSet<SearchStrategyModule>();
for(SearchStrategy strat : algo.getSearchStrategyManager().getStrategies()){
for(SearchStrategyModule module : strat.getSearchStrategyModules()){
if(module.getName().endsWith("Ruin")){
nOfRuinModules++;
uniqueStrategies.add(module);
}
}
}
assertEquals(3, nOfRuinModules);
assertEquals(2, uniqueStrategies.size());
}
@Test
public void whenCreatingAlgorithm_regretInsertionIsReadCorrectly(){
VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/configWithRegretInsertion.xml");
int nOfModules = 0;
for(SearchStrategy strat : algo.getSearchStrategyManager().getStrategies()){
for(SearchStrategyModule module : strat.getSearchStrategyModules()){
if(module.getName().contains("ruin_and_recreate")){
nOfModules++;
}
}
}
assertEquals(3, nOfModules);
}
}

View file

@ -0,0 +1,218 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
//package algorithms;
//
//import java.util.ArrayList;
//import java.util.Collection;
//import java.util.List;
//
//import junit.framework.TestCase;
//
//import org.junit.Test;
//
//import util.EuclideanDistanceCalculator;
//import basics.Coordinate;
//import basics.Driver;
//import basics.Job;
//import basics.Service;
//import basics.TimeWindow;
//import basics.Tour;
//import basics.TourActivity;
//import basics.TourBuilder;
//import basics.Vehicle;
//import basics.VehicleRoutingTransportCosts;
//
//
//public class TestAuxilliaryCostCalculatorWithServices extends TestCase{
//
// AuxilliaryCostCalculator costCalc;
//
// Tour tour;
//
// public void setUp(){
//
// VehicleRoutingTransportCosts cost = new VehicleRoutingTransportCosts() {
//
// @Override
// public double getBackwardTransportTime(String fromId, String toId,
// double arrivalTime, Driver driver, Vehicle vehicle) {
// // TODO Auto-generated method stub
// return 0;
// }
//
// @Override
// public double getBackwardTransportCost(String fromId, String toId,
// double arrivalTime, Driver driver, Vehicle vehicle) {
// // TODO Auto-generated method stub
// return 0;
// }
//
// @Override
// public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
// String[] fromTokens = fromId.split(",");
// String[] toTokens = toId.split(",");
// double fromX = Double.parseDouble(fromTokens[0]);
// double fromY = Double.parseDouble(fromTokens[1]);
//
// double toX = Double.parseDouble(toTokens[0]);
// double toY = Double.parseDouble(toTokens[1]);
//
// return EuclideanDistanceCalculator.calculateDistance(new Coordinate(fromX, fromY), new Coordinate(toX, toY));
// }
//
// @Override
// public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
//
// return 0;
// }
// };
//
// costCalc = AuxilliaryCostCalculator.newInstance(cost, new ExampleTransportCostFunction());
//
// Service firstService = Service.Builder.newInstance("1", 0).setLocationId("10,0").setTimeWindow(TimeWindow.newInstance(0, 20)).build();
// Service secondService = Service.Builder.newInstance("2", 0).setLocationId("0,10").setTimeWindow(TimeWindow.newInstance(0, 20)).build();
//
// Collection<Job> services = new ArrayList<Job>();
// services.add(firstService);
// services.add(secondService);
//
// ActivityStates states = new ActivityStates();
// states.initialiseStateOfJobs(services);
//
// TourBuilder tourBuilder = new TourBuilder();
//
// tourBuilder.scheduleStart("0,0", 0.0, Double.MAX_VALUE);
// tourBuilder.addActivity(states.getActivity(firstService,true));
// tourBuilder.addActivity(states.getActivity(secondService,true));
// tourBuilder.scheduleEnd("0,0", 0.0, Double.MAX_VALUE);
//
// tour = tourBuilder.build();
// costCalc.setActivityStates(states);
//
// }
//
//// @Test
//// public void testGetPath(){
//// List<TourActivity> path = AuxilliaryCostCalculator.getPath(tour,tour.getStart(), tour.getActivities().get(1));
//// assertEquals(3,path.size());
//// }
////
//// @Test
//// public void testGetPath_withEnd(){
//// List<TourActivity> path = AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(0), tour.getEnd());
//// assertEquals(3,path.size());
//// }
//
//
//// public void testCalcTourCost(){
//// List<TourActivity> path = AuxilliaryCostCalculator.getPath(tour,tour.getStart(), tour.getActivities().get(1));
//// assertEquals(0.0, costCalc.costOfPath(path,0.0,null,null));
//// }
//
//// public void testCalcTourCost2(){
//// assertEquals(10.0, costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(0), tour.getActivities().get(2)),0.0,null,null));
//// }
////
//// public void testCalcTourCost3(){
//// assertEquals(20.0, costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(2), tour.getActivities().get(6)),0.0,null,null));
//// }
////
//// public void testCalcTourCost4(){
//// assertEquals(30.0, costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(0), tour.getActivities().get(6)),0.0,null,null));
//// }
////
//// public void testCalcTourCost5(){
//// assertEquals(40.0, costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(1), tour.getActivities().get(7)),0.0,null,null));
//// }
//
//// public void testCalcTourCost6(){
//// assertEquals(0.0, costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(1), tour.getActivities().get(1)),0.0,null,null));
//// }
////
//// public void testCalcTourCost7(){
//// try{
//// double c =costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(1), tour.getActivities().get(0)),0.0,null,null);
//// assertTrue(false);
//// }
//// catch(AssertionError e){
//// assertTrue(true);
//// }
//// catch(IllegalArgumentException e){
//// assertTrue(true);
//// }
//// }
////
//// public void testCalcTourCost8(){
//// try{
//// Shipment s = getShipment("10,10","0,10");
//// TourActivity pickup = new Pickup(s);
////
//// double c = costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(0), pickup),0.0,null,null);
//// assertTrue(false);
//// }
//// catch(AssertionError e){
//// assertTrue(true);
//// }
//// catch(IllegalArgumentException e){
//// assertTrue(true);
//// }
//// }
////
//// public void testBoundary1(){
//// assertEquals(40.0, costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(1), tour.getActivities().get(tour.getActivities().size()-1)),0.0,null,null));
//// }
////
//// public void testBoundary2(){
//// try{
//// costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(tour.getActivities().size()-1), tour.getActivities().get(0)),0.0,null,null);
//// assertTrue(false);
//// }
//// catch(AssertionError e){
//// assertTrue(true);
//// }
//// catch(IllegalArgumentException e){
//// assertTrue(true);
//// }
//// }
////
////// public void testBoundary3(){
////// assertEquals(40.0, costCalc.calculateCost(tour, tour.getActivities().getFirst(), tour.getActivities().getLast(), Double.MAX_VALUE, null, null));
////// }
//////
////// public void testBoundary4(){
////// try{
////// costCalc.calculateCost(tour, tour.getActivities().getFirst(), tour.getActivities().getLast(), (-1)*Double.MAX_VALUE, null, null);
////// assertTrue(false);
////// }
////// catch(AssertionError e){
////// assertTrue(true);
////// }
////// }
////
////
////
//// private Shipment getShipment(String string, String string2) {
//// Shipment s = Shipment.Builder.newInstance("first", 0).setFromId(string).setToId(string2).setPickupTW(TimeWindow.newInstance(0.0, 20.0)).setDeliveryTW(TimeWindow.newInstance(0.0, 20.0)).build();
//// return s;
//// }
////
//}

View file

@ -0,0 +1,286 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import algorithms.RouteStates.ActivityState;
import basics.costs.VehicleRoutingTransportCosts;
import basics.route.TourActivities;
import basics.route.TourActivity;
import basics.route.Vehicle;
import basics.route.VehicleRoute;
public class TestCalculatesActivityInsertion {
VehicleRoutingTransportCosts costs;
Vehicle newVehicle;
private RouteStates states;
private CalculatesActivityInsertionWithHardTimeWindows insertionCalculator;
@Before
public void setup(){
costs = mock(VehicleRoutingTransportCosts.class);
newVehicle = mock(Vehicle.class);
when(costs.getTransportCost("depot", "1", 0.0, null, null)).thenReturn(10.0);
when(costs.getTransportCost("depot", "2", 0.0, null, null)).thenReturn(20.0);
when(costs.getTransportCost("depot", "3", 0.0, null, null)).thenReturn(10.0);
when(costs.getTransportCost("1", "2", 0.0, null, null)).thenReturn(10.0);
when(costs.getTransportCost("1", "3", 0.0, null, null)).thenReturn(20.0);
when(costs.getTransportCost("2", "3", 0.0, null, null)).thenReturn(10.0);
when(costs.getTransportCost("1", "depot", 0.0, null, null)).thenReturn(10.0);
when(costs.getTransportCost("2", "depot", 0.0, null, null)).thenReturn(20.0);
when(costs.getTransportCost("3", "depot", 0.0, null, null)).thenReturn(10.0);
when(costs.getTransportCost("2", "1", 0.0, null, null)).thenReturn(10.0);
when(costs.getTransportCost("3", "1", 0.0, null, null)).thenReturn(20.0);
when(costs.getTransportCost("3", "2", 0.0, null, null)).thenReturn(10.0);
when(costs.getTransportCost("depot", "1", 0.0, null, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("depot", "2", 0.0, null, newVehicle)).thenReturn(40.0);
when(costs.getTransportCost("depot", "3", 0.0, null, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("1", "2", 0.0, null, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("1", "3", 0.0, null, newVehicle)).thenReturn(40.0);
when(costs.getTransportCost("2", "3", 0.0, null, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("1", "depot", 0.0, null, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("2", "depot", 0.0, null, newVehicle)).thenReturn(40.0);
when(costs.getTransportCost("3", "depot", 0.0, null, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("2", "1", 0.0, null, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("3", "1", 0.0, null, newVehicle)).thenReturn(40.0);
when(costs.getTransportCost("3", "2", 0.0, null, newVehicle)).thenReturn(20.0);
states = new RouteStates();
insertionCalculator = new CalculatesActivityInsertionWithHardTimeWindows(states,costs,activityCosts());
}
private ExampleActivityCostFunction activityCosts() {
return new ExampleActivityCostFunction();
}
public TourActivity getActivityMock(String id, double earliestOperationStart, double currCost){
TourActivity act = mock(TourActivity.class);
when(act.getLocationId()).thenReturn(id);
states.getActivityStates().put(act, new ActivityState(act));
states.getState(act).setEarliestOperationStart(earliestOperationStart);
states.getState(act).setCurrentCost(currCost);
// when(act.getEarliestOperationStartTime()).thenReturn(earliestOperationStart);
// when(act.getCurrentCost()).thenReturn(currCost);
return act;
}
@Test
public void whenInsertingANewJob_itCalculatesMarginalCostChanges(){
VehicleRoute vehicleRoute = VehicleRoute.emptyRoute();
TourActivities tour = mock(TourActivities.class);
TourActivity start = getActivityMock("depot", 0.0, 0.0);
TourActivity prevAct = getActivityMock("1", 0.0, 10.0);
TourActivity nextAct = getActivityMock("3", 0.0, 30.0);
TourActivity act2insert = getActivityMock("2", 0.0, 0.0);
TourActivity end = getActivityMock("depot", 0.0, 40.0);
vehicleRoute.getTourActivities().addActivity(start);
vehicleRoute.getTourActivities().addActivity(prevAct);
vehicleRoute.getTourActivities().addActivity(nextAct);
vehicleRoute.getTourActivities().addActivity(end);
List<TourActivity> activities = Arrays.asList(start,prevAct,nextAct,end);
when(tour.getActivities()).thenReturn(activities);
// when(states.getRouteState(vehicleRoute).getCosts()).thenReturn(40.0);
double c = insertionCalculator.calculate(vehicleRoute, prevAct, nextAct, act2insert, null, null);
assertEquals(0.0,c,0.2);
}
@Test
public void whenInsertingANewJob_itCalculatesMarginalCostChanges2(){
VehicleRoute vehicleRoute = VehicleRoute.emptyRoute();
TourActivities tour = mock(TourActivities.class);
TourActivity start = getActivityMock("depot", 0.0, 0.0);
TourActivity act1 = getActivityMock("1", 0.0, 10.0);
TourActivity act3 = getActivityMock("3", 0.0, 0.0);
TourActivity act2 = getActivityMock("2", 0.0, 20.0);
TourActivity end = getActivityMock("depot", 0.0, 40.0);
vehicleRoute.getTourActivities().addActivity(start);
vehicleRoute.getTourActivities().addActivity(act1);
vehicleRoute.getTourActivities().addActivity(act2);
vehicleRoute.getTourActivities().addActivity(end);
List<TourActivity> activities = Arrays.asList(start,act1,act2,end);
when(tour.getActivities()).thenReturn(activities);
double c = insertionCalculator.calculate(vehicleRoute, act1, act2, act3, null, null);
assertEquals(20.0,c,0.2);
}
@Test
public void whenInsertingANewJob_itCalculatesMarginalCostChanges3(){
VehicleRoute vehicleRoute = VehicleRoute.emptyRoute();
TourActivities tour = mock(TourActivities.class);
TourActivity start = getActivityMock("depot", 0.0, 0.0);
TourActivity act1 = getActivityMock("1", 0.0, 10.0);
TourActivity act3 = getActivityMock("3", 0.0, 0.0);
TourActivity act2 = getActivityMock("2", 0.0, 0.0);
TourActivity end = getActivityMock("depot", 0.0, 20.0);
vehicleRoute.getTourActivities().addActivity(start);
vehicleRoute.getTourActivities().addActivity(act1);
vehicleRoute.getTourActivities().addActivity(end);
List<TourActivity> activities = Arrays.asList(start,act1,end);
when(tour.getActivities()).thenReturn(activities);
double c = insertionCalculator.calculate(vehicleRoute, start, act1, act3, null, null);
assertEquals(20.0,c,0.2);
}
@Test
public void whenInsertingANewJobWithANewVehicle_itCalculatesLocalMarginalCostChanges(){
VehicleRoute vehicleRoute = VehicleRoute.emptyRoute();
TourActivities tour = mock(TourActivities.class);
TourActivity start = getActivityMock("depot", 0.0, 0.0);
TourActivity act1 = getActivityMock("1", 0.0, 10.0);
TourActivity act3 = getActivityMock("3", 0.0, 0.0);
TourActivity act2 = getActivityMock("2", 0.0, 20.0);
TourActivity end = getActivityMock("depot", 0.0, 40.0);
vehicleRoute.getTourActivities().addActivity(start);
vehicleRoute.getTourActivities().addActivity(act1);
vehicleRoute.getTourActivities().addActivity(act2);
vehicleRoute.getTourActivities().addActivity(end);
List<TourActivity> activities = Arrays.asList(start,act1,act2,end);
when(tour.getActivities()).thenReturn(activities);
double c = insertionCalculator.calculate(vehicleRoute, act1, act2, act3, null, newVehicle);
assertEquals(50.0,c,0.2);
}
@Test
public void whenInsertingANewJobWithANewVehicle_itCalculatesLocalMarginalCostChangesAndAfterInsertionCostChanges(){
VehicleRoute vehicleRoute = VehicleRoute.emptyRoute();
TourActivities tour = mock(TourActivities.class);
TourActivity start = getActivityMock("depot", 0.0, 0.0);
TourActivity act1 = getActivityMock("1", 0.0, 10.0);
TourActivity act3 = getActivityMock("3", 0.0, 0.0);
TourActivity act2 = getActivityMock("2", 0.0, 20.0);
TourActivity end = getActivityMock("depot", 0.0, 40.0);
vehicleRoute.getTourActivities().addActivity(start);
vehicleRoute.getTourActivities().addActivity(act1);
vehicleRoute.getTourActivities().addActivity(act2);
vehicleRoute.getTourActivities().addActivity(end);
List<TourActivity> activities = Arrays.asList(start,act1,act2,end);
when(tour.getActivities()).thenReturn(activities);
double c = insertionCalculator.calculate(vehicleRoute, act1, act2, act3, null, newVehicle);
assertEquals(50.0,c,0.2);
}
//already on route-level
// @Test
// public void whenInsertingANewJobWithANewVehicle_itCalculatesTotalMarginalCostChanges(){
// Tour tour = mock(Tour.class);
// TourActivity start = getActivityMock("depot", 0.0, 0.0);
// TourActivity act1 = getActivityMock("1", 0.0, 10.0);
// TourActivity act3 = getActivityMock("3", 0.0, 0.0);
// TourActivity act2 = getActivityMock("2", 0.0, 20.0);
// TourActivity end = getActivityMock("depot", 0.0, 40.0);
//
// List<TourActivity> activities = Arrays.asList(start,act1,act2,end);
// when(tour.getActivities()).thenReturn(activities);
//
// double c = insertionCalculator.calculate(tour, act1, act2, act3, null, newVehicle);
// assertEquals(80.0,c,0.2);
// }
@Test
public void whenInsertingANewJobWithANewVehicle_itCalculatesTotalMarginalCostChanges2(){
VehicleRoute vehicleRoute = VehicleRoute.emptyRoute();
TourActivities tour = mock(TourActivities.class);
TourActivity start = getActivityMock("depot", 0.0, 0.0);
TourActivity act1 = getActivityMock("1", 0.0, 10.0);
TourActivity act3 = getActivityMock("3", 0.0, 0.0);
TourActivity act2 = getActivityMock("2", 0.0, 20.0);
TourActivity end = getActivityMock("depot", 0.0, 40.0);
vehicleRoute.getTourActivities().addActivity(start);
vehicleRoute.getTourActivities().addActivity(act1);
vehicleRoute.getTourActivities().addActivity(act2);
vehicleRoute.getTourActivities().addActivity(end);
List<TourActivity> activities = Arrays.asList(start,act1,act2,end);
when(tour.getActivities()).thenReturn(activities);
double c = insertionCalculator.calculate(vehicleRoute, act2, end, act3, null, newVehicle);
assertEquals(20.0,c,0.2);
}
@Test
public void whenInsertingANewJobWithANewVehicle_itCalculatesTotalMarginalCostChanges3(){
VehicleRoute vehicleRoute = VehicleRoute.emptyRoute();
TourActivities tour = mock(TourActivities.class);
TourActivity start = getActivityMock("depot", 0.0, 0.0);
TourActivity act1 = getActivityMock("1", 0.0, 10.0);
TourActivity act3 = getActivityMock("3", 0.0, 0.0);
TourActivity act2 = getActivityMock("2", 0.0, 20.0);
TourActivity end = getActivityMock("depot", 0.0, 40.0);
vehicleRoute.getTourActivities().addActivity(start);
vehicleRoute.getTourActivities().addActivity(act1);
vehicleRoute.getTourActivities().addActivity(act2);
vehicleRoute.getTourActivities().addActivity(end);
List<TourActivity> activities = Arrays.asList(start,act1,act2,end);
when(tour.getActivities()).thenReturn(activities);
double c = insertionCalculator.calculate(vehicleRoute, start, act1, act3, null, newVehicle);
assertEquals(50.0,c,0.2);
}
}

View file

@ -0,0 +1,261 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import basics.Job;
import basics.Service;
import basics.costs.VehicleRoutingTransportCosts;
import basics.route.DriverImpl;
import basics.route.TimeWindow;
import basics.route.TourActivities;
import basics.route.TourActivity;
import basics.route.Vehicle;
import basics.route.VehicleRoute;
import basics.route.DriverImpl.NoDriver;
public class TestCalculatesServiceInsertion {
CalculatesServiceInsertion serviceInsertion;
VehicleRoutingTransportCosts costs;
Vehicle vehicle;
Vehicle newVehicle;
private Service first;
private Service second;
private Service third;
private RouteStates states;
private TourStateUpdater tourStateUpdater;
private NoDriver driver;
@Before
public void setup(){
Logger.getRootLogger().setLevel(Level.DEBUG);
costs = mock(VehicleRoutingTransportCosts.class);
vehicle = mock(Vehicle.class);
when(vehicle.getCapacity()).thenReturn(1000);
when(vehicle.getLocationId()).thenReturn("depot");
when(vehicle.getEarliestDeparture()).thenReturn(0.0);
when(vehicle.getLatestArrival()).thenReturn(100.0);
newVehicle = mock(Vehicle.class);
when(newVehicle.getCapacity()).thenReturn(1000);
when(newVehicle.getLocationId()).thenReturn("depot");
when(newVehicle.getEarliestDeparture()).thenReturn(0.0);
when(newVehicle.getLatestArrival()).thenReturn(100.0);
driver = DriverImpl.noDriver();
when(costs.getTransportCost("depot", "1", 0.0, driver, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("depot", "2", 0.0, driver, vehicle)).thenReturn(20.0);
when(costs.getTransportCost("depot", "3", 0.0, driver, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("1", "2", 0.0, driver, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("1", "3", 0.0, driver, vehicle)).thenReturn(20.0);
when(costs.getTransportCost("2", "3", 0.0, driver, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("1", "depot", 0.0, driver, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("2", "depot", 0.0, driver, vehicle)).thenReturn(20.0);
when(costs.getTransportCost("3", "depot", 0.0, driver, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("2", "1", 0.0, driver, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("3", "1", 0.0, driver, vehicle)).thenReturn(20.0);
when(costs.getTransportCost("3", "2", 0.0, driver, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("depot", "1", 0.0, driver, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("depot", "2", 0.0, driver, newVehicle)).thenReturn(40.0);
when(costs.getTransportCost("depot", "3", 0.0, driver, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("1", "2", 0.0, driver, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("1", "3", 0.0, driver, newVehicle)).thenReturn(40.0);
when(costs.getTransportCost("2", "3", 0.0, driver, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("1", "depot", 0.0, driver, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("2", "depot", 0.0, driver, newVehicle)).thenReturn(40.0);
when(costs.getTransportCost("3", "depot", 0.0, driver, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("2", "1", 0.0, driver, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("3", "1", 0.0, driver, newVehicle)).thenReturn(40.0);
when(costs.getTransportCost("3", "2", 0.0, driver, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("depot", "1", 0.0, null, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("depot", "2", 0.0, null, vehicle)).thenReturn(20.0);
when(costs.getTransportCost("depot", "3", 0.0, null, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("1", "2", 0.0, null, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("1", "3", 0.0, null, vehicle)).thenReturn(20.0);
when(costs.getTransportCost("2", "3", 0.0, null, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("1", "depot", 0.0, null, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("2", "depot", 0.0, null, vehicle)).thenReturn(20.0);
when(costs.getTransportCost("3", "depot", 0.0, null, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("2", "1", 0.0, null, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("3", "1", 0.0, null, vehicle)).thenReturn(20.0);
when(costs.getTransportCost("3", "2", 0.0, null, vehicle)).thenReturn(10.0);
when(costs.getTransportCost("depot", "1", 0.0, null, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("depot", "2", 0.0, null, newVehicle)).thenReturn(40.0);
when(costs.getTransportCost("depot", "3", 0.0, null, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("1", "2", 0.0, null, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("1", "3", 0.0, null, newVehicle)).thenReturn(40.0);
when(costs.getTransportCost("2", "3", 0.0, null, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("1", "depot", 0.0, null, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("2", "depot", 0.0, null, newVehicle)).thenReturn(40.0);
when(costs.getTransportCost("3", "depot", 0.0, null, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("2", "1", 0.0, null, newVehicle)).thenReturn(20.0);
when(costs.getTransportCost("3", "1", 0.0, null, newVehicle)).thenReturn(40.0);
when(costs.getTransportCost("3", "2", 0.0, null, newVehicle)).thenReturn(20.0);
first = Service.Builder.newInstance("1", 0).setLocationId("1").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
second = Service.Builder.newInstance("3", 0).setLocationId("3").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
third = Service.Builder.newInstance("2", 0).setLocationId("2").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
Collection<Job> jobs = new ArrayList<Job>();
jobs.add(first);
jobs.add(second);
jobs.add(third);
states = new RouteStates();
states.initialiseStateOfJobs(jobs);
ExampleActivityCostFunction activityCosts = new ExampleActivityCostFunction();
serviceInsertion = new CalculatesServiceInsertion(costs, activityCosts);
serviceInsertion.setActivityStates(states);
tourStateUpdater = new TourStateUpdater(states, costs, activityCosts);
}
public TourActivity getActivityMock(String id, double earliestOperationStart, double currCost){
TourActivity act = mock(TourActivity.class);
when(act.getLocationId()).thenReturn(id);
return act;
}
@Test
public void whenInsertingTheFirstJobInAnEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){
TourActivities tour = new TourActivities();
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
tourStateUpdater.updateRoute(route);
InsertionData iData = serviceInsertion.calculate(route, first, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
assertEquals(20.0, iData.getInsertionCost(), 0.2);
assertEquals(0, iData.getDeliveryInsertionIndex());
}
@Test
public void whenInsertingTheSecondJobInAnNonEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){
TourActivities tour = new TourActivities();
tour.addActivity(states.getActivity(first, true));
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
tourStateUpdater.updateRoute(route);
InsertionData iData = serviceInsertion.calculate(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
assertEquals(20.0, iData.getInsertionCost(), 0.2);
assertEquals(0, iData.getDeliveryInsertionIndex());
}
@Test
public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges(){
TourActivities tour = new TourActivities();
tour.addActivity(states.getActivity(first,true));
tour.addActivity(states.getActivity(second,true));
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
tourStateUpdater.updateRoute(route);
InsertionData iData = serviceInsertion.calculate(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
assertEquals(0.0, iData.getInsertionCost(), 0.2);
assertEquals(1, iData.getDeliveryInsertionIndex());
}
@Test
public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges(){
TourActivities tour = new TourActivities();
tour.addActivity(states.getActivity(first,true));
tour.addActivity(states.getActivity(second,true));
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
tourStateUpdater.updateRoute(route);
InsertionData iData = serviceInsertion.calculate(route, third, newVehicle, newVehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
assertEquals(20.0, iData.getInsertionCost(), 0.2);
assertEquals(1, iData.getDeliveryInsertionIndex());
}
@Test
public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges(){
TourActivities tour = new TourActivities();
tour.addActivity(states.getActivity(first,true));
tour.addActivity(states.getActivity(third,true));
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
tourStateUpdater.updateRoute(route);
InsertionData iData = serviceInsertion.calculate(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
assertEquals(0.0, iData.getInsertionCost(), 0.2);
assertEquals(2, iData.getDeliveryInsertionIndex());
}
@Test
public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges(){
TourActivities tour = new TourActivities();
tour.addActivity(states.getActivity(first,true));
tour.addActivity(states.getActivity(third,true));
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
// route.addActivity(states.getActivity(first,true));
// route.addActivity(states.getActivity(third,true));
tourStateUpdater.updateRoute(route);
InsertionData iData = serviceInsertion.calculate(route, second, newVehicle, newVehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
assertEquals(20.0, iData.getInsertionCost(), 0.2);
assertEquals(2, iData.getDeliveryInsertionIndex());
}
}

View file

@ -0,0 +1,276 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import util.Coordinate;
import util.ManhattanDistanceCalculator;
import basics.Job;
import basics.Service;
import basics.costs.VehicleRoutingTransportCosts;
import basics.route.Driver;
import basics.route.DriverImpl;
import basics.route.TimeWindow;
import basics.route.TourActivities;
import basics.route.TourActivity;
import basics.route.Vehicle;
import basics.route.VehicleRoute;
import basics.route.DriverImpl.NoDriver;
public class TestCalculatesServiceInsertionOnRouteLevel {
CalculatesServiceInsertionOnRouteLevel serviceInsertion;
VehicleRoutingTransportCosts costs;
Vehicle vehicle;
Vehicle newVehicle;
private Service first;
private Service second;
private Service third;
private RouteStates states;
private TourStateUpdater tourStateUpdater;
private NoDriver driver;
@Before
public void setup(){
Logger.getRootLogger().setLevel(Level.DEBUG);
costs = mock(VehicleRoutingTransportCosts.class);
vehicle = mock(Vehicle.class);
when(vehicle.getCapacity()).thenReturn(1000);
when(vehicle.getLocationId()).thenReturn("0,0");
when(vehicle.getEarliestDeparture()).thenReturn(0.0);
when(vehicle.getLatestArrival()).thenReturn(100.0);
newVehicle = mock(Vehicle.class);
when(newVehicle.getCapacity()).thenReturn(1000);
when(newVehicle.getLocationId()).thenReturn("0,0");
when(newVehicle.getEarliestDeparture()).thenReturn(0.0);
when(newVehicle.getLatestArrival()).thenReturn(100.0);
driver = DriverImpl.noDriver();
costs = new VehicleRoutingTransportCosts() {
@Override
public double getBackwardTransportTime(String fromId, String toId,
double arrivalTime, Driver driver, Vehicle vehicle) {
// TODO Auto-generated method stub
return 0;
}
@Override
public double getBackwardTransportCost(String fromId, String toId,
double arrivalTime, Driver driver, Vehicle vehicle) {
// TODO Auto-generated method stub
return 0;
}
@Override
public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle veh) {
String[] fromTokens = fromId.split(",");
String[] toTokens = toId.split(",");
double fromX = Double.parseDouble(fromTokens[0]);
double fromY = Double.parseDouble(fromTokens[1]);
double toX = Double.parseDouble(toTokens[0]);
double toY = Double.parseDouble(toTokens[1]);
double dist = ManhattanDistanceCalculator.calculateDistance(new Coordinate(fromX, fromY), new Coordinate(toX, toY));
if(veh == vehicle){
return dist;
}
else if(veh == newVehicle){
return 2*dist;
}
throw new IllegalStateException();
}
@Override
public double getTransportTime(String fromId, String toId,
double departureTime, Driver driver, Vehicle vehicle) {
// TODO Auto-generated method stub
return 0;
}
};
first = Service.Builder.newInstance("1", 0).setLocationId("0,10").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
second = Service.Builder.newInstance("3", 0).setLocationId("10,0").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
third = Service.Builder.newInstance("2", 0).setLocationId("10,10").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
Collection<Job> jobs = new ArrayList<Job>();
jobs.add(first);
jobs.add(second);
jobs.add(third);
states = new RouteStates();
states.initialiseStateOfJobs(jobs);
ExampleActivityCostFunction activityCosts = new ExampleActivityCostFunction();
serviceInsertion = new CalculatesServiceInsertionOnRouteLevel(costs,activityCosts);
serviceInsertion.setNuOfActsForwardLooking(4);
serviceInsertion.setActivityStates(states);
tourStateUpdater = new TourStateUpdater(states, costs, activityCosts);
}
public TourActivity getActivityMock(String id, double earliestOperationStart, double currCost){
TourActivity act = mock(TourActivity.class);
when(act.getLocationId()).thenReturn(id);
return act;
}
@Test
public void whenInsertingTheFirstJobInAnEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){
TourActivities tour = new TourActivities();
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
tourStateUpdater.updateRoute(route);
InsertionData iData = serviceInsertion.calculate(route, first, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
assertEquals(20.0, iData.getInsertionCost(), 0.2);
assertEquals(0, iData.getDeliveryInsertionIndex());
}
// @Test
// public void whenInsertingTheSecondJobInAnNonEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){
// TourActivities tour = new TourActivities();
// tour.addActivity(states.getActivity(first, true));
//
// VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
// tourStateUpdater.updateRoute(route);
//
// InsertionData iData = serviceInsertion.calculate(route, second, vehicle, null, Double.MAX_VALUE);
// assertEquals(20.0, iData.getInsertionCost(), 0.2);
// assertEquals(1, iData.getDeliveryInsertionIndex());
// }
// @Test
// public void whenInsertingTheSecotndJobInAnNonEmptyTourWithNewVehicle_itCalculatesMarginalCostChanges(){
// TourActivities tour = new TourActivities();
// tour.addActivity(states.getActivity(first, true));
//
// VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
// tourStateUpdater.updateRoute(route);
//
// InsertionData iData = serviceInsertion.calculate(route, second, newVehicle, null, Double.MAX_VALUE);
// assertEquals(40.0, iData.getInsertionCost(), 0.2);
// assertEquals(1, iData.getDeliveryInsertionIndex());
// }
@Test
public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges(){
TourActivities tour = new TourActivities();
tour.addActivity(states.getActivity(first,true));
tour.addActivity(states.getActivity(second,true));
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
tourStateUpdater.updateRoute(route);
InsertionData iData = serviceInsertion.calculate(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
assertEquals(0.0, iData.getInsertionCost(), 0.2);
assertEquals(1, iData.getDeliveryInsertionIndex());
}
@Test
public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges(){
TourActivities tour = new TourActivities();
tour.addActivity(states.getActivity(first,true));
tour.addActivity(states.getActivity(second,true));
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
tourStateUpdater.updateRoute(route);
InsertionData iData = serviceInsertion.calculate(route, third, newVehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
assertEquals(40.0, iData.getInsertionCost(), 0.2);
assertEquals(1, iData.getDeliveryInsertionIndex());
}
@Test
public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges(){
TourActivities tour = new TourActivities();
tour.addActivity(states.getActivity(first,true));
tour.addActivity(states.getActivity(third,true));
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
tourStateUpdater.updateRoute(route);
InsertionData iData = serviceInsertion.calculate(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
assertEquals(0.0, iData.getInsertionCost(), 0.2);
assertEquals(2, iData.getDeliveryInsertionIndex());
}
@Test
public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges(){
TourActivities tour = new TourActivities();
tour.addActivity(states.getActivity(first,true));
tour.addActivity(states.getActivity(third,true));
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
tourStateUpdater.updateRoute(route);
InsertionData iData = serviceInsertion.calculate(route, second, newVehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
assertEquals(40.0, iData.getInsertionCost(), 0.2);
assertEquals(2, iData.getDeliveryInsertionIndex());
}
// @Test
// public void whenInsertingFirstJobWithANewVehicle_itCalculatesLocalMarginalCostChanges(){
// TourActivities tour = new TourActivities();
// tour.addActivity(states.getActivity(third,true));
// tour.addActivity(states.getActivity(second,true));
//
// VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
// tourStateUpdater.updateRoute(route);
//
// InsertionData iData = serviceInsertion.calculate(route, second, newVehicle, null, Double.MAX_VALUE);
// assertEquals(40.0, iData.getInsertionCost(), 0.2);
// assertEquals(2, iData.getDeliveryInsertionIndex());
// }
}

View file

@ -0,0 +1,212 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import java.util.Collection;
import org.junit.Test;
import util.Coordinate;
import util.Solutions;
import basics.Service;
import basics.VehicleRoutingAlgorithm;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblemSolution;
import basics.costs.VehicleRoutingActivityCosts;
import basics.route.Driver;
import basics.route.TimeWindow;
import basics.route.TourActivity;
import basics.route.Vehicle;
import basics.route.VehicleImpl;
import basics.route.VehicleImpl.VehicleType;
public class TestDepartureTimeOpt {
@Test
public void whenSettingOneCustWithTWAnd_NO_DepTimeChoice_totalCostsShouldBe50(){
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
VehicleType type = mock(VehicleType.class);
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
.setType(VehicleType.Builder.newInstance("vType", 0).build()).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addService(service).addVehicle(vehicle).build();
vrp.setActivityCosts(new VehicleRoutingActivityCosts(){
@Override
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime)*1;
double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime())*100;
return waiting + late;
}
});
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
assertEquals(20.0+30.0,Solutions.getBest(solutions).getCost(),0.1);
}
@Test
public void whenSettingOneCustWithTWAnd_NO_DepTimeChoice_depTimeShouldBe0(){
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
VehicleType type = mock(VehicleType.class);
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
.setType(VehicleType.Builder.newInstance("vType", 0).build()).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addService(service).addVehicle(vehicle).build();
vrp.setActivityCosts(new VehicleRoutingActivityCosts(){
@Override
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime)*1;
double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime())*100;
return waiting + late;
}
});
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
assertEquals(0.0,Solutions.getBest(solutions).getRoutes().iterator().next().getStart().getEndTime(),0.1);
}
@Test
public void whenSettingOneCustWithTWAndDepTimeChoice_totalCostsShouldBe50(){
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
.setType(VehicleType.Builder.newInstance("vType", 0).build()).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addService(service).addVehicle(vehicle).build();
vrp.setActivityCosts(new VehicleRoutingActivityCosts(){
@Override
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime)*1;
double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime())*100;
return waiting + late;
}
});
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml");
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
assertEquals(20.0,Solutions.getBest(solutions).getCost(),0.1);
}
@Test
public void whenSettingOneCustWithTWAndDepTimeChoice_depTimeShouldBe0(){
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
.setType(VehicleType.Builder.newInstance("vType", 0).build()).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addService(service).addVehicle(vehicle).build();
vrp.setActivityCosts(new VehicleRoutingActivityCosts(){
@Override
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime)*1;
double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime())*100;
return waiting + late;
}
});
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml");
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
assertEquals(30.0,Solutions.getBest(solutions).getRoutes().iterator().next().getStart().getEndTime(),0.1);
}
@Test
public void whenSettingTwoCustWithTWAndDepTimeChoice_totalCostsShouldBe50(){
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
Service service2 = Service.Builder.newInstance("s2", 0).setLocationId("servLoc2").setCoord(Coordinate.newInstance(0, 20)).
setTimeWindow(TimeWindow.newInstance(30, 40)).build();
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
.setType(VehicleType.Builder.newInstance("vType", 0).build()).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addService(service).addService(service2).addVehicle(vehicle).build();
vrp.setActivityCosts(new VehicleRoutingActivityCosts(){
@Override
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime)*1;
double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime())*100;
return waiting + late;
}
});
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml");
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
assertEquals(40.0,Solutions.getBest(solutions).getCost(),0.1);
}
@Test
public void whenSettingTwoCustWithTWAndDepTimeChoice_depTimeShouldBe10(){
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
Service service2 = Service.Builder.newInstance("s2", 0).setLocationId("servLoc2").setCoord(Coordinate.newInstance(0, 20)).
setTimeWindow(TimeWindow.newInstance(30, 40)).build();
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
.setType(VehicleType.Builder.newInstance("vType", 0).build()).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addService(service).addService(service2).addVehicle(vehicle).build();
vrp.setActivityCosts(new VehicleRoutingActivityCosts(){
@Override
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime)*1;
double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime())*100;
return waiting + late;
}
});
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml");
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
assertEquals(10.0,Solutions.getBest(solutions).getRoutes().iterator().next().getStart().getEndTime(),0.1);
}
}

View file

@ -0,0 +1,102 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms;
import org.junit.Test;
import basics.Service;
import basics.costs.VehicleRoutingTransportCosts;
import basics.route.Driver;
import basics.route.Vehicle;
public class TestJobDistanceAvgCosts {
public static void main(String[] args) {
VehicleRoutingTransportCosts costs = new VehicleRoutingTransportCosts() {
@Override
public double getBackwardTransportTime(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
return 0;
}
@Override
public double getBackwardTransportCost(String fromId, String toId,
double arrivalTime, Driver driver, Vehicle vehicle) {
// TODO Auto-generated method stub
return 0;
}
@Override
public double getTransportCost(String fromId, String toId,
double departureTime, Driver driver, Vehicle vehicle) {
String vehicleId = vehicle.getId();
return 0;
}
@Override
public double getTransportTime(String fromId, String toId,
double departureTime, Driver driver, Vehicle vehicle) {
// TODO Auto-generated method stub
return 0;
}
};
JobDistanceAvgCosts c = new JobDistanceAvgCosts(costs);
c.calculateDistance(Service.Builder.newInstance("1", 1).setLocationId("foo").build(), Service.Builder.newInstance("2", 2).setLocationId("foo").build());
}
@Test(expected=NullPointerException.class)
public void whenVehicleAndDriverIsNull_And_CostsDoesNotProvideAMethodForThis_throwException(){
// (expected=NullPointerException.class)
VehicleRoutingTransportCosts costs = new VehicleRoutingTransportCosts() {
@Override
public double getBackwardTransportTime(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
return 0;
}
@Override
public double getBackwardTransportCost(String fromId, String toId,
double arrivalTime, Driver driver, Vehicle vehicle) {
// TODO Auto-generated method stub
return 0;
}
@Override
public double getTransportCost(String fromId, String toId,
double departureTime, Driver driver, Vehicle vehicle) {
String vehicleId = vehicle.getId();
return 0;
}
@Override
public double getTransportTime(String fromId, String toId,
double departureTime, Driver driver, Vehicle vehicle) {
// TODO Auto-generated method stub
return 0;
}
};
JobDistanceAvgCosts c = new JobDistanceAvgCosts(costs);
c.calculateDistance(Service.Builder.newInstance("1", 1).setLocationId("loc").build(), Service.Builder.newInstance("2", 2).setLocationId("loc").build());
}
}

View file

@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import basics.route.Start;
public class TestRefs {
@Test
public void testReferencs(){
List<Start> starts = new ArrayList<Start>();
starts.add(Start.newInstance("foo0", 0.0, 0.0));
starts.add(Start.newInstance("foo1", 1.0, 1.0));
doSmth(starts);
assertTrue(starts.get(0).getLocationId().startsWith("foo"));
assertTrue(starts.get(1).getLocationId().startsWith("foo"));
}
private void doSmth(List<Start> starts) {
int count = 0;
for(Start s : starts){
s = Start.newInstance("yo_"+count,0.0,0.0);
count++;
}
}
}

View file

@ -0,0 +1,246 @@
/*******************************************************************************
* Copyright (C) 2011 Stefan Schroeder.
* eMail: stefan.schroeder@kit.edu
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package algorithms;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import util.Coordinate;
import util.ManhattanDistanceCalculator;
import basics.Job;
import basics.Service;
import basics.costs.VehicleRoutingTransportCosts;
import basics.route.Driver;
import basics.route.DriverImpl;
import basics.route.TimeWindow;
import basics.route.TourActivities;
import basics.route.Vehicle;
import basics.route.VehicleImpl;
import basics.route.VehicleImpl.VehicleType;
import basics.route.VehicleRoute;
public class TestTourStateUpdaterWithService {
TourActivities tour;
Driver driver;
Vehicle vehicle;
TourActivities anotherTour;
TourStateUpdater tdTourStatusProcessor;
RouteStates states;
private VehicleRoute vehicleRoute;
@Before
public void setUp() {
VehicleRoutingTransportCosts cost = new VehicleRoutingTransportCosts() {
@Override
public double getBackwardTransportTime(String fromId, String toId,
double arrivalTime, Driver driver, Vehicle vehicle) {
return getTransportCost(fromId, toId, arrivalTime, driver, vehicle);
}
@Override
public double getBackwardTransportCost(String fromId, String toId,
double arrivalTime, Driver driver, Vehicle vehicle) {
return getTransportCost(fromId, toId, arrivalTime, driver, vehicle);
}
@Override
public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
String[] fromTokens = fromId.split(",");
String[] toTokens = toId.split(",");
double fromX = Double.parseDouble(fromTokens[0]);
double fromY = Double.parseDouble(fromTokens[1]);
double toX = Double.parseDouble(toTokens[0]);
double toY = Double.parseDouble(toTokens[1]);
return ManhattanDistanceCalculator.calculateDistance(new Coordinate(fromX, fromY), new Coordinate(toX, toY));
}
@Override
public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
return getTransportCost(fromId, toId, departureTime, driver, vehicle);
}
};
Service firstService = Service.Builder.newInstance("1", 5).setLocationId("10,0").setTimeWindow(TimeWindow.newInstance(0, 20)).build();
Service secondService = Service.Builder.newInstance("2", 5).setLocationId("0,10").setTimeWindow(TimeWindow.newInstance(0, 50)).build();
Collection<Job> services = new ArrayList<Job>();
services.add(firstService);
services.add(secondService);
states = new RouteStates();
states.initialiseStateOfJobs(services);
VehicleType type = VehicleImpl.VehicleType.Builder.newInstance("test", 0).build();
vehicle = VehicleImpl.VehicleBuilder.newInstance("testvehicle").setType(type).setLocationId("0,0")
.setEarliestStart(0.0).setLatestArrival(50.0).build();
tour = new TourActivities();
tour.addActivity(states.getActivity(firstService,true));
tour.addActivity(states.getActivity(secondService,true));
tdTourStatusProcessor = new TourStateUpdater(states, cost, new ExampleActivityCostFunction());
vehicleRoute = VehicleRoute.newInstance(tour,DriverImpl.noDriver(),vehicle);
}
@Test
public void testCalculatedCost() {
tdTourStatusProcessor.updateRoute(vehicleRoute);
assertEquals(40.0, states.getRouteState(vehicleRoute).getCosts(), 0.05);
assertEquals(10, states.getRouteState(vehicleRoute).getLoad());
}
@Test
public void testStatesOfAct0(){
tdTourStatusProcessor.updateRoute(vehicleRoute);
assertEquals(0.0, vehicleRoute.getStart().getEndTime(),0.05);
assertEquals(vehicleRoute.getVehicle().getLocationId(), vehicleRoute.getStart().getLocationId());
assertEquals(vehicleRoute.getVehicle().getEarliestDeparture(), vehicleRoute.getStart().getTheoreticalEarliestOperationStartTime(),0.05);
assertEquals(vehicleRoute.getVehicle().getLatestArrival(), vehicleRoute.getStart().getTheoreticalLatestOperationStartTime(),0.05);
}
@Test
public void testStatesOfAct1(){
tdTourStatusProcessor.updateRoute(vehicleRoute);
assertEquals(10.0, states.getState(tour.getActivities().get(0)).getCurrentCost(),0.05);
assertEquals(5.0, states.getState(tour.getActivities().get(0)).getCurrentLoad(),0.05);
assertEquals(10.0, states.getState(tour.getActivities().get(0)).getEarliestOperationStart(),0.05);
assertEquals(20.0, states.getState(tour.getActivities().get(0)).getLatestOperationStart(),0.05);
}
@Test
public void testStatesOfAct2(){
tdTourStatusProcessor.updateRoute(vehicleRoute);
assertEquals(30.0, states.getState(tour.getActivities().get(1)).getCurrentCost(),0.05);
assertEquals(10.0, states.getState(tour.getActivities().get(1)).getCurrentLoad(),0.05);
assertEquals(30.0, states.getState(tour.getActivities().get(1)).getEarliestOperationStart(),0.05);
assertEquals(40.0, states.getState(tour.getActivities().get(1)).getLatestOperationStart(),0.05);
}
@Test
public void testStatesOfAct3(){
tdTourStatusProcessor.updateRoute(vehicleRoute);
assertEquals(40.0, states.getRouteState(vehicleRoute).getCosts(), 0.05);
assertEquals(40.0, vehicleRoute.getEnd().getEndTime(),0.05);
assertEquals(50.0, vehicleRoute.getEnd().getTheoreticalLatestOperationStartTime(),0.05);
}
// public void testEarliestArrStart() {
// tdTourStatusProcessor.calculate(tour, vehicle, driver);
// assertEquals(0.0, tour.getActivities().get(0)
// .getEarliestOperationStartTime());
// }
//
// public void testLatestArrStart() {
// tdTourStatusProcessor.calculate(tour, vehicle, driver);
// assertEquals(0.0, tour.getActivities().get(0)
// .getLatestOperationStartTime());
// }
//
// public void testEarliestArrAtFirstPickup() {
// tdTourStatusProcessor.calculate(tour, vehicle, driver);
// assertEquals(10.0, tour.getActivities().get(1)
// .getEarliestOperationStartTime());
// }
//
// public void testEarliestArrAtFirstPickupWithTDCost() {
// tdTourStatusProcessor.calculate(tour, vehicle, driver);
// assertEquals(10.0, tour.getActivities().get(1)
// .getEarliestOperationStartTime());
// }
//
// public void testLatestArrAtFirstPickup() {
// tdTourStatusProcessor.calculate(tour, vehicle, driver);
// assertEquals(10.0, tour.getActivities().get(1)
// .getLatestOperationStartTime());
// }
//
// public void testLatestArrAtFirstPickupWithTDCost() {
// tdTourStatusProcessor.calculate(tour, vehicle, driver);
// assertEquals(12.0, tour.getActivities().get(1)
// .getLatestOperationStartTime());
// }
//
// public void testEarliestArrAtSecondPickup() {
// tdTourStatusProcessor.calculate(tour, vehicle, driver);
// assertEquals(30.0, tour.getActivities().get(2)
// .getEarliestOperationStartTime());
// }
//
// public void testEarliestArrAtSecondPickupWithTDCosts() {
// tdTourStatusProcessor.calculate(tour, vehicle, driver);
// assertEquals(30.0, tour.getActivities().get(2)
// .getEarliestOperationStartTime());
// }
//
// public void testLatestArrAtSecondPickup() {
// tdTourStatusProcessor.calculate(tour, vehicle, driver);
// assertEquals(30.0, tour.getActivities().get(2)
// .getLatestOperationStartTime());
// }
//
// public void testLatestArrAtSecondPickupWithTDCosts() {
// tdTourStatusProcessor.calculate(tour, vehicle, driver);
// assertEquals(30.0, tour.getActivities().get(2)
// .getLatestOperationStartTime());
// }
//
// public void testEarliestArrAtEnd() {
// tdTourStatusProcessor.calculate(tour, vehicle, driver);
// assertEquals(40.0, tour.getActivities().get(5)
// .getEarliestOperationStartTime());
// }
//
// public void testEarliestArrAtEndWithTDCosts() {
// tdTourStatusProcessor.calculate(tour, vehicle, driver);
// assertEquals(35.0, tour.getActivities().get(5)
// .getEarliestOperationStartTime());
// }
//
// public void testLatestArrAtEnd() {
// tdTourStatusProcessor.calculate(tour, vehicle, driver);
// assertEquals(Double.MAX_VALUE, tour.getActivities().get(5)
// .getLatestOperationStartTime());
// }
//
// public void testLatestArrAtEndWithTDCosts() {
// tdTourStatusProcessor.calculate(tour, vehicle, driver);
// assertEquals(Double.MAX_VALUE, tour.getActivities().get(5)
// .getLatestOperationStartTime());
// }
}

View file

@ -0,0 +1,106 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import basics.route.Vehicle;
import basics.route.VehicleImpl;
import basics.route.VehicleImpl.VehicleBuilder;
import basics.route.VehicleImpl.VehicleType;
import basics.route.VehicleImpl.VehicleType.Builder;
import algorithms.VehicleFleetManager;
import algorithms.VehicleFleetManagerImpl;
import algorithms.VehicleFleetManager.TypeKey;
import junit.framework.TestCase;
public class TestVehicleFleetManager extends TestCase{
VehicleFleetManager fleetManager;
Vehicle v1;
Vehicle v2;
public void setUp(){
List<Vehicle> vehicles = new ArrayList<Vehicle>();
v1 = VehicleImpl.VehicleBuilder.newInstance("standard").setLocationId("loc").setType(VehicleImpl.VehicleType.Builder.newInstance("standard", 0).build()).build();
v2 = VehicleImpl.VehicleBuilder.newInstance("foo").setLocationId("fooLoc").setType(VehicleImpl.VehicleType.Builder.newInstance("foo", 0).build()).build();
vehicles.add(v1);
vehicles.add(v2);
fleetManager = new VehicleFleetManagerImpl(vehicles);
}
public void testGetTypes(){
Collection<TypeKey> types = fleetManager.getAvailableVehicleTypes();
assertEquals(2, types.size());
}
public void testGetVehicle(){
TypeKey typeKey = new TypeKey(v1.getType(),v1.getLocationId());
Vehicle v = fleetManager.getEmptyVehicle(typeKey);
assertEquals(v.getId(), v1.getId());
}
public void testLock(){
fleetManager.lock(v1);
Collection<TypeKey> types = fleetManager.getAvailableVehicleTypes();
assertEquals(1, types.size());
}
public void testLockTwice(){
fleetManager.lock(v1);
Collection<TypeKey> types = fleetManager.getAvailableVehicleTypes();
assertEquals(1, types.size());
try{
fleetManager.lock(v1);
Collection<TypeKey> types_ = fleetManager.getAvailableVehicleTypes();
assertFalse(true);
}
catch(IllegalStateException e){
assertTrue(true);
}
}
public void testGetTypesWithout(){
TypeKey typeKey = new TypeKey(v1.getType(),v1.getLocationId());
Collection<TypeKey> types = fleetManager.getAvailableVehicleTypes(typeKey);
assertEquals(new TypeKey(v2.getType(),v2.getLocationId()), types.iterator().next());
assertEquals(1, types.size());
}
public void testUnlock(){
fleetManager.lock(v1);
Collection<TypeKey> types = fleetManager.getAvailableVehicleTypes();
assertEquals(1, types.size());
fleetManager.unlock(v1);
Collection<TypeKey> types_ = fleetManager.getAvailableVehicleTypes();
assertEquals(2, types_.size());
}
}

View file

@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms.acceptors;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblemSolution;
public class AcceptNewRemoveWorstTest {
@Test
public void whenHavingNewSolAndLimitedMemory_removeWorstAndAddNew(){
VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class);
VehicleRoutingProblemSolution sol2 = mock(VehicleRoutingProblemSolution.class);
when(sol1.getCost()).thenReturn(1.0);
when(sol2.getCost()).thenReturn(2.0);
List<VehicleRoutingProblemSolution> solList = new ArrayList<VehicleRoutingProblemSolution>();
solList.add(sol1);
solList.add(sol2);
VehicleRoutingProblemSolution sol3 = mock(VehicleRoutingProblemSolution.class);
new AcceptNewIfBetterThanWorst(2).acceptSolution(solList, sol3);
assertEquals(2,solList.size());
assertThat(sol3,is(solList.get(1)));
}
}

View file

@ -0,0 +1,61 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms.selectors;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
import basics.VehicleRoutingProblemSolution;
public class SelectBestTest {
@Test
public void whenHaving2Solutions_selectBest(){
VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class);
VehicleRoutingProblemSolution sol2 = mock(VehicleRoutingProblemSolution.class);
when(sol1.getCost()).thenReturn(1.0);
when(sol2.getCost()).thenReturn(2.0);
assertThat(new SelectBest().selectSolution(Arrays.asList(sol1,sol2)), is(sol1));
}
@Test
public void whenHavingOnly1Solutions_selectThisOne(){
VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class);
when(sol1.getCost()).thenReturn(1.0);
assertThat(new SelectBest().selectSolution(Arrays.asList(sol1)), is(sol1));
}
@Test
public void whenHavingNoSolutions_returnNull(){
assertNull(new SelectBest().selectSolution(Collections.EMPTY_LIST));
}
}

View file

@ -0,0 +1,87 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package algorithms.selectors;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;
import org.junit.Test;
import algorithms.selectors.SelectRandomly;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblemSolution;
public class SelectRandomlyTest {
@Test
public void whenHaving2Solutions_selectSecond(){
VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class);
VehicleRoutingProblemSolution sol2 = mock(VehicleRoutingProblemSolution.class);
when(sol1.getCost()).thenReturn(1.0);
when(sol2.getCost()).thenReturn(2.0);
Random random = mock(Random.class);
when(random.nextInt(2)).thenReturn(1);
SelectRandomly selectRandomly = new SelectRandomly();
selectRandomly.setRandom(random);
assertThat(selectRandomly.selectSolution(Arrays.asList(sol1,sol2)), is(sol2));
}
@Test
public void whenHaving2Solutions_selectFirst(){
VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class);
VehicleRoutingProblemSolution sol2 = mock(VehicleRoutingProblemSolution.class);
when(sol1.getCost()).thenReturn(1.0);
when(sol2.getCost()).thenReturn(2.0);
Random random = mock(Random.class);
when(random.nextInt(2)).thenReturn(0);
SelectRandomly selectRandomly = new SelectRandomly();
selectRandomly.setRandom(random);
assertThat(selectRandomly.selectSolution(Arrays.asList(sol1,sol2)), is(sol1));
}
@Test
public void whenHavingNoSolutions_returnNull(){
Random random = mock(Random.class);
when(random.nextInt(2)).thenReturn(0);
SelectRandomly selectRandomly = new SelectRandomly();
selectRandomly.setRandom(random);
assertNull(selectRandomly.selectSolution(Collections.EMPTY_LIST));
}
}

View file

@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package allsuites;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import algorithms.AlgorithmsSuite;
import basics.BasicsSuite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
AlgorithmsSuite.class,
BasicsSuite.class
})
public class AllTests {}

View file

@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package basics;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import algorithms.TestVehicleFleetManager;
import basics.algo.SearchStrategyManagerTest;
import basics.algo.SearchStrategyTest;
import basics.io.VrpReaderV2Test;
import basics.io.VrpWriterV2Test;
import basics.io.VrpWriterV3Test;
import basics.route.ServiceActTest;
import basics.route.TestTour;
import basics.route.TestVehicleRoute;
@RunWith(Suite.class)
@Suite.SuiteClasses({
SearchStrategyManagerTest.class,
SearchStrategyTest.class,
TestTour.class,
TestVehicleFleetManager.class,
TestVehicleRoute.class,
ServiceActTest.class,
ServiceTest.class,
VehicleRoutingProblemBuilderTest.class,
VrpReaderV2Test.class,
VrpWriterV2Test.class,
VrpWriterV3Test.class
})
public class BasicsSuite {}

View file

@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package basics;
import static org.junit.Assert.assertTrue;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;
public class ServiceTest {
@Test
public void whenTwoServicesHaveTheSameId_theyShouldBeEqual(){
Service one = Service.Builder.newInstance("service", 10).setLocationId("foo").build();
Service two = Service.Builder.newInstance("service", 10).setLocationId("fo").build();
assertTrue(one != two);
}
@Test
public void whenTwoServicesHaveTheSameId_theyShouldBeEqual2(){
Service one = Service.Builder.newInstance("service", 10).setLocationId("foo").build();
Service two = Service.Builder.newInstance("service", 10).setLocationId("fo").build();
assertTrue(one.equals(two));
}
@Test
public void noName(){
Set<Service> serviceSet = new HashSet<Service>();
Service one = Service.Builder.newInstance("service", 10).setLocationId("foo").build();
Service two = Service.Builder.newInstance("service", 10).setLocationId("fo").build();
serviceSet.add(one);
// assertTrue(serviceSet.contains(two));
serviceSet.remove(two);
assertTrue(serviceSet.isEmpty());
}
}

View file

@ -0,0 +1,72 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package basics;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import basics.VehicleRoutingProblem.FleetSize;
import basics.route.Vehicle;
import basics.route.VehicleImpl;
import basics.route.VehicleImpl.VehicleType;
public class VehicleRoutingProblemBuilderTest {
@Test
public void buildsProblemWithInfiniteVehiclesCorrectly(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
builder.setFleetSize(FleetSize.INFINITE);
// Depot depot = new Depot("depot1", Coordinate.newInstance(0, 0));
// builder.assignVehicleType(depot, VehicleType.Builder.newInstance("t1", 20).build());
// builder.assignVehicleType(depot, VehicleType.Builder.newInstance("t2", 200).build());
VehicleRoutingProblem vrp = builder.build();
assertEquals(FleetSize.INFINITE,vrp.getFleetSize());
}
@Test
public void buildsProblemWithFiniteVehiclesCorrectly_checkVehiclesAndTypesSizes(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
builder.setFleetSize(FleetSize.FINITE);
VehicleType type1 = VehicleType.Builder.newInstance("t1", 20).build();
VehicleType type2 = VehicleType.Builder.newInstance("t2", 200).build();
Vehicle v1 = VehicleImpl.VehicleBuilder.newInstance("v1").setLocationId("yo").setType(type1).build();
Vehicle v2 = VehicleImpl.VehicleBuilder.newInstance("v2").setLocationId("yo").setType(type1).build();
Vehicle v3 = VehicleImpl.VehicleBuilder.newInstance("v3").setLocationId("yo").setType(type2).build();
Vehicle v4 = VehicleImpl.VehicleBuilder.newInstance("v4").setLocationId("yo").setType(type2).build();
builder.addVehicle(v1);
builder.addVehicle(v2);
builder.addVehicle(v3);
builder.addVehicle(v4);
VehicleRoutingProblem vrp = builder.build();
assertEquals(FleetSize.FINITE,vrp.getFleetSize());
assertEquals(4,vrp.getVehicles().size());
assertEquals(2,vrp.getTypes().size());
}
}

View file

@ -0,0 +1,145 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package basics.algo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.stub;
import static org.mockito.Mockito.when;
import java.util.Random;
import org.junit.Test;
import basics.algo.SearchStrategy;
import basics.algo.SearchStrategyManager;
public class SearchStrategyManagerTest {
@Test
public void StrategyManagerInAction_addingStrategy_IsSuccessful(){
SearchStrategyManager manager = new SearchStrategyManager();
SearchStrategy strat1 = mock(SearchStrategy.class);
SearchStrategy strat2 = mock(SearchStrategy.class);
manager.addStrategy(strat1, 0.5);
manager.addStrategy(strat2, 0.5);
assertTrue(true);
}
@Test(expected=IllegalStateException.class)
public void StrategyManagerInAction_strategyIsNull_throwsException(){
SearchStrategyManager manager = new SearchStrategyManager();
manager.addStrategy(null, 1.0);
assertTrue(false);
}
@Test(expected=IllegalStateException.class)
public void StrategyManagerInAction_probabilityIsHigherThanOne_throwsException(){
SearchStrategyManager manager = new SearchStrategyManager();
SearchStrategy strat = mock(SearchStrategy.class);
manager.addStrategy(strat, 1.5);
assertTrue(false);
}
@Test(expected=IllegalStateException.class)
public void StrategyManagerInAction_probabilityIsLowerThanZero_throwsException(){
SearchStrategyManager manager = new SearchStrategyManager();
SearchStrategy strat = mock(SearchStrategy.class);
manager.addStrategy(strat, -1.0);
assertTrue(false);
}
@Test(expected = IllegalStateException.class)
public void StrategyManagerInAction_addingSeveralStratsLeadsToAProbHigherThanOne_throwsException(){
SearchStrategyManager manager = new SearchStrategyManager();
SearchStrategy mockedStrat1 = mock(SearchStrategy.class);
SearchStrategy mockedStrat2 = mock(SearchStrategy.class);
manager.addStrategy(mockedStrat1, 0.5);
manager.addStrategy(mockedStrat2, 0.6);
}
@Test
public void whenRandomDices_0point1_returnsStrategy1(){
SearchStrategyManager managerUnderTest = new SearchStrategyManager();
SearchStrategy mockedStrategy1 = mock(SearchStrategy.class);
SearchStrategy mockedStrategy2 = mock(SearchStrategy.class);
managerUnderTest.addStrategy(mockedStrategy1, 0.2);
managerUnderTest.addStrategy(mockedStrategy2, 0.8);
Random mockedRandom = mock(Random.class);
managerUnderTest.setRandom(mockedRandom);
stub(mockedRandom.nextDouble()).toReturn(0.1);
assertThat(managerUnderTest.getRandomStrategy(), is(mockedStrategy1));
}
@Test
public void whenRandomDices_0point5_returnsStrategy2(){
SearchStrategyManager managerUnderTest = new SearchStrategyManager();
SearchStrategy mockedStrategy1 = mock(SearchStrategy.class);
SearchStrategy mockedStrategy2 = mock(SearchStrategy.class);
managerUnderTest.addStrategy(mockedStrategy1, 0.2);
managerUnderTest.addStrategy(mockedStrategy2, 0.8);
Random mockedRandom = mock(Random.class);
managerUnderTest.setRandom(mockedRandom);
when(mockedRandom.nextDouble()).thenReturn(0.5);
assertThat(managerUnderTest.getRandomStrategy(), is(mockedStrategy2));
}
@Test
public void whenRandomDices_0point0_returnsStrategy1(){
SearchStrategyManager managerUnderTest = new SearchStrategyManager();
SearchStrategy mockedStrategy1 = mock(SearchStrategy.class);
SearchStrategy mockedStrategy2 = mock(SearchStrategy.class);
managerUnderTest.addStrategy(mockedStrategy1, 0.2);
managerUnderTest.addStrategy(mockedStrategy2, 0.8);
Random mockedRandom = mock(Random.class);
managerUnderTest.setRandom(mockedRandom);
when(mockedRandom.nextDouble()).thenReturn(0.0);
assertThat(managerUnderTest.getRandomStrategy(), is(mockedStrategy1));
}
@Test(expected=IllegalStateException.class)
public void whenRandomIsNull_throwException(){
SearchStrategyManager managerUnderTest = new SearchStrategyManager();
SearchStrategy mockedStrategy1 = mock(SearchStrategy.class);
SearchStrategy mockedStrategy2 = mock(SearchStrategy.class);
managerUnderTest.addStrategy(mockedStrategy1, 0.2);
managerUnderTest.addStrategy(mockedStrategy2, 0.8);
Random mockedRandom = null;
managerUnderTest.setRandom(mockedRandom);
managerUnderTest.getRandomStrategy();
}
}

View file

@ -0,0 +1,246 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package basics.algo;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;
import org.junit.Test;
import algorithms.acceptors.SolutionAcceptor;
import algorithms.selectors.SolutionSelector;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblemSolution;
import basics.algo.SearchStrategy;
import basics.algo.SearchStrategyModule;
import basics.algo.SearchStrategyModuleListener;
public class SearchStrategyTest {
@Test(expected=IllegalStateException.class)
public void whenANullModule_IsAdded_throwException(){
SolutionSelector select = mock(SolutionSelector.class);
SolutionAcceptor accept = mock(SolutionAcceptor.class);
SearchStrategy strat = new SearchStrategy(select, accept);
strat.addModule(null);
}
@Test
public void whenStratRunsWithOneModule_runItOnes(){
SolutionSelector select = mock(SolutionSelector.class);
SolutionAcceptor accept = mock(SolutionAcceptor.class);
final VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
final VehicleRoutingProblemSolution newSol = mock(VehicleRoutingProblemSolution.class);
when(select.selectSolution(null)).thenReturn(newSol);
final Collection<Integer> runs = new ArrayList<Integer>();
SearchStrategy strat = new SearchStrategy(select, accept);
SearchStrategyModule mod = new SearchStrategyModule() {
@Override
public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) {
runs.add(1);
return vrpSolution;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public void addModuleListener(
SearchStrategyModuleListener moduleListener) {
// TODO Auto-generated method stub
}
};
strat.addModule(mod);
strat.run(vrp, null);
assertEquals(runs.size(), 1);
}
@Test
public void whenStratRunsWithTwoModule_runItTwice(){
SolutionSelector select = mock(SolutionSelector.class);
SolutionAcceptor accept = mock(SolutionAcceptor.class);
final VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
final VehicleRoutingProblemSolution newSol = mock(VehicleRoutingProblemSolution.class);
when(select.selectSolution(null)).thenReturn(newSol);
final Collection<Integer> runs = new ArrayList<Integer>();
SearchStrategy strat = new SearchStrategy(select, accept);
SearchStrategyModule mod = new SearchStrategyModule() {
@Override
public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) {
runs.add(1);
return vrpSolution;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public void addModuleListener(
SearchStrategyModuleListener moduleListener) {
// TODO Auto-generated method stub
}
};
SearchStrategyModule mod2 = new SearchStrategyModule() {
@Override
public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) {
runs.add(1);
return vrpSolution;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public void addModuleListener(
SearchStrategyModuleListener moduleListener) {
// TODO Auto-generated method stub
}
};
strat.addModule(mod);
strat.addModule(mod2);
strat.run(vrp, null);
assertEquals(runs.size(), 2);
}
@Test
public void whenStratRunsWithNModule_runItNTimes(){
SolutionSelector select = mock(SolutionSelector.class);
SolutionAcceptor accept = mock(SolutionAcceptor.class);
final VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
final VehicleRoutingProblemSolution newSol = mock(VehicleRoutingProblemSolution.class);
when(select.selectSolution(null)).thenReturn(newSol);
int N = new Random().nextInt(1000);
final Collection<Integer> runs = new ArrayList<Integer>();
SearchStrategy strat = new SearchStrategy(select, accept);
for(int i=0;i<N;i++){
SearchStrategyModule mod = new SearchStrategyModule() {
@Override
public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) {
runs.add(1);
return vrpSolution;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public void addModuleListener(
SearchStrategyModuleListener moduleListener) {
// TODO Auto-generated method stub
}
};
strat.addModule(mod);
}
strat.run(vrp, null);
assertEquals(runs.size(), N);
}
@Test(expected=IllegalStateException.class)
public void whenSelectorDeliversNullSolution_throwException(){
SolutionSelector select = mock(SolutionSelector.class);
SolutionAcceptor accept = mock(SolutionAcceptor.class);
final VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
when(select.selectSolution(null)).thenReturn(null);
int N = new Random().nextInt(1000);
final Collection<Integer> runs = new ArrayList<Integer>();
SearchStrategy strat = new SearchStrategy(select, accept);
for(int i=0;i<N;i++){
SearchStrategyModule mod = new SearchStrategyModule() {
@Override
public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) {
runs.add(1);
return vrpSolution;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public void addModuleListener(
SearchStrategyModuleListener moduleListener) {
// TODO Auto-generated method stub
}
};
strat.addModule(mod);
}
strat.run(vrp, null);
assertEquals(runs.size(), N);
}
}

View file

@ -0,0 +1,41 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package basics.io;
import org.junit.Test;
public class AlgorithmReaderTest {
@Test
public void readerTest_whenReadingAlgoWithSchemaValidation_itReadsCorrectly(){
AlgorithmConfig algoConfig = new AlgorithmConfig();
new AlgorithmConfigXmlReader(algoConfig).read("src/test/resources/algorithmConfig.xml");
}
@Test
public void readerTest_whenReadingAlgoWithSchemaValidationWithoutIterations_itReadsCorrectly(){
AlgorithmConfig algoConfig = new AlgorithmConfig();
new AlgorithmConfigXmlReader(algoConfig).read("src/test/resources/algorithmConfig_withoutIterations.xml");
}
}

View file

@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package basics.io;
import java.util.ArrayList;
import org.junit.Test;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblemSolution;
public class ReaderTest {
@Test
public void testRead_ifReaderIsCalled_itReadsSuccessfully(){
new VrpXMLReader(VehicleRoutingProblem.Builder.newInstance(), new ArrayList<VehicleRoutingProblemSolution>()).read("src/test/resources/lui-shen-solution.xml");
}
}

View file

@ -0,0 +1,133 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package basics.io;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import basics.Service;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblem.Builder;
import basics.VehicleRoutingProblem.FleetComposition;
import basics.VehicleRoutingProblem.FleetSize;
import basics.io.VrpXMLReader;
import basics.route.Vehicle;
public class VrpReaderV2Test {
private String inFileName;
@Before
public void doBefore(){
inFileName = "src/test/resources/finiteVrpForReaderV2Test.xml";
}
@Test
public void whenReadingVrp_problemTypeIsReadCorrectly(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(builder, null).read(inFileName);
VehicleRoutingProblem vrp = builder.build();
assertEquals(FleetSize.FINITE,vrp.getFleetSize());
assertEquals(FleetComposition.HETEROGENEOUS,vrp.getFleetComposition());
}
@Test
public void whenReadingVrp_vehiclesAreReadCorrectly(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(builder, null).read(inFileName);
VehicleRoutingProblem vrp = builder.build();
assertEquals(2,vrp.getVehicles().size());
assertTrue(idsInCollection(Arrays.asList("v1","v2"),vrp.getVehicles()));
}
@Test
public void whenReadingVrp_vehiclesAreReadCorrectly2(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(builder, null).read(inFileName);
VehicleRoutingProblem vrp = builder.build();
Vehicle v1 = getVehicle("v1",vrp.getVehicles());
assertEquals(20,v1.getCapacity());
assertEquals(100.0,v1.getCoord().getX(),0.01);
assertEquals(0.0,v1.getEarliestDeparture(),0.01);
assertEquals("depotLoc2",v1.getLocationId());
assertNotNull(v1.getType());
assertEquals("vehType", v1.getType().getTypeId());
assertEquals(1000.0,v1.getLatestArrival(),0.01);
}
private Vehicle getVehicle(String string, Collection<Vehicle> vehicles) {
for(Vehicle v : vehicles) if(string.equals(v.getId())) return v;
return null;
}
private boolean idsInCollection(List<String> asList, Collection<Vehicle> vehicles) {
List<String> ids = new ArrayList<String>(asList);
for(Vehicle v : vehicles){
if(ids.contains(v.getId())) ids.remove(v.getId());
}
return ids.isEmpty();
}
@Test
public void whenReadingVrp_vehicleTypesAreReadCorrectly(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(builder, null).read(inFileName);
VehicleRoutingProblem vrp = builder.build();
assertEquals(2,vrp.getTypes().size());
}
@Test
public void whenReadingVrpWithInfiniteSize_itReadsCorrectly(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(builder, null).read(inFileName);
VehicleRoutingProblem vrp = builder.build();
assertEquals(FleetSize.FINITE,vrp.getFleetSize());
}
@Test
public void whenReadingServices_itReadsThemCorrectly(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(builder, null).read(inFileName);
VehicleRoutingProblem vrp = builder.build();
assertEquals(2, vrp.getJobs().size());
}
@Test
public void whenReadingServices_servicesAreBuiltCorrectly(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(builder, null).read(inFileName);
VehicleRoutingProblem vrp = builder.build();
Service s1 = (Service) vrp.getJobs().get("1");
assertEquals("delivery",s1.getType());
assertEquals(1,s1.getCapacityDemand());
assertEquals(0.0,s1.getServiceDuration(),0.01);
assertEquals(2, vrp.getJobs().size());
}
}

View file

@ -0,0 +1,203 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package basics.io;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import basics.Service;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblemSolution;
import basics.VehicleRoutingProblem.Builder;
import basics.VehicleRoutingProblem.FleetComposition;
import basics.VehicleRoutingProblem.FleetSize;
import basics.io.VrpXMLReader;
import basics.io.VrpXMLWriter;
import basics.route.End;
import basics.route.ServiceActivity;
import basics.route.Start;
import basics.route.Vehicle;
import basics.route.VehicleImpl;
import basics.route.VehicleRoute;
import basics.route.VehicleImpl.VehicleType;
public class VrpWriterV2Test {
private String infileName;
@Before
public void doBefore(){
infileName = "src/test/resources/infiniteWriterV2Test.xml";
}
@Test
public void whenWritingInfiniteVrp_itWritesCorrectly(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
builder.setFleetComposition(FleetComposition.HETEROGENEOUS);
builder.setFleetSize(FleetSize.INFINITE);
// Depot depot = new Depot("depotLoc",Coordinate.newInstance(0, 0));
// Depot depot2 = new Depot("depotLoc2",Coordinate.newInstance(100, 100));
// builder.addDepot(depot2);
// builder.assignVehicleType(depot, VehicleType.Builder.newInstance("vehType", 20).build());
// builder.assignVehicleType(depot, VehicleType.Builder.newInstance("vehType2", 200).build());
VehicleType type = VehicleType.Builder.newInstance("vehType", 20).build();
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("myVehicle").setLocationId("loc").setType(type).build();
builder.addVehicle(vehicle);
VehicleRoutingProblem vrp = builder.build();
new VrpXMLWriter(vrp, null).write(infileName);
}
@Test
public void whenWritingFiniteVrp_itWritesCorrectly(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
builder.setFleetComposition(FleetComposition.HETEROGENEOUS);
builder.setFleetSize(FleetSize.FINITE);
// Depot depot = new Depot("depotLoc",Coordinate.newInstance(0, 0));
// Depot depot2 = new Depot("depotLoc2",Coordinate.newInstance(100, 100));
// builder.addDepot(depot2);
VehicleType type1 = VehicleType.Builder.newInstance("vehType", 20).build();
VehicleType type2 = VehicleType.Builder.newInstance("vehType2", 200).build();
Vehicle v1 = VehicleImpl.VehicleBuilder.newInstance("v1").setLocationId("loc").setType(type1).build();
Vehicle v2 = VehicleImpl.VehicleBuilder.newInstance("v2").setLocationId("loc").setType(type2).build();
builder.addVehicleType(type1);
builder.addVehicleType(type2);
builder.addVehicle(v1);
builder.addVehicle(v2);
VehicleRoutingProblem vrp = builder.build();
new VrpXMLWriter(vrp, null).write(infileName);
}
@Test
public void t(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
builder.setFleetComposition(FleetComposition.HETEROGENEOUS);
builder.setFleetSize(FleetSize.FINITE);
// Depot depot = new Depot("depotLoc",Coordinate.newInstance(0, 0));
// Depot depot2 = new Depot("depotLoc2",Coordinate.newInstance(100, 100));
// builder.addDepot(depot2);
VehicleType type1 = VehicleType.Builder.newInstance("vehType", 20).build();
VehicleType type2 = VehicleType.Builder.newInstance("vehType2", 200).build();
Vehicle v1 = VehicleImpl.VehicleBuilder.newInstance("v1").setLocationId("loc").setType(type1).build();
Vehicle v2 = VehicleImpl.VehicleBuilder.newInstance("v2").setLocationId("loc").setType(type2).build();
builder.addVehicleType(type1);
builder.addVehicleType(type2);
builder.addVehicle(v1);
builder.addVehicle(v2);
VehicleRoutingProblem vrp = builder.build();
new VrpXMLWriter(vrp, null).write(infileName);
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
}
@Test
public void whenWritingServices_itWritesThemCorrectly(){
Builder builder = VehicleRoutingProblem.Builder.newInstance();
VehicleType type1 = VehicleType.Builder.newInstance("vehType", 20).build();
VehicleType type2 = VehicleType.Builder.newInstance("vehType2", 200).build();
Vehicle v1 = VehicleImpl.VehicleBuilder.newInstance("v1").setLocationId("loc").setType(type1).build();
Vehicle v2 = VehicleImpl.VehicleBuilder.newInstance("v2").setLocationId("loc").setType(type2).build();
builder.addVehicleType(type1);
builder.addVehicleType(type2);
builder.addVehicle(v1);
builder.addVehicle(v2);
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setName("delivery").setServiceTime(2.0).build();
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setName("delivery").setServiceTime(4.0).build();
VehicleRoutingProblem vrp = builder.addService(s1).addService(s2).build();
new VrpXMLWriter(vrp, null).write(infileName);
VehicleRoutingProblem.Builder vrpToReadBuilder = builder;
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
assertEquals(2,readVrp.getJobs().size());
Service s1_read = (Service) vrp.getJobs().get("1");
assertEquals("1", s1_read.getId());
assertEquals("loc", s1_read.getLocationId());
assertEquals("delivery", s1_read.getType());
assertEquals(2.0,s1_read.getServiceDuration(),0.01);
}
@Test
public void whenWritingSolutions_itWritesThemCorrectly(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
builder.setFleetComposition(FleetComposition.HETEROGENEOUS);
builder.setFleetSize(FleetSize.FINITE);
VehicleType type1 = VehicleType.Builder.newInstance("vehType", 20).build();
VehicleType type2 = VehicleType.Builder.newInstance("vehType2", 200).build();
Vehicle v1 = VehicleImpl.VehicleBuilder.newInstance("v1").setLocationId("loc").setType(type1).build();
Vehicle v2 = VehicleImpl.VehicleBuilder.newInstance("v2").setLocationId("loc").setType(type2).build();
builder.addVehicleType(type1);
builder.addVehicleType(type2);
builder.addVehicle(v1);
builder.addVehicle(v2);
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setName("delivery").setServiceTime(2.0).build();
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setName("delivery").setServiceTime(4.0).build();
builder.addService(s1).addService(s2);
VehicleRoutingProblem vrp = builder.build();
Collection<VehicleRoute> routes = new ArrayList<VehicleRoute>();
Start start = Start.newInstance("start", 0.0, Double.MAX_VALUE);
start.setEndTime(10.0);
End end = End.newInstance("end", 0.0, Double.MAX_VALUE);
end.setArrTime(100);
VehicleRoute.Builder routebuilder = VehicleRoute.Builder.newInstance(start, end);
ServiceActivity act1 = ServiceActivity.newInstance(s1);
ServiceActivity act2 = ServiceActivity.newInstance(s2);
act1.setArrTime(20.0);
act1.setEndTime(30.0);
act2.setArrTime(40.0);
act2.setEndTime(80.0);
routebuilder.addActivity(act1).addActivity(act2).setVehicle(v1);
VehicleRoute route = routebuilder.build();
routes.add(route);
VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes, 100);
new VrpXMLWriter(vrp, Arrays.asList(solution)).write(infileName);
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
Collection<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>();
new VrpXMLReader(vrpToReadBuilder, solutions).read(infileName);
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
assertEquals(1, solutions.size());
}
}

View file

@ -0,0 +1,107 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package basics.io;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import basics.Service;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblemSolution;
import basics.Service.Builder;
import basics.VehicleRoutingProblem.FleetComposition;
import basics.VehicleRoutingProblem.FleetSize;
import basics.io.VrpXMLReader;
import basics.io.VrpXMLWriter;
import basics.route.End;
import basics.route.ServiceActivity;
import basics.route.Start;
import basics.route.Vehicle;
import basics.route.VehicleImpl;
import basics.route.VehicleRoute;
import basics.route.VehicleImpl.VehicleType;
public class VrpWriterV3Test {
private String infileName;
@Before
public void doBefore(){
infileName = "src/test/resources/infiniteWriterV2Test.xml";
}
@Test
public void whenWritingSolutions_itWritesThemCorrectly(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
builder.setFleetComposition(FleetComposition.HETEROGENEOUS);
builder.setFleetSize(FleetSize.FINITE);
VehicleType type1 = VehicleType.Builder.newInstance("vehType", 20).build();
VehicleType type2 = VehicleType.Builder.newInstance("vehType2", 200).build();
Vehicle v1 = VehicleImpl.VehicleBuilder.newInstance("v1").setLocationId("loc").setType(type1).build();
Vehicle v2 = VehicleImpl.VehicleBuilder.newInstance("v2").setLocationId("loc").setType(type2).build();
builder.addVehicleType(type1);
builder.addVehicleType(type2);
builder.addVehicle(v1);
builder.addVehicle(v2);
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setName("delivery").setServiceTime(2.0).build();
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setName("delivery").setServiceTime(4.0).build();
builder.addService(s1).addService(s2);
VehicleRoutingProblem vrp = builder.build();
Collection<VehicleRoute> routes = new ArrayList<VehicleRoute>();
Start start = Start.newInstance("start", 0.0, Double.MAX_VALUE);
start.setEndTime(10.0);
End end = End.newInstance("end", 0.0, Double.MAX_VALUE);
end.setArrTime(100);
VehicleRoute.Builder routebuilder = VehicleRoute.Builder.newInstance(start, end);
ServiceActivity act1 = ServiceActivity.newInstance(s1);
ServiceActivity act2 = ServiceActivity.newInstance(s2);
act1.setArrTime(20.0);
act1.setEndTime(30.0);
act2.setArrTime(40.0);
act2.setEndTime(80.0);
routebuilder.addActivity(act1).addActivity(act2).setVehicle(v1);
VehicleRoute route = routebuilder.build();
routes.add(route);
VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes, 100);
new VrpXMLWriter(vrp, Arrays.asList(solution)).write(infileName);
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
Collection<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>();
new VrpXMLReader(vrpToReadBuilder, solutions).read(infileName);
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
}
}

View file

@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package basics.route;
import static org.junit.Assert.*;
import org.junit.Test;
import basics.Service;
import basics.Service.Builder;
import basics.route.ServiceActivity;
public class ServiceActTest {
@Test
public void whenTwoDeliveriesHaveTheSameUnderlyingJob_theyAreEqual(){
Service s1 = Service.Builder.newInstance("s", 10).setLocationId("loc").build();
Service s2 = Service.Builder.newInstance("s", 10).setLocationId("loc").build();
ServiceActivity d1 = ServiceActivity.newInstance(s1);
ServiceActivity d2 = ServiceActivity.newInstance(s2);
assertTrue(d1.equals(d2));
}
@Test
public void whenTwoDeliveriesHaveTheDifferentUnderlyingJob_theyAreNotEqual(){
Service s1 = Service.Builder.newInstance("s", 10).setLocationId("loc").build();
Service s2 = Service.Builder.newInstance("s1", 10).setLocationId("loc").build();
ServiceActivity d1 = ServiceActivity.newInstance(s1);
ServiceActivity d2 = ServiceActivity.newInstance(s2);
assertFalse(d1.equals(d2));
}
}

View file

@ -0,0 +1,83 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package basics.route;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import basics.Service;
import basics.Service.Builder;
import basics.route.ServiceActivity;
import basics.route.TourActivities;
public class TestTour {
private Service service;
private ServiceActivity act;
private TourActivities tour;
@Before
public void doBefore(){
service = Service.Builder.newInstance("yo", 10).setLocationId("loc").build();
act = ServiceActivity.newInstance(service);
tour = new TourActivities();
}
@Test
public void whenAddingServiceAct_serviceActIsAdded(){
assertFalse(tour.servesJob(service));
tour.addActivity(act);
assertTrue(tour.servesJob(service));
}
@Test(expected=IllegalStateException.class)
public void whenAddingServiceActTwice_serviceActIsAdded(){
assertFalse(tour.servesJob(service));
tour.addActivity(act);
tour.addActivity(act);
}
@Test
public void whenAddingServiceAndRemoveIt_tourShouldNotServeService(){
assertFalse(tour.servesJob(service));
tour.addActivity(act);
assertTrue(tour.servesJob(service));
tour.removeJob(service);
assertFalse(tour.servesJob(service));
}
@Test
public void noNameYet(){
assertEquals(0, tour.getActivities().size());
tour.addActivity(act);
assertEquals(1, tour.getActivities().size());
Service anotherServiceInstance = Service.Builder.newInstance("yo", 10).setLocationId("loc").build();
assertTrue(service.equals(anotherServiceInstance));
boolean removed = tour.removeJob(anotherServiceInstance);
assertTrue(removed);
// assertEquals(0, tour.getActivities().size());
}
}

View file

@ -0,0 +1,250 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package basics.route;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import org.junit.Before;
import org.junit.Test;
import basics.Service;
import basics.Service.Builder;
import basics.route.DriverImpl;
import basics.route.ServiceActivity;
import basics.route.Start;
import basics.route.TourActivities;
import basics.route.TourActivity;
import basics.route.Vehicle;
import basics.route.VehicleImpl;
import basics.route.VehicleRoute;
import basics.route.DriverImpl.NoDriver;
public class TestVehicleRoute {
private VehicleImpl vehicle;
private NoDriver driver;
@Before
public void doBefore(){
vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("loc").setType(VehicleImpl.VehicleType.Builder.newInstance("yo", 0).build()).build();
driver = DriverImpl.noDriver();
}
@Test
public void whenBuildingEmptyRouteCorrectly_go(){
VehicleRoute route = VehicleRoute.newInstance(TourActivities.emptyTour(),DriverImpl.noDriver(),VehicleImpl.noVehicle());
assertTrue(true);
}
@Test
public void whenBuildingEmptyRouteCorrectlyV2_go(){
VehicleRoute route = VehicleRoute.emptyRoute();
assertTrue(true);
}
@Test
public void whenBuildingEmptyRoute_ActivityIteratorIteratesOverZeroActivities(){
VehicleRoute route = VehicleRoute.emptyRoute();
Iterator<TourActivity> iter = route.getTourActivities().iterator();
int count=0;
while(iter.hasNext()){
iter.next();
count++;
}
assertEquals(0,count);
}
@Test(expected=IllegalStateException.class)
public void whenBuildingEmptyRoute_(){
VehicleRoute route = VehicleRoute.newInstance(null,null,null);
}
@Test(expected=IllegalStateException.class)
public void whenBuildingRouteWithNonEmptyTour_throwException(){
TourActivities tour = new TourActivities();
tour.addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("jo", 10).build()));
VehicleRoute route = VehicleRoute.newInstance(tour,DriverImpl.noDriver(),VehicleImpl.noVehicle());
}
@Test
public void whenBuildingEmptyTour_tourIterIteratesOverAnEmptyList(){
TourActivities tour = new TourActivities();
Vehicle v = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("loc").setType(VehicleImpl.VehicleType.Builder.newInstance("yo", 0).build()).build();
VehicleRoute route = VehicleRoute.newInstance(tour,DriverImpl.noDriver(),v);
Iterator<TourActivity> iter = route.getTourActivities().iterator();
int count = 0;
while(iter.hasNext()){
TourActivity act = iter.next();
count++;
}
assertEquals(0,count);
}
@Test
public void whenBuildingANonEmptyTour_tourIterIteratesOverActivitiesCorrectly(){
TourActivities tour = new TourActivities();
tour.addActivity(Start.newInstance("", 0, 0));
VehicleRoute route = VehicleRoute.newInstance(tour, driver, vehicle);
Iterator<TourActivity> iter = route.getTourActivities().iterator();
int count = 0;
while(iter.hasNext()){
TourActivity act = iter.next();
count++;
}
assertEquals(1,count);
}
@Test
public void whenBuildingANonEmptyTour2Times_tourIterIteratesOverActivitiesCorrectly(){
TourActivities tour = new TourActivities();
tour.addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("2", 30).setLocationId("1").build()));
VehicleRoute route = VehicleRoute.newInstance(tour, driver, vehicle);
{
Iterator<TourActivity> iter = route.getTourActivities().iterator();
int count = 0;
while(iter.hasNext()){
TourActivity act = iter.next();
count++;
}
assertEquals(1,count);
}
{
tour.addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("3", 30).setLocationId("1").build()));
Iterator<TourActivity> iter = route.getTourActivities().iterator();
int count = 0;
while(iter.hasNext()){
TourActivity act = iter.next();
count++;
}
assertEquals(2,count);
}
}
@Test
public void whenBuildingANonEmptyTour_tourReverseIterIteratesOverActivitiesCorrectly(){
TourActivities tour = new TourActivities();
VehicleRoute route = VehicleRoute.newInstance(tour, driver, vehicle);
Iterator<TourActivity> iter = route.getTourActivities().reverseActivityIterator();
int count = 0;
while(iter.hasNext()){
TourActivity act = iter.next();
count++;
}
assertEquals(0,count);
}
@Test
public void whenBuildingANonEmptyTourV2_tourReverseIterIteratesOverActivitiesCorrectly(){
TourActivities tour = new TourActivities();
tour.addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("2", 30).setLocationId("1").build()));
VehicleRoute route = VehicleRoute.newInstance(tour, driver, vehicle);
Iterator<TourActivity> iter = route.getTourActivities().reverseActivityIterator();
int count = 0;
while(iter.hasNext()){
TourActivity act = iter.next();
count++;
}
assertEquals(1,count);
}
@Test
public void whenBuildingANonEmptyTourV3_tourReverseIterIteratesOverActivitiesCorrectly(){
TourActivities tour = new TourActivities();
tour.addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("2", 30).setLocationId("1").build()));
ServiceActivity del = ServiceActivity.newInstance(Service.Builder.newInstance("3", 30).setLocationId("1").build());
tour.addActivity(del);
VehicleRoute route = VehicleRoute.newInstance(tour, driver, vehicle);
Iterator<TourActivity> iter = route.getTourActivities().reverseActivityIterator();
int count = 0;
TourActivity memAct = null;
while(iter.hasNext()){
TourActivity act = iter.next();
if(count==0) memAct = act;
count++;
}
assertEquals(memAct,del);
}
@Test
public void whenBuildingANonEmptyTourV4_tourReverseIterIteratesOverActivitiesCorrectly(){
TourActivities tour = new TourActivities();
tour.addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("2", 30).setLocationId("1").build()));
ServiceActivity del = ServiceActivity.newInstance(Service.Builder.newInstance("3", 30).setLocationId("1").build());
tour.addActivity(del);
VehicleRoute route = VehicleRoute.newInstance(tour, driver, vehicle);
Iterator<TourActivity> iter = route.getTourActivities().reverseActivityIterator();
int count = 0;
TourActivity memAct = null;
while(iter.hasNext()){
TourActivity act = iter.next();
if(count==0) memAct = act;
count++;
}
assertEquals(memAct,del);
assertEquals(2,count);
}
@Test
public void whenBuildingANonEmptyTour2Times_tourReverseIterIteratesOverActivitiesCorrectly(){
TourActivities tour = new TourActivities();
tour.addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("2", 30).setLocationId("1").build()));
ServiceActivity del = ServiceActivity.newInstance(Service.Builder.newInstance("3", 30).setLocationId("1").build());
tour.addActivity(del);
VehicleRoute route = VehicleRoute.newInstance(tour, driver, vehicle);
{
Iterator<TourActivity> iter = route.getTourActivities().reverseActivityIterator();
int count = 0;
TourActivity memAct = null;
while(iter.hasNext()){
TourActivity act = iter.next();
if(count==0) memAct = act;
count++;
}
assertEquals(memAct,del);
assertEquals(2,count);
}
{
Iterator<TourActivity> secondIter = route.getTourActivities().reverseActivityIterator();
int count = 0;
TourActivity memAct = null;
while(secondIter.hasNext()){
TourActivity act = secondIter.next();
if(count==0) memAct = act;
count++;
}
assertEquals(memAct,del);
assertEquals(2,count);
}
}
}

View file

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2013 Stefan Schroeder
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Contributors:
Stefan Schroeder - initial API and implementation
-->
<algorithm xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd">
<iterations>2000</iterations>
<construction>
<insertion name="bestInsertion"/>
</construction>
<strategy>
<memory>1</memory>
<searchStrategies>
<searchStrategy name="randomRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="ruin_and_recreate">
<ruin name="randomRuin">
<share>0.5</share>
</ruin>
<insertion name="bestInsertion"/>
</module>
</modules>
<probability>0.5</probability>
</searchStrategy>
<searchStrategy name="radialRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="ruin_and_recreate">
<ruin name="radialRuin">
<share>0.3</share>
</ruin>
<insertion name="bestInsertion"/>
</module>
</modules>
<probability>0.5</probability>
</searchStrategy>
</searchStrategies>
</strategy>
</algorithm>

View file

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2013 Stefan Schroeder
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Contributors:
Stefan Schroeder - initial API and implementation
-->
<algorithm xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd">
<iterations>2000</iterations>
<construction>
<insertion name="bestInsertion"/>
</construction>
<strategy>
<memory>1</memory>
<searchStrategies>
<searchStrategy name="randomRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="ruin_and_recreate">
<ruin name="randomRuin">
<share>0.5</share>
</ruin>
<insertion name="bestInsertion"/>
</module>
</modules>
<probability>0.4</probability>
</searchStrategy>
<searchStrategy name="radialRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="ruin_and_recreate">
<ruin name="radialRuin">
<share>0.3</share>
</ruin>
<insertion name="bestInsertion"/>
</module>
</modules>
<probability>0.4</probability>
</searchStrategy>
<searchStrategy name="radialRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="ruin_and_recreate">
<ruin id="1" name="radialRuin">
<share>0.1</share>
</ruin>
<insertion id="1" name="bestInsertion">
<experimental timeSlice="10" neighboringSlices="3"/>
</insertion>
</module>
</modules>
<probability>0.2</probability>
</searchStrategy>
</searchStrategies>
</strategy>
</algorithm>

View file

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2013 Stefan Schroeder
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Contributors:
Stefan Schroeder - initial API and implementation
-->
<algorithm xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd">
<construction>
<insertion name="bestInsertion"/>
</construction>
<strategy>
<memory>1</memory>
<searchStrategies>
<searchStrategy name="randomRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="ruin_and_recreate">
<ruin name="randomRuin">
<share>0.5</share>
</ruin>
<insertion name="bestInsertion"/>
</module>
</modules>
<probability>0.5</probability>
</searchStrategy>
<searchStrategy name="radialRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="ruin_and_recreate">
<ruin name="radialRuin">
<share>0.3</share>
</ruin>
<insertion name="bestInsertion"/>
</module>
</modules>
<probability>0.5</probability>
</searchStrategy>
</searchStrategies>
</strategy>
</algorithm>

View file

@ -0,0 +1,91 @@
<?xml version="1.0" ?>
<!--
Copyright (C) 2013 Stefan Schroeder
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Contributors:
Stefan Schroeder - initial API and implementation
-->
<algorithm xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd">
<iterations>10</iterations>
<construction>
<insertion name="bestInsertion"/>
</construction>
<strategy>
<memory>1</memory>
<searchStrategies>
<searchStrategy name="randomRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="ruin_and_recreate">
<ruin name="randomRuin">
<share>0.5</share>
</ruin>
<insertion name="bestInsertion"/>
</module>
</modules>
<probability>0.4</probability>
</searchStrategy>
<searchStrategy name="randomRuinSmall">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="ruin_and_recreate">
<ruin name="randomRuin">
<share>0.1</share>
</ruin>
<insertion name="regretInsertion"/>
</module>
</modules>
<probability>0.4</probability>
</searchStrategy>
<searchStrategy name="radialRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="ruin_and_recreate">
<ruin name="radialRuin">
<share>0.3</share>
</ruin>
<insertion name="bestInsertion" id="1"/>
</module>
</modules>
<probability>0.2</probability>
</searchStrategy>
<!-- <searchStrategy id="gendreauPostOpt"> -->
<!-- <modules number="1"> -->
<!-- <module name="gendreau"> -->
<!-- <iterations>200</iterations> -->
<!-- <share>0.2</share> -->
<!-- </module> -->
<!-- </modules> -->
<!-- <probability>0.1</probability> -->
<!-- </searchStrategy> -->
</searchStrategies>
</strategy>
</algorithm>

View file

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2013 Stefan Schroeder
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Contributors:
Stefan Schroeder - initial API and implementation
-->
<problem xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
<problemType>
<fleetSize>FINITE</fleetSize>
<fleetComposition>HETEROGENEOUS</fleetComposition>
</problemType>
<vehicles>
<vehicle>
<id>v1</id>
<location>
<id>depotLoc2</id>
<coord x="100.0" y="100.0"/>
</location>
<typeId>vehType</typeId>
<timeSchedule>
<start>0.0</start>
<end>1000.0</end>
</timeSchedule>
</vehicle>
<vehicle>
<id>v2</id>
<location>
<id>depotLoc</id>
<coord x="10.0" y="100.0"/>
</location>
<typeId>vehType2</typeId>
<timeSchedule>
<start>0.0</start>
<end>1000.0</end>
</timeSchedule>
</vehicle>
</vehicles>
<vehicleTypes>
<type>
<id>vehType</id>
<capacity>20</capacity>
<costs>
<fixed>0.0</fixed>
<distance>0.0</distance>
<time>0.0</time>
</costs>
</type>
<type>
<id>vehType2</id>
<capacity>200</capacity>
<costs>
<fixed>0.0</fixed>
<distance>0.0</distance>
<time>0.0</time>
</costs>
</type>
</vehicleTypes>
<services>
<service id="1" type="delivery">
<locationId>j(1,5)</locationId>
<coord x="10.0" y="10.0"/>
<capacity-demand>1</capacity-demand>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>4000.0</end>
</timeWindow>
</timeWindows>
</service>
<service id="2" type="delivery">
<locationId>i(3,9)</locationId>
<coord x="10.0" y="10.0"/>
<capacity-demand>1</capacity-demand>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>4000.0</end>
</timeWindow>
</timeWindows>
</service>
</services>
</problem>

View file

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<problem xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
<problemType>
<fleetSize>FINITE</fleetSize>
<fleetComposition>HETEROGENEOUS</fleetComposition>
</problemType>
<vehicles>
<vehicle>
<id>v1</id>
<typeId>vehType</typeId>
<location>
<id>loc</id>
</location>
<timeSchedule>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeSchedule>
</vehicle>
<vehicle>
<id>v2</id>
<typeId>vehType2</typeId>
<location>
<id>loc</id>
</location>
<timeSchedule>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeSchedule>
</vehicle>
</vehicles>
<vehicleTypes>
<type>
<id>vehType</id>
<capacity>20</capacity>
<costs>
<fixed>0.0</fixed>
<distance>0.0</distance>
<time>0.0</time>
</costs>
</type>
<type>
<id>vehType2</id>
<capacity>200</capacity>
<costs>
<fixed>0.0</fixed>
<distance>0.0</distance>
<time>0.0</time>
</costs>
</type>
</vehicleTypes>
<services>
<service id="2" type="delivery">
<locationId>loc2</locationId>
<capacity-demand>1</capacity-demand>
<duration>4.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</service>
<service id="1" type="delivery">
<locationId>loc</locationId>
<capacity-demand>1</capacity-demand>
<duration>2.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</service>
</services>
<solutions>
<solution>
<cost>100.0</cost>
<routes>
<route>
<cost>0.0</cost>
<driverId>noDriver</driverId>
<vehicleId>v1</vehicleId>
<start>10.0</start>
<act type="delivery">
<serviceId>1</serviceId>
<arrTime>20.0</arrTime>
<endTime>30.0</endTime>
</act>
<act type="delivery">
<serviceId>2</serviceId>
<arrTime>40.0</arrTime>
<endTime>80.0</endTime>
</act>
<end>100.0</end>
</route>
</routes>
</solution>
</solutions>
</problem>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,85 @@
<?xml version="1.0" ?>
<!--
Copyright (C) 2013 Stefan Schroeder
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Contributors:
Stefan Schroeder - initial API and implementation
-->
<config>
<iterations>10</iterations>
<construction>
<insertion name="bestInsertion"/>
</construction>
<strategy>
<memory>1</memory>
<searchStrategies>
<searchStrategy name="randomRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="randomRuin">
<share>0.5</share>
</module>
<module name="bestInsertion">
</module>
</modules>
<probability>0.4</probability>
</searchStrategy>
<searchStrategy name="randomRuinSmall">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="randomRuin">
<share>0.1</share>
</module>
<module name="bestInsertion"></module>
</modules>
<probability>0.4</probability>
</searchStrategy>
<searchStrategy name="radialRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="radialRuin">
<share>0.3</share>
<distanceMeasure>euclid</distanceMeasure>
</module>
<module name="bestInsertion" id="1"></module>
</modules>
<probability>0.2</probability>
</searchStrategy>
<!-- <searchStrategy id="gendreauPostOpt"> -->
<!-- <modules number="1"> -->
<!-- <module name="gendreau"> -->
<!-- <iterations>200</iterations> -->
<!-- <share>0.2</share> -->
<!-- </module> -->
<!-- </modules> -->
<!-- <probability>0.1</probability> -->
<!-- </searchStrategy> -->
</searchStrategies>
</strategy>
</config>

View file

@ -0,0 +1,85 @@
<?xml version="1.0" ?>
<!--
Copyright (C) 2013 Stefan Schroeder
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Contributors:
Stefan Schroeder - initial API and implementation
-->
<config>
<iterations>10</iterations>
<construction>
<insertion name="bestInsertion"/>
</construction>
<strategy>
<memory>1</memory>
<searchStrategies>
<searchStrategy name="randomRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="randomRuin">
<share>0.5</share>
</module>
<module name="bestInsertion">
</module>
</modules>
<probability>0.4</probability>
</searchStrategy>
<searchStrategy name="randomRuinSmall">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="randomRuin">
<share>0.1</share>
</module>
<module name="bestInsertion"></module>
</modules>
<probability>0.4</probability>
</searchStrategy>
<searchStrategy name="radialRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="radialRuin">
<share>0.3</share>
<distanceMeasure>euclid</distanceMeasure>
</module>
<module name="bestInsertion" id="1"></module>
</modules>
<probability>0.2</probability>
</searchStrategy>
<!-- <searchStrategy id="gendreauPostOpt"> -->
<!-- <modules number="1"> -->
<!-- <module name="gendreau"> -->
<!-- <iterations>200</iterations> -->
<!-- <share>0.2</share> -->
<!-- </module> -->
<!-- </modules> -->
<!-- <probability>0.1</probability> -->
<!-- </searchStrategy> -->
</searchStrategies>
</strategy>
</config>