1
0
Fork 0
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:
Stefan Schroeder 2013-11-13 11:18:58 +01:00
commit 7a5f1052df
62 changed files with 60070 additions and 220 deletions

View file

@ -26,7 +26,7 @@ import basics.algo.InsertionEndsListener;
import basics.route.VehicleFleetManager; import basics.route.VehicleFleetManager;
import basics.route.VehicleRoute; import basics.route.VehicleRoute;
class RemoveEmptyVehicles implements InsertionEndsListener{ public class RemoveEmptyVehicles implements InsertionEndsListener{
private static Logger log = Logger.getLogger(RemoveEmptyVehicles.class); private static Logger log = Logger.getLogger(RemoveEmptyVehicles.class);

View file

@ -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.LATEST_OPERATION_START_TIME)) return new StateImpl(act.getTheoreticalLatestOperationStartTime());
if(stateId.equals(StateFactory.FUTURE_PICKS)) return new StateImpl(0); if(stateId.equals(StateFactory.FUTURE_PICKS)) return new StateImpl(0);
if(stateId.equals(StateFactory.PAST_DELIVERIES)) return new StateImpl(0); if(stateId.equals(StateFactory.PAST_DELIVERIES)) return new StateImpl(0);
if(defaultActivityStates.containsKey(stateId)) return defaultActivityStates.get(stateId);
return null; 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.LOAD_AT_BEGINNING)) return new StateImpl(0);
if(stateId.equals(StateFactory.COSTS)) return new StateImpl(0); if(stateId.equals(StateFactory.COSTS)) return new StateImpl(0);
if(stateId.equals(StateFactory.DURATION)) return new StateImpl(0); if(stateId.equals(StateFactory.DURATION)) return new StateImpl(0);
if(defaultRouteStates.containsKey(stateId)) return defaultRouteStates.get(stateId);
return null; return null;
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -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);
// }
//
//
//}

View 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);
}
}