mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Merge branch 'PickupAndDelivery' of https://github.com/jsprit/jsprit.git into pickupAndDelivery
This commit is contained in:
commit
7a5f1052df
62 changed files with 60070 additions and 220 deletions
|
|
@ -26,7 +26,7 @@ import basics.algo.InsertionEndsListener;
|
|||
import basics.route.VehicleFleetManager;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
class RemoveEmptyVehicles implements InsertionEndsListener{
|
||||
public class RemoveEmptyVehicles implements InsertionEndsListener{
|
||||
|
||||
private static Logger log = Logger.getLogger(RemoveEmptyVehicles.class);
|
||||
|
||||
|
|
|
|||
|
|
@ -232,6 +232,7 @@ public class StateManager implements StateGetter, IterationStartsListener, RuinL
|
|||
if(stateId.equals(StateFactory.LATEST_OPERATION_START_TIME)) return new StateImpl(act.getTheoreticalLatestOperationStartTime());
|
||||
if(stateId.equals(StateFactory.FUTURE_PICKS)) return new StateImpl(0);
|
||||
if(stateId.equals(StateFactory.PAST_DELIVERIES)) return new StateImpl(0);
|
||||
if(defaultActivityStates.containsKey(stateId)) return defaultActivityStates.get(stateId);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -242,6 +243,7 @@ public class StateManager implements StateGetter, IterationStartsListener, RuinL
|
|||
if(stateId.equals(StateFactory.LOAD_AT_BEGINNING)) return new StateImpl(0);
|
||||
if(stateId.equals(StateFactory.COSTS)) return new StateImpl(0);
|
||||
if(stateId.equals(StateFactory.DURATION)) return new StateImpl(0);
|
||||
if(defaultRouteStates.containsKey(stateId)) return defaultRouteStates.get(stateId);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
1056
jsprit-instances/instances/lilim/1000/LC1101.txt
Normal file
1056
jsprit-instances/instances/lilim/1000/LC1101.txt
Normal file
File diff suppressed because it is too large
Load diff
1048
jsprit-instances/instances/lilim/1000/LC11010.txt
Normal file
1048
jsprit-instances/instances/lilim/1000/LC11010.txt
Normal file
File diff suppressed because it is too large
Load diff
1048
jsprit-instances/instances/lilim/1000/LC1102.txt
Normal file
1048
jsprit-instances/instances/lilim/1000/LC1102.txt
Normal file
File diff suppressed because it is too large
Load diff
1050
jsprit-instances/instances/lilim/1000/LC1103.txt
Normal file
1050
jsprit-instances/instances/lilim/1000/LC1103.txt
Normal file
File diff suppressed because it is too large
Load diff
1040
jsprit-instances/instances/lilim/1000/LC1104.txt
Normal file
1040
jsprit-instances/instances/lilim/1000/LC1104.txt
Normal file
File diff suppressed because it is too large
Load diff
1060
jsprit-instances/instances/lilim/1000/LC1105.txt
Normal file
1060
jsprit-instances/instances/lilim/1000/LC1105.txt
Normal file
File diff suppressed because it is too large
Load diff
1056
jsprit-instances/instances/lilim/1000/LC1106.txt
Normal file
1056
jsprit-instances/instances/lilim/1000/LC1106.txt
Normal file
File diff suppressed because it is too large
Load diff
1054
jsprit-instances/instances/lilim/1000/LC1107.txt
Normal file
1054
jsprit-instances/instances/lilim/1000/LC1107.txt
Normal file
File diff suppressed because it is too large
Load diff
1054
jsprit-instances/instances/lilim/1000/LC1108.txt
Normal file
1054
jsprit-instances/instances/lilim/1000/LC1108.txt
Normal file
File diff suppressed because it is too large
Load diff
1048
jsprit-instances/instances/lilim/1000/LC1109.txt
Normal file
1048
jsprit-instances/instances/lilim/1000/LC1109.txt
Normal file
File diff suppressed because it is too large
Load diff
1016
jsprit-instances/instances/lilim/1000/LC2101.txt
Normal file
1016
jsprit-instances/instances/lilim/1000/LC2101.txt
Normal file
File diff suppressed because it is too large
Load diff
1010
jsprit-instances/instances/lilim/1000/LC21010.txt
Normal file
1010
jsprit-instances/instances/lilim/1000/LC21010.txt
Normal file
File diff suppressed because it is too large
Load diff
1018
jsprit-instances/instances/lilim/1000/LC2102.txt
Normal file
1018
jsprit-instances/instances/lilim/1000/LC2102.txt
Normal file
File diff suppressed because it is too large
Load diff
1018
jsprit-instances/instances/lilim/1000/LC2103.txt
Normal file
1018
jsprit-instances/instances/lilim/1000/LC2103.txt
Normal file
File diff suppressed because it is too large
Load diff
1020
jsprit-instances/instances/lilim/1000/LC2104.txt
Normal file
1020
jsprit-instances/instances/lilim/1000/LC2104.txt
Normal file
File diff suppressed because it is too large
Load diff
1016
jsprit-instances/instances/lilim/1000/LC2105.txt
Normal file
1016
jsprit-instances/instances/lilim/1000/LC2105.txt
Normal file
File diff suppressed because it is too large
Load diff
1020
jsprit-instances/instances/lilim/1000/LC2106.txt
Normal file
1020
jsprit-instances/instances/lilim/1000/LC2106.txt
Normal file
File diff suppressed because it is too large
Load diff
1020
jsprit-instances/instances/lilim/1000/LC2107.txt
Normal file
1020
jsprit-instances/instances/lilim/1000/LC2107.txt
Normal file
File diff suppressed because it is too large
Load diff
1016
jsprit-instances/instances/lilim/1000/LC2108.txt
Normal file
1016
jsprit-instances/instances/lilim/1000/LC2108.txt
Normal file
File diff suppressed because it is too large
Load diff
1024
jsprit-instances/instances/lilim/1000/LC2109.txt
Normal file
1024
jsprit-instances/instances/lilim/1000/LC2109.txt
Normal file
File diff suppressed because it is too large
Load diff
1056
jsprit-instances/instances/lilim/1000/LR1101.txt
Normal file
1056
jsprit-instances/instances/lilim/1000/LR1101.txt
Normal file
File diff suppressed because it is too large
Load diff
1040
jsprit-instances/instances/lilim/1000/LR11010.txt
Normal file
1040
jsprit-instances/instances/lilim/1000/LR11010.txt
Normal file
File diff suppressed because it is too large
Load diff
1042
jsprit-instances/instances/lilim/1000/LR1102.txt
Normal file
1042
jsprit-instances/instances/lilim/1000/LR1102.txt
Normal file
File diff suppressed because it is too large
Load diff
1048
jsprit-instances/instances/lilim/1000/LR1103.txt
Normal file
1048
jsprit-instances/instances/lilim/1000/LR1103.txt
Normal file
File diff suppressed because it is too large
Load diff
1040
jsprit-instances/instances/lilim/1000/LR1104.txt
Normal file
1040
jsprit-instances/instances/lilim/1000/LR1104.txt
Normal file
File diff suppressed because it is too large
Load diff
1050
jsprit-instances/instances/lilim/1000/LR1105.txt
Normal file
1050
jsprit-instances/instances/lilim/1000/LR1105.txt
Normal file
File diff suppressed because it is too large
Load diff
1050
jsprit-instances/instances/lilim/1000/LR1106.txt
Normal file
1050
jsprit-instances/instances/lilim/1000/LR1106.txt
Normal file
File diff suppressed because it is too large
Load diff
1048
jsprit-instances/instances/lilim/1000/LR1107.txt
Normal file
1048
jsprit-instances/instances/lilim/1000/LR1107.txt
Normal file
File diff suppressed because it is too large
Load diff
1048
jsprit-instances/instances/lilim/1000/LR1108.txt
Normal file
1048
jsprit-instances/instances/lilim/1000/LR1108.txt
Normal file
File diff suppressed because it is too large
Load diff
1048
jsprit-instances/instances/lilim/1000/LR1109.txt
Normal file
1048
jsprit-instances/instances/lilim/1000/LR1109.txt
Normal file
File diff suppressed because it is too large
Load diff
1008
jsprit-instances/instances/lilim/1000/LR2101.txt
Normal file
1008
jsprit-instances/instances/lilim/1000/LR2101.txt
Normal file
File diff suppressed because it is too large
Load diff
1006
jsprit-instances/instances/lilim/1000/LR21010.txt
Normal file
1006
jsprit-instances/instances/lilim/1000/LR21010.txt
Normal file
File diff suppressed because it is too large
Load diff
1010
jsprit-instances/instances/lilim/1000/LR2102.txt
Normal file
1010
jsprit-instances/instances/lilim/1000/LR2102.txt
Normal file
File diff suppressed because it is too large
Load diff
1012
jsprit-instances/instances/lilim/1000/LR2103.txt
Normal file
1012
jsprit-instances/instances/lilim/1000/LR2103.txt
Normal file
File diff suppressed because it is too large
Load diff
1010
jsprit-instances/instances/lilim/1000/LR2104.txt
Normal file
1010
jsprit-instances/instances/lilim/1000/LR2104.txt
Normal file
File diff suppressed because it is too large
Load diff
1010
jsprit-instances/instances/lilim/1000/LR2105.txt
Normal file
1010
jsprit-instances/instances/lilim/1000/LR2105.txt
Normal file
File diff suppressed because it is too large
Load diff
1014
jsprit-instances/instances/lilim/1000/LR2106.txt
Normal file
1014
jsprit-instances/instances/lilim/1000/LR2106.txt
Normal file
File diff suppressed because it is too large
Load diff
1012
jsprit-instances/instances/lilim/1000/LR2107.txt
Normal file
1012
jsprit-instances/instances/lilim/1000/LR2107.txt
Normal file
File diff suppressed because it is too large
Load diff
1010
jsprit-instances/instances/lilim/1000/LR2108.txt
Normal file
1010
jsprit-instances/instances/lilim/1000/LR2108.txt
Normal file
File diff suppressed because it is too large
Load diff
1010
jsprit-instances/instances/lilim/1000/LR2109.txt
Normal file
1010
jsprit-instances/instances/lilim/1000/LR2109.txt
Normal file
File diff suppressed because it is too large
Load diff
1056
jsprit-instances/instances/lilim/1000/LRC1101.txt
Normal file
1056
jsprit-instances/instances/lilim/1000/LRC1101.txt
Normal file
File diff suppressed because it is too large
Load diff
1046
jsprit-instances/instances/lilim/1000/LRC11010.txt
Normal file
1046
jsprit-instances/instances/lilim/1000/LRC11010.txt
Normal file
File diff suppressed because it is too large
Load diff
1048
jsprit-instances/instances/lilim/1000/LRC1102.txt
Normal file
1048
jsprit-instances/instances/lilim/1000/LRC1102.txt
Normal file
File diff suppressed because it is too large
Load diff
1050
jsprit-instances/instances/lilim/1000/LRC1103.txt
Normal file
1050
jsprit-instances/instances/lilim/1000/LRC1103.txt
Normal file
File diff suppressed because it is too large
Load diff
1044
jsprit-instances/instances/lilim/1000/LRC1104.txt
Normal file
1044
jsprit-instances/instances/lilim/1000/LRC1104.txt
Normal file
File diff suppressed because it is too large
Load diff
1054
jsprit-instances/instances/lilim/1000/LRC1105.txt
Normal file
1054
jsprit-instances/instances/lilim/1000/LRC1105.txt
Normal file
File diff suppressed because it is too large
Load diff
1048
jsprit-instances/instances/lilim/1000/LRC1106.txt
Normal file
1048
jsprit-instances/instances/lilim/1000/LRC1106.txt
Normal file
File diff suppressed because it is too large
Load diff
1048
jsprit-instances/instances/lilim/1000/LRC1107.txt
Normal file
1048
jsprit-instances/instances/lilim/1000/LRC1107.txt
Normal file
File diff suppressed because it is too large
Load diff
1046
jsprit-instances/instances/lilim/1000/LRC1108.txt
Normal file
1046
jsprit-instances/instances/lilim/1000/LRC1108.txt
Normal file
File diff suppressed because it is too large
Load diff
1050
jsprit-instances/instances/lilim/1000/LRC1109.txt
Normal file
1050
jsprit-instances/instances/lilim/1000/LRC1109.txt
Normal file
File diff suppressed because it is too large
Load diff
1016
jsprit-instances/instances/lilim/1000/LRC2101.txt
Normal file
1016
jsprit-instances/instances/lilim/1000/LRC2101.txt
Normal file
File diff suppressed because it is too large
Load diff
1010
jsprit-instances/instances/lilim/1000/LRC21010.txt
Normal file
1010
jsprit-instances/instances/lilim/1000/LRC21010.txt
Normal file
File diff suppressed because it is too large
Load diff
1012
jsprit-instances/instances/lilim/1000/LRC2102.txt
Normal file
1012
jsprit-instances/instances/lilim/1000/LRC2102.txt
Normal file
File diff suppressed because it is too large
Load diff
1016
jsprit-instances/instances/lilim/1000/LRC2103.txt
Normal file
1016
jsprit-instances/instances/lilim/1000/LRC2103.txt
Normal file
File diff suppressed because it is too large
Load diff
1014
jsprit-instances/instances/lilim/1000/LRC2104.txt
Normal file
1014
jsprit-instances/instances/lilim/1000/LRC2104.txt
Normal file
File diff suppressed because it is too large
Load diff
1010
jsprit-instances/instances/lilim/1000/LRC2105.txt
Normal file
1010
jsprit-instances/instances/lilim/1000/LRC2105.txt
Normal file
File diff suppressed because it is too large
Load diff
1010
jsprit-instances/instances/lilim/1000/LRC2106.txt
Normal file
1010
jsprit-instances/instances/lilim/1000/LRC2106.txt
Normal file
File diff suppressed because it is too large
Load diff
1012
jsprit-instances/instances/lilim/1000/LRC2107.txt
Normal file
1012
jsprit-instances/instances/lilim/1000/LRC2107.txt
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,219 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package readers;
|
||||
//package instances;
|
||||
//
|
||||
//import java.io.BufferedReader;
|
||||
//import java.io.IOException;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Collection;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//import org.apache.log4j.Level;
|
||||
//import org.apache.log4j.Logger;
|
||||
//import org.matsim.contrib.freight.vrp.algorithms.rr.RuinAndRecreate;
|
||||
//import org.matsim.contrib.freight.vrp.basics.Job;
|
||||
//import org.matsim.contrib.freight.vrp.basics.Shipment;
|
||||
//import org.matsim.contrib.freight.vrp.basics.VehicleRoutingProblem;
|
||||
//import org.matsim.contrib.freight.vrp.basics.VrpBuilder;
|
||||
//import org.matsim.contrib.freight.vrp.utils.Coordinate;
|
||||
//import org.matsim.contrib.freight.vrp.utils.CrowFlyCosts;
|
||||
//import org.matsim.contrib.freight.vrp.utils.Locations;
|
||||
//import org.matsim.core.utils.io.IOUtils;
|
||||
//
|
||||
///**
|
||||
// * test instances for the capacitated vrp with pickup and deliveries and time windows.
|
||||
// * instances are from li and lim and can be found at:
|
||||
// * http://www.top.sintef.no/vrp/benchmarks.html
|
||||
// * @author stefan schroeder
|
||||
// *
|
||||
// */
|
||||
//
|
||||
//
|
||||
//public class LiLim {
|
||||
//
|
||||
// static class MyLocations implements Locations{
|
||||
//
|
||||
// private Map<String,Coordinate> locations = new HashMap<String, Coordinate>();
|
||||
//
|
||||
// public void addLocation(String id, Coordinate coord){
|
||||
// locations.put(id, coord);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Coordinate getCoord(String id) {
|
||||
// return locations.get(id);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// static class CustomerData{
|
||||
// public double start;
|
||||
// public double end;
|
||||
// public double serviceTime;
|
||||
// public CustomerData(double start, double end, double serviceTime) {
|
||||
// super();
|
||||
// this.start = start;
|
||||
// this.end = end;
|
||||
// this.serviceTime = serviceTime;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// static class Relation{
|
||||
// public String from;
|
||||
// public String to;
|
||||
// public int demand;
|
||||
// public Relation(String from, String to, int demand) {
|
||||
// super();
|
||||
// this.from = from;
|
||||
// this.to = to;
|
||||
// this.demand = demand;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private static Logger logger = Logger.getLogger(Christophides.class);
|
||||
//
|
||||
// private VrpBuilder vrpBuilder;
|
||||
//
|
||||
//// private Locations locations;
|
||||
//
|
||||
// private String fileNameOfInstance;
|
||||
//
|
||||
// private int vehicleCapacity;
|
||||
//
|
||||
// private String depotId;
|
||||
//
|
||||
// private Map<String,CustomerData> data;
|
||||
//
|
||||
// private Collection<Relation> relations;
|
||||
//
|
||||
// private String instanceName;
|
||||
// public LiLim(String fileNameOfInstance, String instanceName) {
|
||||
// this.fileNameOfInstance = fileNameOfInstance;
|
||||
// this.instanceName = instanceName;
|
||||
// data = new HashMap<String, LiLim.CustomerData>();
|
||||
// relations = new ArrayList<LiLim.Relation>();
|
||||
// }
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
// Logger.getRootLogger().setLevel(Level.INFO);
|
||||
// LiLim liLim = new LiLim("/Users/stefan/Documents/workspace/VehicleRouting/instances/cvrppdtw_lilim/pdp100/lc205.txt", "lc205");
|
||||
// liLim.run();
|
||||
// }
|
||||
//
|
||||
// public void run(){
|
||||
// MyLocations myLocations = new MyLocations();
|
||||
// Collection<Job> jobs = new ArrayList<Job>();
|
||||
// readLocationsAndJobs(myLocations);
|
||||
// buildJobs(jobs);
|
||||
// VrpBuilder vrpBuilder = new VrpBuilder(new CrowFlyCosts(myLocations));
|
||||
// for(Job j : jobs){
|
||||
// vrpBuilder.addJob(j);
|
||||
// }
|
||||
// for(int i=0;i<20;i++){
|
||||
// vrpBuilder.addVehicle(VrpUtils.createVehicle("" + (i+1), depotId, vehicleCapacity, "standard",100.0,1.0,1.0));
|
||||
// }
|
||||
// RuinAndRecreate algo = createAlgo(vrpBuilder.build());
|
||||
// algo.run();
|
||||
// }
|
||||
//
|
||||
// private void buildJobs(Collection<Job> jobs) {
|
||||
// Integer counter = 0;
|
||||
// for(Relation rel : relations){
|
||||
// counter++;
|
||||
// String from = rel.from;
|
||||
// String to = rel.to;
|
||||
// Shipment s = VrpUtils.createShipment(counter.toString(), from, to, rel.demand,
|
||||
// VrpUtils.createTimeWindow(data.get(from).start, data.get(from).end),
|
||||
// VrpUtils.createTimeWindow(data.get(to).start, data.get(to).end));
|
||||
// s.setPickupServiceTime(data.get(from).serviceTime);
|
||||
// s.setDeliveryServiceTime(data.get(to).serviceTime);
|
||||
// jobs.add(s);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private RuinAndRecreate createAlgo(VehicleRoutingProblem vrp) {
|
||||
//// PickupAndDeliveryTourWithTimeWindowsAlgoFactory factory = new PickupAndDeliveryTourWithTimeWindowsAlgoFactory();
|
||||
//// factory.setIterations(100);
|
||||
//// factory.setWarmUp(10);
|
||||
//// RuinAndRecreateChartListener chartListener = new RuinAndRecreateChartListener();
|
||||
//// chartListener.setFilename("vrp/liLim/"+instanceName+".png");
|
||||
//// RuinAndRecreateReport report = new RuinAndRecreateReport();
|
||||
//// factory.addRuinAndRecreateListener(chartListener);
|
||||
//// factory.addRuinAndRecreateListener(report);
|
||||
//// return factory.createAlgorithm(vrp);
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// private void readLocationsAndJobs(MyLocations locs) {
|
||||
// BufferedReader reader = IOUtils.getBufferedReader(fileNameOfInstance);
|
||||
// String line = null;
|
||||
// boolean firstLine = true;
|
||||
// try {
|
||||
// while((line = reader.readLine()) != null){
|
||||
// line = line.replace("\r", "");
|
||||
// line = line.trim();
|
||||
// String[] tokens = line.split("\t");
|
||||
// if(firstLine){
|
||||
// int vehicleCapacity = getInt(tokens[1]);
|
||||
// this.vehicleCapacity = vehicleCapacity;
|
||||
// firstLine = false;
|
||||
// continue;
|
||||
// }
|
||||
// else{
|
||||
// String customerId = tokens[0];
|
||||
// Coordinate coord = makeCoord(tokens[1], tokens[2]);
|
||||
// if(customerId.equals("0")){
|
||||
// depotId = customerId;
|
||||
// }
|
||||
// int demand = getInt(tokens[3]);
|
||||
// double startTimeWindow = getDouble(tokens[4]);
|
||||
// double endTimeWindow = getDouble(tokens[5]);
|
||||
// double serviceTime = getDouble(tokens[6]);
|
||||
// locs.addLocation(customerId, coord);
|
||||
// data.put(customerId, new CustomerData(startTimeWindow,endTimeWindow,serviceTime));
|
||||
// if(demand > 0){
|
||||
// relations.add(new Relation(customerId,tokens[8],demand));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// reader.close();
|
||||
// } catch (IOException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private Coordinate makeCoord(String xString, String yString) {
|
||||
// double x = Double.parseDouble(xString);
|
||||
// double y = Double.parseDouble(yString);
|
||||
// return new Coordinate(x,y);
|
||||
// }
|
||||
//
|
||||
// private double getDouble(String string) {
|
||||
// return Double.parseDouble(string);
|
||||
// }
|
||||
//
|
||||
// private int getInt(String string) {
|
||||
// return Integer.parseInt(string);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
213
jsprit-instances/src/main/java/readers/LiLimReader.java
Normal file
213
jsprit-instances/src/main/java/readers/LiLimReader.java
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package readers;
|
||||
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.Coordinate;
|
||||
import util.Locations;
|
||||
import basics.Shipment;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblem.Builder;
|
||||
import basics.route.TimeWindow;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl;
|
||||
import basics.route.VehicleTypeImpl;
|
||||
|
||||
/**
|
||||
* test instances for the capacitated vrp with pickup and deliveries and time windows.
|
||||
* instances are from li and lim and can be found at:
|
||||
* http://www.top.sintef.no/vrp/benchmarks.html
|
||||
* @author stefan schroeder
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
public class LiLimReader {
|
||||
|
||||
static class MyLocations implements Locations{
|
||||
|
||||
private Map<String,Coordinate> locations = new HashMap<String, Coordinate>();
|
||||
|
||||
public void addLocation(String id, Coordinate coord){
|
||||
locations.put(id, coord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
return locations.get(id);
|
||||
}
|
||||
}
|
||||
|
||||
static class CustomerData{
|
||||
public Coordinate coord;
|
||||
public double start;
|
||||
public double end;
|
||||
public double serviceTime;
|
||||
|
||||
public CustomerData(Coordinate coord, double start, double end, double serviceTime) {
|
||||
super();
|
||||
this.coord = coord;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.serviceTime = serviceTime;
|
||||
}
|
||||
}
|
||||
|
||||
static class Relation{
|
||||
public String from;
|
||||
public String to;
|
||||
public int demand;
|
||||
public Relation(String from, String to, int demand) {
|
||||
super();
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.demand = demand;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Logger logger = Logger.getLogger(LiLimReader.class);
|
||||
|
||||
private VehicleRoutingProblem.Builder vrpBuilder;
|
||||
|
||||
private int vehicleCapacity;
|
||||
|
||||
private String depotId;
|
||||
|
||||
private Map<String,CustomerData> customers;
|
||||
|
||||
private Collection<Relation> relations;
|
||||
|
||||
private double depotOpeningTime;
|
||||
|
||||
private double depotClosingTime;
|
||||
|
||||
public LiLimReader(Builder vrpBuilder) {
|
||||
customers = new HashMap<String, LiLimReader.CustomerData>();
|
||||
relations = new ArrayList<LiLimReader.Relation>();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
}
|
||||
|
||||
public void read(String filename){
|
||||
readShipments(filename);
|
||||
buildShipments();
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", vehicleCapacity)
|
||||
.setCostPerDistance(1.0).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehicle")
|
||||
.setEarliestStart(depotOpeningTime).setLatestArrival(depotClosingTime)
|
||||
.setLocationCoord(customers.get(depotId).coord).setType(type).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
}
|
||||
|
||||
private void buildShipments() {
|
||||
Integer counter = 0;
|
||||
for(Relation rel : relations){
|
||||
counter++;
|
||||
String from = rel.from;
|
||||
String to = rel.to;
|
||||
int demand = rel.demand;
|
||||
Shipment s = Shipment.Builder.newInstance(counter.toString(), demand)
|
||||
.setPickupCoord(customers.get(from).coord).setPickupServiceTime(customers.get(from).serviceTime)
|
||||
.setPickupTimeWindow(TimeWindow.newInstance(customers.get(from).start, customers.get(from).end))
|
||||
.setDeliveryCoord(customers.get(to).coord).setDeliveryServiceTime(customers.get(to).serviceTime)
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(customers.get(to).start, customers.get(to).end)).build();
|
||||
vrpBuilder.addJob(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private BufferedReader getReader(String file) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(file));
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
logger.error(e1);
|
||||
System.exit(1);
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
|
||||
private void readShipments(String file) {
|
||||
BufferedReader reader = getReader(file);
|
||||
String line = null;
|
||||
boolean firstLine = true;
|
||||
try {
|
||||
while((line = reader.readLine()) != null){
|
||||
line = line.replace("\r", "");
|
||||
line = line.trim();
|
||||
String[] tokens = line.split("\t");
|
||||
if(firstLine){
|
||||
int vehicleCapacity = getInt(tokens[1]);
|
||||
this.vehicleCapacity = vehicleCapacity;
|
||||
firstLine = false;
|
||||
continue;
|
||||
}
|
||||
else{
|
||||
String customerId = tokens[0];
|
||||
Coordinate coord = makeCoord(tokens[1], tokens[2]);
|
||||
int demand = getInt(tokens[3]);
|
||||
double startTimeWindow = getDouble(tokens[4]);
|
||||
double endTimeWindow = getDouble(tokens[5]);
|
||||
double serviceTime = getDouble(tokens[6]);
|
||||
// vrpBuilder.addLocation(customerId, coord);
|
||||
customers.put(customerId, new CustomerData(coord,startTimeWindow,endTimeWindow, serviceTime));
|
||||
if(customerId.equals("0")){
|
||||
depotId = customerId;
|
||||
depotOpeningTime = startTimeWindow;
|
||||
depotClosingTime = endTimeWindow;
|
||||
}
|
||||
if(demand > 0){
|
||||
relations.add(new Relation(customerId,tokens[8],demand));
|
||||
}
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Coordinate makeCoord(String xString, String yString) {
|
||||
double x = Double.parseDouble(xString);
|
||||
double y = Double.parseDouble(yString);
|
||||
return new Coordinate(x,y);
|
||||
}
|
||||
|
||||
private double getDouble(String string) {
|
||||
return Double.parseDouble(string);
|
||||
}
|
||||
|
||||
private int getInt(String string) {
|
||||
return Integer.parseInt(string);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue