mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
prepare for release v0.1.0
This commit is contained in:
parent
77d38de461
commit
a85b0fc395
304 changed files with 4035 additions and 64795 deletions
|
|
@ -1,19 +0,0 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
|
||||
public class BestInsertionStrategyFactory implements InsertionStrategyFactory{
|
||||
|
||||
private JobInsertionCostsCalculator jobInsertionCalculator;
|
||||
|
||||
public BestInsertionStrategyFactory(JobInsertionCostsCalculator jobInsertionCalculator) {
|
||||
super();
|
||||
this.jobInsertionCalculator = jobInsertionCalculator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InsertionStrategy createStrategy(VehicleRoutingProblem vrp) {
|
||||
return new BestInsertion(jobInsertionCalculator);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package algorithms;
|
||||
|
||||
public class ConcurrentVehicleRoutingAlgorithmWrapper {
|
||||
|
||||
|
||||
private int nuOfThreads;
|
||||
|
||||
public ConcurrentVehicleRoutingAlgorithmWrapper(int nuOfThreads) {
|
||||
super();
|
||||
this.nuOfThreads = nuOfThreads;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,53 +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 algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import basics.Job;
|
||||
import basics.algo.InsertionStartsListener;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
class FindCheaperVehicle implements InsertionStartsListener{
|
||||
|
||||
FindCheaperVehicleAlgo findCheaperVehicle;
|
||||
|
||||
public FindCheaperVehicle(FindCheaperVehicleAlgo findCheaperVehicle) {
|
||||
super();
|
||||
this.findCheaperVehicle = findCheaperVehicle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void informInsertionStarts(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) {
|
||||
List<VehicleRoute> newRoutes = new ArrayList<VehicleRoute>();
|
||||
for(VehicleRoute route : vehicleRoutes){
|
||||
if(route.isEmpty()) continue;
|
||||
VehicleRoute cheaperRoute = findCheaperVehicle.runAndGetVehicleRoute(route);
|
||||
newRoutes.add(cheaperRoute);
|
||||
}
|
||||
vehicleRoutes.clear();
|
||||
vehicleRoutes.addAll(newRoutes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[name=findCheaperVehicle]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,110 +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 algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.route.TourActivities;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleFleetManager;
|
||||
import basics.route.VehicleImpl.NoVehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
final class FindCheaperVehicleAlgo {
|
||||
|
||||
private static Logger log = Logger.getLogger(FindCheaperVehicleAlgo.class);
|
||||
|
||||
private VehicleFleetManager fleetManager;
|
||||
|
||||
private VehicleRouteUpdater tourStateCalculator;
|
||||
|
||||
private AuxilliaryCostCalculator auxilliaryCostCalculator;
|
||||
|
||||
private double weightFixCosts = 1.0;
|
||||
|
||||
private StateGetter states;
|
||||
|
||||
public void setWeightFixCosts(double weightFixCosts) {
|
||||
this.weightFixCosts = weightFixCosts;
|
||||
}
|
||||
|
||||
public void setStates(StateGetter states) {
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
public FindCheaperVehicleAlgo(VehicleFleetManager fleetManager, VehicleRouteUpdater tourStateCalculator, AuxilliaryCostCalculator auxilliaryCostCalculator) {
|
||||
super();
|
||||
this.fleetManager = fleetManager;
|
||||
this.tourStateCalculator = tourStateCalculator;
|
||||
this.auxilliaryCostCalculator = auxilliaryCostCalculator;
|
||||
}
|
||||
|
||||
|
||||
public VehicleRoute runAndGetVehicleRoute(VehicleRoute vehicleRoute) {
|
||||
if(vehicleRoute.getVehicle() instanceof NoVehicle){
|
||||
return vehicleRoute;
|
||||
}
|
||||
if(vehicleRoute.getTourActivities() == null || vehicleRoute.getVehicle() == null){
|
||||
return vehicleRoute;
|
||||
}
|
||||
// Collection<TypeKey> availableVehicleTypes = fleetManager.getAvailableVehicleTypes(new TypeKey(vehicleRoute.getVehicle().getType(),vehicleRoute.getVehicle().getLocationId()));
|
||||
double bestSaving = 0.0;
|
||||
Vehicle bestVehicle = null;
|
||||
List<TourActivity> path = new ArrayList<TourActivity>();
|
||||
path.add(vehicleRoute.getStart());
|
||||
path.addAll(vehicleRoute.getTourActivities().getActivities());
|
||||
path.add(vehicleRoute.getEnd());
|
||||
|
||||
for(Vehicle vehicle : fleetManager.getAvailableVehicles(vehicleRoute.getVehicle().getType().getTypeId(), vehicleRoute.getVehicle().getLocationId())){
|
||||
// Vehicle vehicle = fleetManager.getEmptyVehicle(vehicleType);
|
||||
if(vehicle.getType().getTypeId().equals(vehicleRoute.getVehicle().getType().getTypeId())){
|
||||
continue;
|
||||
}
|
||||
if(states.getRouteState(vehicleRoute,StateFactory.LOAD).toDouble() <= vehicle.getCapacity()){
|
||||
double fixCostSaving = vehicleRoute.getVehicle().getType().getVehicleCostParams().fix - vehicle.getType().getVehicleCostParams().fix;
|
||||
double departureTime = vehicleRoute.getStart().getEndTime();
|
||||
double newCost = auxilliaryCostCalculator.costOfPath(path, departureTime, vehicleRoute.getDriver(), vehicle);
|
||||
double varCostSaving = states.getRouteState(vehicleRoute, StateFactory.COSTS).toDouble() - newCost;
|
||||
double totalCostSaving = varCostSaving + weightFixCosts*fixCostSaving;
|
||||
if(totalCostSaving > bestSaving){
|
||||
bestSaving = totalCostSaving;
|
||||
bestVehicle = vehicle;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(bestVehicle != null){
|
||||
try{
|
||||
fleetManager.unlock(vehicleRoute.getVehicle());
|
||||
fleetManager.lock(bestVehicle);
|
||||
}
|
||||
catch(IllegalStateException e){
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
TourActivities newTour = TourActivities.copyOf(vehicleRoute.getTourActivities());
|
||||
tourStateCalculator.iterate(vehicleRoute);
|
||||
return VehicleRoute.newInstance(newTour,vehicleRoute.getDriver(),bestVehicle);
|
||||
}
|
||||
return vehicleRoute;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,220 +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 algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.RandomNumberGeneration;
|
||||
import basics.Job;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.algo.InsertionListener;
|
||||
import basics.algo.RuinListener;
|
||||
import basics.algo.SearchStrategyModule;
|
||||
import basics.algo.SearchStrategyModuleListener;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.TourActivity.JobActivity;
|
||||
import basics.route.VehicleFleetManager;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
public final class Gendreau implements SearchStrategyModule{
|
||||
|
||||
private final static Logger log = Logger.getLogger(Gendreau.class);
|
||||
|
||||
private final static String NAME = "gendreauPostOpt";
|
||||
|
||||
private final RuinStrategy ruin;
|
||||
|
||||
private final VehicleRoutingProblem vrp;
|
||||
|
||||
private final InsertionStrategy insertionStrategy;
|
||||
|
||||
private VehicleFleetManager fleetManager;
|
||||
|
||||
private Random random = RandomNumberGeneration.getRandom();
|
||||
|
||||
private int nOfIterations = 10;
|
||||
|
||||
private double shareOfJobsToRuin = 0.15;
|
||||
|
||||
public void setShareOfJobsToRuin(double shareOfJobsToRuin) {
|
||||
this.shareOfJobsToRuin = shareOfJobsToRuin;
|
||||
}
|
||||
|
||||
public Gendreau(VehicleRoutingProblem vrp, RuinStrategy ruin, InsertionStrategy insertionStrategy, VehicleFleetManager vehicleFleetManager) {
|
||||
super();
|
||||
InsertionListeners insertionListeners = new InsertionListeners();
|
||||
insertionListeners.addAllListeners(insertionStrategy.getListeners());
|
||||
new Inserter(insertionListeners);
|
||||
this.ruin = ruin;
|
||||
this.vrp = vrp;
|
||||
this.insertionStrategy = insertionStrategy;
|
||||
this.fleetManager = vehicleFleetManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[name=gendreau][iterations="+nOfIterations+"][share2ruin="+shareOfJobsToRuin+"]";
|
||||
}
|
||||
|
||||
public void setRandom(Random random) {
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
|
||||
public void setNuOfIterations(int nOfIterations) {
|
||||
this.nOfIterations = nOfIterations;
|
||||
}
|
||||
|
||||
// public void setFleetManager(VehicleFleetManager vehicleFleetManager) {
|
||||
// this.fleetManager = vehicleFleetManager;
|
||||
//
|
||||
// }
|
||||
|
||||
@Override
|
||||
public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) {
|
||||
// log.info("run gendreau postopt");
|
||||
VehicleRoutingProblemSolution bestSolution = vrpSolution;
|
||||
int itersWithoutImprovement = 0;
|
||||
|
||||
for(int i=0;i<nOfIterations;i++){
|
||||
List<VehicleRoute> copiedRoutes = copyRoutes(bestSolution.getRoutes());
|
||||
iniFleet(copiedRoutes);
|
||||
|
||||
VehicleRoute route2split = pickRouteThatHasAtLeastTwoJobs(copiedRoutes);
|
||||
if(route2split == null) continue;
|
||||
List<Job> jobsInRoute = getJobs(route2split);
|
||||
Set<Job> unassignedJobs = new HashSet<Job>();
|
||||
unassignedJobs.addAll(jobsInRoute);
|
||||
copiedRoutes.remove(route2split);
|
||||
|
||||
Collections.shuffle(jobsInRoute,random);
|
||||
Job targetJob = jobsInRoute.get(0);
|
||||
int nOfJobs2BeRemovedAdditionally = (int) (shareOfJobsToRuin*(double)vrp.getJobs().size());
|
||||
Collection<Job> unassignedJobsList = ruin.ruin(copiedRoutes, targetJob, nOfJobs2BeRemovedAdditionally);
|
||||
unassignedJobs.addAll(unassignedJobsList);
|
||||
|
||||
VehicleRoute emptyRoute1 = VehicleRoute.emptyRoute();
|
||||
copiedRoutes.add(emptyRoute1);
|
||||
insertionStrategy.insertJobs(Arrays.asList(emptyRoute1), Arrays.asList(targetJob));
|
||||
|
||||
unassignedJobs.remove(targetJob);
|
||||
|
||||
VehicleRoute emptyRoute2 = VehicleRoute.emptyRoute();
|
||||
copiedRoutes.add(emptyRoute2);
|
||||
Job job2 = jobsInRoute.get(1);
|
||||
insertionStrategy.insertJobs(Arrays.asList(emptyRoute2), Arrays.asList(job2));
|
||||
|
||||
unassignedJobs.remove(job2);
|
||||
|
||||
insertionStrategy.insertJobs(copiedRoutes, unassignedJobs);
|
||||
double cost = getCost(copiedRoutes);
|
||||
|
||||
if(cost < bestSolution.getCost()){
|
||||
// log.info("BING - new: " + cost + " old: " + bestSolution.getCost());
|
||||
bestSolution = new VehicleRoutingProblemSolution(copiedRoutes, cost);
|
||||
itersWithoutImprovement=0;
|
||||
}
|
||||
else{
|
||||
itersWithoutImprovement++;
|
||||
if(itersWithoutImprovement > 200){
|
||||
// log.info("BREAK i="+i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return bestSolution;
|
||||
}
|
||||
|
||||
private List<VehicleRoute> copyRoutes(Collection<VehicleRoute> routes) {
|
||||
List<VehicleRoute> routeList = new ArrayList<VehicleRoute>();
|
||||
for(VehicleRoute r : routes){
|
||||
routeList.add(VehicleRoute.copyOf(r));
|
||||
}
|
||||
return routeList;
|
||||
}
|
||||
|
||||
private void iniFleet(Collection<VehicleRoute> routes) {
|
||||
fleetManager.unlockAll();
|
||||
for(VehicleRoute route : routes){
|
||||
if(!route.isEmpty()){
|
||||
fleetManager.lock(route.getVehicle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double getCost(Collection<VehicleRoute> routes) {
|
||||
double c = 0.0;
|
||||
for(VehicleRoute r : routes){
|
||||
c+=r.getCost();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private List<Job> getJobs(VehicleRoute route2split) {
|
||||
Set<Job> jobs = new HashSet<Job>();
|
||||
for(TourActivity act : route2split.getTourActivities().getActivities()){
|
||||
if(act instanceof JobActivity){
|
||||
jobs.add(((JobActivity) act).getJob());
|
||||
}
|
||||
}
|
||||
return new ArrayList<Job>(jobs);
|
||||
}
|
||||
|
||||
private VehicleRoute pickRouteThatHasAtLeastTwoJobs(Collection<VehicleRoute> routeList) {
|
||||
List<VehicleRoute> routes = new ArrayList<VehicleRoute>();
|
||||
for(VehicleRoute r : routeList){
|
||||
if(getJobs(r).size() > 1){
|
||||
routes.add(r);
|
||||
}
|
||||
}
|
||||
if(routes.isEmpty()) return null;
|
||||
Collections.shuffle(routes,random);
|
||||
return routes.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addModuleListener(SearchStrategyModuleListener moduleListener) {
|
||||
if(moduleListener instanceof InsertionListener){
|
||||
InsertionListener iListener = (InsertionListener) moduleListener;
|
||||
if(!insertionStrategy.getListeners().contains(iListener)){
|
||||
insertionStrategy.addListener(iListener);
|
||||
}
|
||||
}
|
||||
if(moduleListener instanceof RuinListener){
|
||||
RuinListener rListener = (RuinListener) moduleListener;
|
||||
if(!ruin.getListeners().contains(rListener)){
|
||||
ruin.addListener(rListener);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.route.TourActivity;
|
||||
|
||||
public interface HardActivityStateLevelConstraint {
|
||||
|
||||
static enum ConstraintsStatus {
|
||||
|
||||
NOT_FULFILLED_BREAK, NOT_FULFILLED, FULFILLED;
|
||||
|
||||
}
|
||||
|
||||
public ConstraintsStatus fulfilled(InsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime);
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
package algorithms;
|
||||
|
||||
|
||||
public interface HardRouteStateLevelConstraint {
|
||||
|
||||
public boolean fulfilled(InsertionContext insertionContext);
|
||||
|
||||
}
|
||||
|
|
@ -1,57 +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 algorithms;
|
||||
|
||||
import util.CrowFlyCosts;
|
||||
import util.Locations;
|
||||
import basics.Job;
|
||||
import basics.Service;
|
||||
|
||||
|
||||
|
||||
class JobDistanceBeeline implements JobDistance {
|
||||
|
||||
private Locations locations;
|
||||
|
||||
public JobDistanceBeeline(Locations locations) {
|
||||
super();
|
||||
this.locations = locations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDistance(Job i, Job j) {
|
||||
double avgCost = 0.0;
|
||||
if (i instanceof Service && j instanceof Service) {
|
||||
if (i.equals(j)) {
|
||||
avgCost = 0.0;
|
||||
} else {
|
||||
Service s_i = (Service) i;
|
||||
Service s_j = (Service) j;
|
||||
avgCost = calcDist(s_i.getLocationId(), s_j.getLocationId());
|
||||
}
|
||||
} else {
|
||||
throw new UnsupportedOperationException(
|
||||
"currently, this class just works with shipments and services.");
|
||||
}
|
||||
return avgCost;
|
||||
}
|
||||
|
||||
private double calcDist(String from, String to) {
|
||||
return new CrowFlyCosts(locations).getTransportCost(from, to, 0.0,null, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,59 +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 algorithms;
|
||||
|
||||
import basics.Job;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
class ScoredJob {
|
||||
|
||||
private final Job job;
|
||||
|
||||
private final double score;
|
||||
|
||||
private final InsertionData insertionData;
|
||||
|
||||
private final VehicleRoute route;
|
||||
|
||||
public ScoredJob(final Job job, final double score, final InsertionData insertionData, final VehicleRoute route) {
|
||||
super();
|
||||
this.job = job;
|
||||
this.score = score;
|
||||
this.insertionData = insertionData;
|
||||
this.route = route;
|
||||
}
|
||||
|
||||
public InsertionData getInsertionData() {
|
||||
return insertionData;
|
||||
}
|
||||
|
||||
public VehicleRoute getRoute() {
|
||||
return route;
|
||||
}
|
||||
|
||||
public Job getJob() {
|
||||
return job;
|
||||
}
|
||||
|
||||
public double getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.route.DeliverShipment;
|
||||
import basics.route.PickupShipment;
|
||||
import basics.route.TourActivity;
|
||||
|
||||
public class ShipmentPickupsFirstConstraint implements HardActivityStateLevelConstraint {
|
||||
|
||||
@Override
|
||||
public ConstraintsStatus fulfilled(InsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||
if(newAct instanceof DeliverShipment && nextAct instanceof PickupShipment){ return ConstraintsStatus.NOT_FULFILLED; }
|
||||
if(newAct instanceof PickupShipment && prevAct instanceof DeliverShipment){ return ConstraintsStatus.NOT_FULFILLED_BREAK; }
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package algorithms;
|
||||
|
||||
public interface StateUpdater {
|
||||
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
package algorithms;
|
||||
|
||||
import util.ActivityTimeTracker;
|
||||
import algorithms.StateManager.StateImpl;
|
||||
import basics.costs.VehicleRoutingTransportCosts;
|
||||
import basics.route.ActivityVisitor;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
class UpdateEarliestStartTime implements ActivityVisitor,StateUpdater{
|
||||
|
||||
private StateManager states;
|
||||
|
||||
private ActivityTimeTracker timeTracker;
|
||||
|
||||
public UpdateEarliestStartTime(StateManager states, VehicleRoutingTransportCosts transportCosts) {
|
||||
super();
|
||||
this.states = states;
|
||||
timeTracker = new ActivityTimeTracker(transportCosts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
timeTracker.begin(route);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity activity) {
|
||||
timeTracker.visit(activity);
|
||||
states.putActivityState(activity, StateFactory.EARLIEST_OPERATION_START_TIME, new StateImpl(Math.max(timeTracker.getActArrTime(), activity.getTheoreticalEarliestOperationStartTime())));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {}
|
||||
|
||||
}
|
||||
|
|
@ -1,33 +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 algorithms;
|
||||
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
/**
|
||||
* Updater that updates a vehicleRoute, e.g. the total costs or the time-windows.
|
||||
*
|
||||
* @author stefan schroeder
|
||||
*
|
||||
*/
|
||||
|
||||
interface VehicleRouteUpdater {
|
||||
|
||||
public void iterate(VehicleRoute vehicleRoute);
|
||||
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.algo.SearchStrategyManager;
|
||||
import basics.algo.VehicleRoutingAlgorithmFactory;
|
||||
import basics.route.VehicleFleetManager;
|
||||
|
||||
public class VehicleRoutingAlgorithmFactoryImpl implements VehicleRoutingAlgorithmFactory{
|
||||
|
||||
private SearchStrategyManager searchStrategyManager;
|
||||
|
||||
private StateManager stateManager;
|
||||
|
||||
private VehicleFleetManager fleetManager;
|
||||
|
||||
public VehicleRoutingAlgorithmFactoryImpl(SearchStrategyManager searchStrategyManager,
|
||||
StateManager stateManager, VehicleFleetManager fleetManager) {
|
||||
super();
|
||||
this.searchStrategyManager = searchStrategyManager;
|
||||
this.stateManager = stateManager;
|
||||
this.fleetManager = fleetManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) {
|
||||
this.stateManager.addActivityVisitor(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), this.stateManager));
|
||||
//<<<<<<< HEAD
|
||||
// this.stateManager.addActivityVisitor(new UpdateMaxLoad(this.stateManager));
|
||||
this.stateManager.addActivityVisitor(new UpdateActivityTimes(vrp.getTransportCosts()));
|
||||
//=======
|
||||
//// this.stateManager.addActivityVisitor(new UpdateMaxLoad_(this.stateManager));
|
||||
//>>>>>>> refs/heads/pickupAndDelivery
|
||||
VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(vrp, searchStrategyManager);
|
||||
algorithm.getAlgorithmListeners().addListener(stateManager);
|
||||
algorithm.getSearchStrategyManager().addSearchStrategyModuleListener(stateManager);
|
||||
algorithm.getSearchStrategyManager().addSearchStrategyModuleListener(new RemoveEmptyVehicles(fleetManager));
|
||||
return algorithm;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package basics.algo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.Job;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
public class InsertionListeners {
|
||||
|
||||
private Collection<InsertionStartsListener> startListeners = new ArrayList<InsertionStartsListener>();
|
||||
|
||||
private Collection<JobInsertedListener> jobInsertedListeners = new ArrayList<JobInsertedListener>();
|
||||
|
||||
private Collection<InsertionEndsListener> endListeners = new ArrayList<InsertionEndsListener>();
|
||||
|
||||
public void addListener(InsertionListener insertionListener){
|
||||
if(insertionListener instanceof InsertionStartsListener) startListeners.add((InsertionStartsListener) insertionListener);
|
||||
if(insertionListener instanceof JobInsertedListener) jobInsertedListeners.add((JobInsertedListener) insertionListener);
|
||||
if(insertionListener instanceof InsertionEndsListener) endListeners.add((InsertionEndsListener) insertionListener);
|
||||
// else throw new IllegalStateException("cannot add this type of insertionListener");
|
||||
}
|
||||
|
||||
public void removeListener(InsertionListener insertionListener){
|
||||
if(insertionListener instanceof InsertionStartsListener) startListeners.remove((InsertionStartsListener) insertionListener);
|
||||
if(insertionListener instanceof JobInsertedListener) jobInsertedListeners.remove((JobInsertedListener) insertionListener);
|
||||
if(insertionListener instanceof InsertionEndsListener) endListeners.remove((InsertionEndsListener) insertionListener);
|
||||
// else throw new IllegalStateException("cannot remove this type of insertionListener");
|
||||
}
|
||||
|
||||
public void insertionStarts(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs){
|
||||
for(InsertionStartsListener l : startListeners) l.informInsertionStarts(vehicleRoutes, unassignedJobs);
|
||||
}
|
||||
|
||||
public void jobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime){
|
||||
for(JobInsertedListener l : jobInsertedListeners) l.informJobInserted(job2insert, inRoute, additionalCosts, additionalTime);
|
||||
}
|
||||
|
||||
public void insertionEnds(Collection<VehicleRoute> vehicleRoutes){
|
||||
for(InsertionEndsListener l : endListeners){ l.informInsertionEnds(vehicleRoutes); }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +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 basics.costs;
|
||||
|
||||
import basics.route.Driver;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.Vehicle;
|
||||
|
||||
|
||||
/**
|
||||
* DefaultActivityCosts = 0.0, i.e. activities do not induce costs at all.
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public class DefaultVehicleRoutingActivityCosts implements VehicleRoutingActivityCosts{
|
||||
|
||||
@Override
|
||||
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[name=defaultActivityCosts]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,128 +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 basics.route;
|
||||
|
||||
|
||||
|
||||
public class DefaultVehicleRouteCostCalculator implements VehicleRouteCostCalculator {
|
||||
|
||||
private double tpCosts = 0.0;
|
||||
private double actCosts = 0.0;
|
||||
private double vehicleCosts = 0.0;
|
||||
private double driverCosts = 0.0;
|
||||
private double other = 0.0;
|
||||
|
||||
public DefaultVehicleRouteCostCalculator(){}
|
||||
|
||||
private DefaultVehicleRouteCostCalculator(DefaultVehicleRouteCostCalculator costCalc){
|
||||
this.tpCosts=costCalc.getTpCosts();
|
||||
this.actCosts = costCalc.getActCosts();
|
||||
this.driverCosts = costCalc.getDriverCosts();
|
||||
this.other = costCalc.getOther();
|
||||
this.vehicleCosts = costCalc.getVehicleCosts();
|
||||
}
|
||||
|
||||
public void addTransportCost(double tpCost) {
|
||||
this.tpCosts+=tpCost;
|
||||
}
|
||||
|
||||
public void addActivityCost(double actCost){
|
||||
this.actCosts+=actCost;
|
||||
}
|
||||
|
||||
public void price(Vehicle vehicle){
|
||||
if(vehicle != null){
|
||||
VehicleType type = vehicle.getType();
|
||||
if(type != null){
|
||||
this.vehicleCosts = type.getVehicleCostParams().fix;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void price(Driver driver){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
tpCosts = 0.0;
|
||||
actCosts = 0.0;
|
||||
vehicleCosts = 0.0;
|
||||
driverCosts = 0.0;
|
||||
other = 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOtherCost(double cost) {
|
||||
this.other = cost;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCosts() {
|
||||
return tpCosts + actCosts + vehicleCosts + driverCosts + other;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tpCosts
|
||||
*/
|
||||
public double getTpCosts() {
|
||||
return tpCosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actCosts
|
||||
*/
|
||||
public double getActCosts() {
|
||||
return actCosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the vehicleCosts
|
||||
*/
|
||||
public double getVehicleCosts() {
|
||||
return vehicleCosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the driverCosts
|
||||
*/
|
||||
public double getDriverCosts() {
|
||||
return driverCosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the other
|
||||
*/
|
||||
public double getOther() {
|
||||
return other;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VehicleRouteCostCalculator duplicate() {
|
||||
return new DefaultVehicleRouteCostCalculator(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,209 +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 basics.route;
|
||||
|
||||
import basics.route.VehicleImpl.NoVehicle;
|
||||
|
||||
public class VehicleRoute {
|
||||
|
||||
public static VehicleRoute copyOf(VehicleRoute route) {
|
||||
return new VehicleRoute(route);
|
||||
}
|
||||
|
||||
public static VehicleRoute newInstance(TourActivities tour, Driver driver, Vehicle vehicle) {
|
||||
return new VehicleRoute(tour,driver,vehicle);
|
||||
}
|
||||
|
||||
public static VehicleRoute emptyRoute() {
|
||||
return new VehicleRoute(TourActivities.emptyTour(), DriverImpl.noDriver(), VehicleImpl.noVehicle());
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
public static Builder newInstance(Start start, End end){
|
||||
return new Builder(start,end);
|
||||
}
|
||||
|
||||
private Start start;
|
||||
|
||||
private End end;
|
||||
|
||||
private Vehicle vehicle = VehicleImpl.noVehicle();
|
||||
|
||||
private Driver driver = DriverImpl.noDriver();
|
||||
|
||||
private TourActivities tour;
|
||||
|
||||
private Builder(Start start, End end) {
|
||||
super();
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.tour = TourActivities.emptyTour();
|
||||
}
|
||||
|
||||
public Builder setVehicle(Vehicle vehicle){
|
||||
this.vehicle = vehicle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDriver(Driver driver){
|
||||
this.driver = driver;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addActivity(TourActivity act){
|
||||
if(act instanceof Start || act instanceof End){
|
||||
throw new IllegalStateException("tourActivity should be of type Delivery or Pickup, but is of type " + act.getName());
|
||||
}
|
||||
tour.addActivity(act);
|
||||
return this;
|
||||
}
|
||||
|
||||
public VehicleRoute build(){
|
||||
return new VehicleRoute(this);
|
||||
}
|
||||
}
|
||||
|
||||
private TourActivities tourActivities;
|
||||
|
||||
private Vehicle vehicle;
|
||||
|
||||
private Driver driver;
|
||||
|
||||
private Start start;
|
||||
|
||||
private End end;
|
||||
|
||||
@Deprecated
|
||||
private VehicleRouteCostCalculator costCalculator = new DefaultVehicleRouteCostCalculator();
|
||||
|
||||
@Deprecated
|
||||
public VehicleRouteCostCalculator getVehicleRouteCostCalculator(){
|
||||
return costCalculator;
|
||||
}
|
||||
|
||||
private VehicleRoute(VehicleRoute route){
|
||||
this.start = Start.copyOf(route.getStart());
|
||||
this.end = End.copyOf(route.getEnd());
|
||||
this.tourActivities = TourActivities.copyOf(route.getTourActivities());
|
||||
this.vehicle = route.getVehicle();
|
||||
this.driver = route.getDriver();
|
||||
this.costCalculator = route.getVehicleRouteCostCalculator().duplicate();
|
||||
}
|
||||
|
||||
private VehicleRoute(TourActivities tour, Driver driver, Vehicle vehicle) {
|
||||
super();
|
||||
verify(tour, driver, vehicle);
|
||||
this.tourActivities = tour;
|
||||
this.vehicle = vehicle;
|
||||
this.driver = driver;
|
||||
setStartAndEnd(vehicle, vehicle.getEarliestDeparture());
|
||||
}
|
||||
|
||||
private VehicleRoute(Builder builder){
|
||||
this.tourActivities = builder.tour;
|
||||
this.vehicle = builder.vehicle;
|
||||
this.driver = builder.driver;
|
||||
this.start = builder.start;
|
||||
this.end = builder.end;
|
||||
}
|
||||
|
||||
private void verify(TourActivities tour, Driver driver, Vehicle vehicle) {
|
||||
if(tour == null || driver == null || vehicle == null) throw new IllegalStateException("null is not allowed for tour, driver or vehicle. use emptyRoute. use Tour.emptyTour, DriverImpl.noDriver() and VehicleImpl.noVehicle() instead." +
|
||||
"\n\tor make it easier and use VehicleRoute.emptyRoute()");
|
||||
if(!tour.isEmpty() && vehicle instanceof NoVehicle){
|
||||
throw new IllegalStateException("if tour is not empty. there must be a vehicle for this tour, but there is no vehicle.");
|
||||
}
|
||||
}
|
||||
|
||||
public TourActivities getTourActivities() {
|
||||
return tourActivities;
|
||||
}
|
||||
|
||||
|
||||
public Vehicle getVehicle() {
|
||||
return vehicle;
|
||||
}
|
||||
|
||||
public Driver getDriver() {
|
||||
return driver;
|
||||
}
|
||||
|
||||
public void setVehicle(Vehicle vehicle, double vehicleDepTime){
|
||||
this.vehicle = vehicle;
|
||||
setStartAndEnd(vehicle, vehicleDepTime);
|
||||
}
|
||||
|
||||
public void setDepartureTime(double vehicleDepTime){
|
||||
if(start == null) throw new IllegalStateException("cannot set departureTime without having a vehicle on this route. use setVehicle(vehicle,departureTime) instead.");
|
||||
start.setEndTime(vehicleDepTime);
|
||||
}
|
||||
|
||||
public double getDepartureTime(){
|
||||
if(start == null) throw new IllegalStateException("cannot get departureTime without having a vehicle on this route. use setVehicle(vehicle,departureTime) instead.");
|
||||
return start.getEndTime();
|
||||
}
|
||||
|
||||
private void setStartAndEnd(Vehicle vehicle, double vehicleDepTime) {
|
||||
if(!(vehicle instanceof NoVehicle)){
|
||||
if(start == null && end == null){
|
||||
start = Start.newInstance(vehicle.getLocationId(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival());
|
||||
end = End.newInstance(vehicle.getLocationId(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival());
|
||||
}
|
||||
start.setEndTime(vehicleDepTime);
|
||||
start.setTheoreticalEarliestOperationStartTime(vehicle.getEarliestDeparture());
|
||||
start.setTheoreticalLatestOperationStartTime(vehicle.getLatestArrival());
|
||||
start.setLocationId(vehicle.getLocationId());
|
||||
end.setLocationId(vehicle.getLocationId());
|
||||
end.setTheoreticalEarliestOperationStartTime(vehicle.getEarliestDeparture());
|
||||
end.setTheoreticalLatestOperationStartTime(vehicle.getLatestArrival());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean isEmpty() {
|
||||
return tourActivities.isEmpty();
|
||||
}
|
||||
|
||||
public Start getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public End getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[start="+start+"][end=" + end + "][departureTime=" + start.getEndTime() + "][vehicle=" + vehicle + "][driver=" + driver + "][nuOfActs="+tourActivities.getActivities().size()+"]";
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setVehicleRouteCostCalculator(VehicleRouteCostCalculator costAccumulator){
|
||||
this.costCalculator = costAccumulator;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public double getCost() {
|
||||
if(tourActivities.isEmpty()){
|
||||
return 0.0;
|
||||
}
|
||||
return costCalculator.getCosts();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,151 +0,0 @@
|
|||
package basics.route;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import basics.Service;
|
||||
import basics.Shipment;
|
||||
|
||||
/**
|
||||
* Builds a {@link VehicleRoute}.
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public class VehicleRouteBuilder {
|
||||
|
||||
private Vehicle vehicle;
|
||||
|
||||
private Driver driver;
|
||||
|
||||
private Start start;
|
||||
|
||||
private TourActivities tourActivities = new TourActivities();
|
||||
|
||||
private TourActivityFactory serviceActivityFactory = new DefaultTourActivityFactory();
|
||||
|
||||
private TourShipmentActivityFactory shipmentActivityFactory = new DefaultShipmentActivityFactory();
|
||||
|
||||
private Set<Shipment> openShipments = new HashSet<Shipment>();
|
||||
|
||||
public void setServiceActivityFactory(TourActivityFactory serviceActivityFactory) {
|
||||
this.serviceActivityFactory = serviceActivityFactory;
|
||||
}
|
||||
|
||||
public void setShipmentActivityFactory(TourShipmentActivityFactory shipmentActivityFactory) {
|
||||
this.shipmentActivityFactory = shipmentActivityFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the route-builder.
|
||||
* @param vehicle
|
||||
* @param driver
|
||||
*/
|
||||
public VehicleRouteBuilder(Vehicle vehicle, Driver driver) {
|
||||
super();
|
||||
this.vehicle = vehicle;
|
||||
this.driver = driver;
|
||||
start = Start.newInstance(vehicle.getLocationId(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival());
|
||||
start.setEndTime(vehicle.getEarliestDeparture());
|
||||
End.newInstance(vehicle.getLocationId(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the departure-time of the route.
|
||||
*
|
||||
* @param departureTime
|
||||
* @return
|
||||
*/
|
||||
public VehicleRouteBuilder setDepartureTime(double departureTime){
|
||||
start.setEndTime(departureTime);
|
||||
return this;
|
||||
}
|
||||
|
||||
public VehicleRouteBuilder addService(Service service){
|
||||
addService(service,0.0,0.0);
|
||||
return this;
|
||||
}
|
||||
|
||||
public VehicleRouteBuilder addService(Service service, double arrTime, double endTime){
|
||||
TourActivity act = serviceActivityFactory.createActivity(service);
|
||||
act.setArrTime(arrTime);
|
||||
act.setEndTime(endTime);
|
||||
tourActivities.addActivity(act);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a the pickup of the specified shipment.
|
||||
*
|
||||
* @param shipment
|
||||
* @throws IllegalStateException if method has already been called with the specified shipment.
|
||||
* @return
|
||||
*/
|
||||
public VehicleRouteBuilder addPickup(Shipment shipment){
|
||||
addPickup(shipment,0.0,0.0);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a the pickup of the specified shipment at specified arrival and end-time.
|
||||
*
|
||||
* @param shipment
|
||||
* @throws IllegalStateException if method has already been called with the specified shipment.
|
||||
* @return
|
||||
*/
|
||||
public VehicleRouteBuilder addPickup(Shipment shipment, double arrTime, double endTime){
|
||||
if(openShipments.contains(shipment)) throw new IllegalStateException("shipment has already been added. cannot add it twice.");
|
||||
TourActivity act = shipmentActivityFactory.createPickup(shipment);
|
||||
act.setArrTime(arrTime);
|
||||
act.setEndTime(endTime);
|
||||
tourActivities.addActivity(act);
|
||||
openShipments.add(shipment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a the delivery of the specified shipment.
|
||||
*
|
||||
* @param shipment
|
||||
* @throws IllegalStateException if specified shipment has not been picked up yet (i.e. method addPickup(shipment) has not been called yet).
|
||||
* @return
|
||||
*/
|
||||
public VehicleRouteBuilder addDelivery(Shipment shipment){
|
||||
addDelivery(shipment,0.0,0.0);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a the delivery of the specified shipment at a specified arrival and endTime.
|
||||
*
|
||||
* @param shipment
|
||||
* @throws IllegalStateException if specified shipment has not been picked up yet (i.e. method addPickup(shipment) has not been called yet).
|
||||
* @return
|
||||
*/
|
||||
public VehicleRouteBuilder addDelivery(Shipment shipment, double arrTime, double endTime){
|
||||
if(openShipments.contains(shipment)){
|
||||
TourActivity act = shipmentActivityFactory.createDelivery(shipment);
|
||||
act.setArrTime(arrTime);
|
||||
act.setEndTime(endTime);
|
||||
tourActivities.addActivity(act);
|
||||
openShipments.remove(shipment);
|
||||
}
|
||||
else{ throw new IllegalStateException("cannot deliver shipment. shipment " + shipment + " needs to be picked up first."); }
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the route.
|
||||
*
|
||||
* @return {@link VehicleRoute}
|
||||
* @throws IllegalStateException if there are still shipments that have been picked up though but not delivery.
|
||||
*/
|
||||
public VehicleRoute build(){
|
||||
if(!openShipments.isEmpty()){
|
||||
throw new IllegalStateException("there are still shipments that have not been delivered yet.");
|
||||
}
|
||||
VehicleRoute route = VehicleRoute.newInstance(tourActivities, driver, vehicle);
|
||||
return route;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,40 +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 basics.route;
|
||||
|
||||
@Deprecated
|
||||
public interface VehicleRouteCostCalculator {
|
||||
|
||||
public void addTransportCost(double cost);
|
||||
|
||||
public void addActivityCost(double cost);
|
||||
|
||||
public void addOtherCost(double cost);
|
||||
|
||||
public void price(Vehicle vehicle);
|
||||
|
||||
public void price(Driver driver);
|
||||
|
||||
public double getCosts();
|
||||
|
||||
public void finish();
|
||||
|
||||
public void reset();
|
||||
|
||||
public VehicleRouteCostCalculator duplicate();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
///*******************************************************************************
|
||||
// * 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 jsprit.core.algorithm;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Collection;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import jsprit.core.algorithm.recreate.listener.InsertionStartsListener;
|
||||
//import jsprit.core.problem.job.Job;
|
||||
//import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
//
|
||||
//
|
||||
//class FindCheaperVehicle implements InsertionStartsListener{
|
||||
//
|
||||
// FindCheaperVehicleAlgo findCheaperVehicle;
|
||||
//
|
||||
// public FindCheaperVehicle(FindCheaperVehicleAlgo findCheaperVehicle) {
|
||||
// super();
|
||||
// this.findCheaperVehicle = findCheaperVehicle;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void informInsertionStarts(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) {
|
||||
// List<VehicleRoute> newRoutes = new ArrayList<VehicleRoute>();
|
||||
// for(VehicleRoute route : vehicleRoutes){
|
||||
// if(route.isEmpty()) continue;
|
||||
// VehicleRoute cheaperRoute = findCheaperVehicle.runAndGetVehicleRoute(route);
|
||||
// newRoutes.add(cheaperRoute);
|
||||
// }
|
||||
// vehicleRoutes.clear();
|
||||
// vehicleRoutes.addAll(newRoutes);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString() {
|
||||
// return "[name=findCheaperVehicle]";
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
///*******************************************************************************
|
||||
// * 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 jsprit.core.algorithm;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import jsprit.core.algorithm.recreate.AuxilliaryCostCalculator;
|
||||
//import jsprit.core.algorithm.state.StateFactory;
|
||||
//import jsprit.core.algorithm.state.StateGetter;
|
||||
//import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
//import jsprit.core.problem.solution.route.activity.TourActivities;
|
||||
//import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
//import jsprit.core.problem.vehicle.Vehicle;
|
||||
//import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
//import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
|
||||
//
|
||||
//import org.apache.log4j.Logger;
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//final class FindCheaperVehicleAlgo {
|
||||
//
|
||||
// private static Logger log = Logger.getLogger(FindCheaperVehicleAlgo.class);
|
||||
//
|
||||
// private VehicleFleetManager fleetManager;
|
||||
//
|
||||
// private VehicleRouteUpdater tourStateCalculator;
|
||||
//
|
||||
// private AuxilliaryCostCalculator auxilliaryCostCalculator;
|
||||
//
|
||||
// private double weightFixCosts = 1.0;
|
||||
//
|
||||
// private StateGetter states;
|
||||
//
|
||||
// public void setWeightFixCosts(double weightFixCosts) {
|
||||
// this.weightFixCosts = weightFixCosts;
|
||||
// }
|
||||
//
|
||||
// public void setStates(StateGetter states) {
|
||||
// this.states = states;
|
||||
// }
|
||||
//
|
||||
// public FindCheaperVehicleAlgo(VehicleFleetManager fleetManager, VehicleRouteUpdater tourStateCalculator, AuxilliaryCostCalculator auxilliaryCostCalculator) {
|
||||
// super();
|
||||
// this.fleetManager = fleetManager;
|
||||
// this.tourStateCalculator = tourStateCalculator;
|
||||
// this.auxilliaryCostCalculator = auxilliaryCostCalculator;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public VehicleRoute runAndGetVehicleRoute(VehicleRoute vehicleRoute) {
|
||||
// if(vehicleRoute.getVehicle() instanceof NoVehicle){
|
||||
// return vehicleRoute;
|
||||
// }
|
||||
// if(vehicleRoute.getTourActivities() == null || vehicleRoute.getVehicle() == null){
|
||||
// return vehicleRoute;
|
||||
// }
|
||||
//// Collection<TypeKey> availableVehicleTypes = fleetManager.getAvailableVehicleTypes(new TypeKey(vehicleRoute.getVehicle().getType(),vehicleRoute.getVehicle().getLocationId()));
|
||||
// double bestSaving = 0.0;
|
||||
// Vehicle bestVehicle = null;
|
||||
// List<TourActivity> path = new ArrayList<TourActivity>();
|
||||
// path.add(vehicleRoute.getStart());
|
||||
// path.addAll(vehicleRoute.getTourActivities().getActivities());
|
||||
// path.add(vehicleRoute.getEnd());
|
||||
//
|
||||
// for(Vehicle vehicle : fleetManager.getAvailableVehicles(vehicleRoute.getVehicle().getType().getTypeId(), vehicleRoute.getVehicle().getLocationId())){
|
||||
//// Vehicle vehicle = fleetManager.getEmptyVehicle(vehicleType);
|
||||
// if(vehicle.getType().getTypeId().equals(vehicleRoute.getVehicle().getType().getTypeId())){
|
||||
// continue;
|
||||
// }
|
||||
// if(states.getRouteState(vehicleRoute,StateFactory.LOAD).toDouble() <= vehicle.getCapacity()){
|
||||
// double fixCostSaving = vehicleRoute.getVehicle().getType().getVehicleCostParams().fix - vehicle.getType().getVehicleCostParams().fix;
|
||||
// double departureTime = vehicleRoute.getStart().getEndTime();
|
||||
// double newCost = auxilliaryCostCalculator.costOfPath(path, departureTime, vehicleRoute.getDriver(), vehicle);
|
||||
// double varCostSaving = states.getRouteState(vehicleRoute, StateFactory.COSTS).toDouble() - newCost;
|
||||
// double totalCostSaving = varCostSaving + weightFixCosts*fixCostSaving;
|
||||
// if(totalCostSaving > bestSaving){
|
||||
// bestSaving = totalCostSaving;
|
||||
// bestVehicle = vehicle;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if(bestVehicle != null){
|
||||
// try{
|
||||
// fleetManager.unlock(vehicleRoute.getVehicle());
|
||||
// fleetManager.lock(bestVehicle);
|
||||
// }
|
||||
// catch(IllegalStateException e){
|
||||
// throw new IllegalStateException(e);
|
||||
// }
|
||||
// TourActivities newTour = TourActivities.copyOf(vehicleRoute.getTourActivities());
|
||||
// tourStateCalculator.iterate(vehicleRoute);
|
||||
// return VehicleRoute.newInstance(newTour,vehicleRoute.getDriver(),bestVehicle);
|
||||
// }
|
||||
// return vehicleRoute;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
@ -30,18 +30,21 @@
|
|||
* *
|
||||
* *********************************************************************** */
|
||||
|
||||
package algorithms;
|
||||
package jsprit.core.algorithm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jsprit.core.algorithm.recreate.InsertionStrategy;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.InitialSolutionFactory;
|
||||
import jsprit.core.problem.solution.SolutionCostCalculator;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.Job;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.algo.SolutionCostCalculator;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,26 +14,26 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.algorithm.listener.AlgorithmStartsListener;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.util.CrowFlyCosts;
|
||||
import jsprit.core.util.EuclideanDistanceCalculator;
|
||||
import jsprit.core.util.Locations;
|
||||
import jsprit.core.util.NeighborhoodImpl;
|
||||
import jsprit.core.util.Solutions;
|
||||
|
||||
import org.apache.commons.math.stat.descriptive.moment.Mean;
|
||||
import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.CrowFlyCosts;
|
||||
import util.EuclideanDistanceCalculator;
|
||||
import util.Locations;
|
||||
import util.NeighborhoodImpl;
|
||||
import util.Solutions;
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.algo.AlgorithmStartsListener;
|
||||
import basics.algo.VehicleRoutingAlgorithmFactory;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
class NeighborhoodThresholdInitialiser implements AlgorithmStartsListener{
|
||||
|
||||
|
|
@ -14,22 +14,19 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionEndsListener;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
|
||||
import basics.algo.InsertionEndsListener;
|
||||
import basics.route.VehicleFleetManager;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
public class RemoveEmptyVehicles implements InsertionEndsListener{
|
||||
|
||||
private static Logger log = Logger.getLogger(RemoveEmptyVehicles.class);
|
||||
|
||||
private VehicleFleetManager fleetManager;
|
||||
|
||||
public RemoveEmptyVehicles(VehicleFleetManager fleetManager) {
|
||||
|
|
@ -14,25 +14,22 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionStartsListener;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
|
||||
import basics.Job;
|
||||
import basics.algo.InsertionStartsListener;
|
||||
import basics.route.VehicleFleetManager;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
class ResetAndIniFleetManager implements InsertionStartsListener{
|
||||
public class ResetAndIniFleetManager implements InsertionStartsListener{
|
||||
|
||||
private static Logger log = Logger.getLogger(ResetAndIniFleetManager.class);
|
||||
|
||||
private VehicleFleetManager vehicleFleetManager;
|
||||
|
||||
ResetAndIniFleetManager(VehicleFleetManager vehicleFleetManager) {
|
||||
public ResetAndIniFleetManager(VehicleFleetManager vehicleFleetManager) {
|
||||
super();
|
||||
this.vehicleFleetManager = vehicleFleetManager;
|
||||
}
|
||||
|
|
@ -42,12 +39,7 @@ class ResetAndIniFleetManager implements InsertionStartsListener{
|
|||
vehicleFleetManager.unlockAll();
|
||||
Collection<VehicleRoute> routes = new ArrayList<VehicleRoute>(vehicleRoutes);
|
||||
for(VehicleRoute route : routes){
|
||||
// if(route.isEmpty()){
|
||||
// vehicleRoutes.remove(route);
|
||||
// }
|
||||
// else{
|
||||
vehicleFleetManager.lock(route.getVehicle());
|
||||
// }
|
||||
vehicleFleetManager.lock(route.getVehicle());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -14,18 +14,21 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import jsprit.core.algorithm.acceptor.SolutionAcceptor;
|
||||
import jsprit.core.algorithm.listener.SearchStrategyModuleListener;
|
||||
import jsprit.core.algorithm.selector.SolutionSelector;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.SolutionCostCalculator;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import algorithms.acceptors.SolutionAcceptor;
|
||||
import algorithms.selectors.SolutionSelector;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,14 +14,17 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import util.RandomNumberGeneration;
|
||||
import jsprit.core.algorithm.listener.SearchStrategyListener;
|
||||
import jsprit.core.algorithm.listener.SearchStrategyModuleListener;
|
||||
import jsprit.core.util.RandomNumberGeneration;
|
||||
|
||||
|
||||
|
||||
public class SearchStrategyManager {
|
||||
|
|
@ -14,9 +14,10 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm;
|
||||
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.algorithm.listener.SearchStrategyModuleListener;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
|
||||
public interface SearchStrategyModule {
|
||||
|
|
@ -1,14 +1,16 @@
|
|||
package algorithms;
|
||||
package jsprit.core.algorithm;
|
||||
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.algo.SolutionCostCalculator;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.SolutionCostCalculator;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
public class VariablePlusFixedSolutionCostCalculatorFactory {
|
||||
|
||||
private StateManager stateManager;
|
||||
private RouteAndActivityStateGetter stateManager;
|
||||
|
||||
public VariablePlusFixedSolutionCostCalculatorFactory(StateManager stateManager) {
|
||||
public VariablePlusFixedSolutionCostCalculatorFactory(RouteAndActivityStateGetter stateManager) {
|
||||
super();
|
||||
this.stateManager = stateManager;
|
||||
}
|
||||
|
|
@ -14,26 +14,29 @@
|
|||
* 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 basics;
|
||||
package jsprit.core.algorithm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.algorithm.SearchStrategy.DiscoveredSolution;
|
||||
import jsprit.core.algorithm.acceptor.SolutionAcceptor;
|
||||
import jsprit.core.algorithm.listener.AlgorithmEndsListener;
|
||||
import jsprit.core.algorithm.listener.AlgorithmStartsListener;
|
||||
import jsprit.core.algorithm.listener.IterationEndsListener;
|
||||
import jsprit.core.algorithm.listener.IterationStartsListener;
|
||||
import jsprit.core.algorithm.listener.SearchStrategyListener;
|
||||
import jsprit.core.algorithm.listener.SearchStrategyModuleListener;
|
||||
import jsprit.core.algorithm.listener.StrategySelectedListener;
|
||||
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListener;
|
||||
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners;
|
||||
import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination;
|
||||
import jsprit.core.algorithm.termination.PrematureAlgorithmTermination;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.Counter;
|
||||
import algorithms.acceptors.SolutionAcceptor;
|
||||
import basics.algo.AlgorithmEndsListener;
|
||||
import basics.algo.AlgorithmStartsListener;
|
||||
import basics.algo.IterationEndsListener;
|
||||
import basics.algo.IterationStartsListener;
|
||||
import basics.algo.IterationWithoutImprovementBreaker;
|
||||
import basics.algo.PrematureAlgorithmBreaker;
|
||||
import basics.algo.SearchStrategy;
|
||||
import basics.algo.SearchStrategy.DiscoveredSolution;
|
||||
import basics.algo.SearchStrategyManager;
|
||||
import basics.algo.VehicleRoutingAlgorithmListener;
|
||||
import basics.algo.VehicleRoutingAlgorithmListeners;
|
||||
|
||||
/**
|
||||
* Algorithm that solves a {@link VehicleRoutingProblem}.
|
||||
|
|
@ -43,7 +46,36 @@ import basics.algo.VehicleRoutingAlgorithmListeners;
|
|||
*/
|
||||
public class VehicleRoutingAlgorithm {
|
||||
|
||||
|
||||
private static class Counter {
|
||||
private final String name;
|
||||
private long counter = 0;
|
||||
private long nextCounter = 1;
|
||||
private static final Logger log = Logger.getLogger(Counter.class);
|
||||
|
||||
public Counter(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void incCounter() {
|
||||
long i = counter++;
|
||||
long n = nextCounter;
|
||||
if (i >= n) {
|
||||
if (nextCounter==n) {
|
||||
nextCounter=n*2;
|
||||
log.info(this.name + n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void print() {
|
||||
log.info(this.name + counter);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
counter=0;
|
||||
nextCounter=1;
|
||||
}
|
||||
}
|
||||
|
||||
public static final int NOBREAK = Integer.MAX_VALUE;
|
||||
|
||||
|
|
@ -61,7 +93,7 @@ public class VehicleRoutingAlgorithm {
|
|||
|
||||
private Collection<VehicleRoutingProblemSolution> initialSolutions;
|
||||
|
||||
private PrematureAlgorithmBreaker prematureAlgorithmBreaker = new PrematureAlgorithmBreaker() {
|
||||
private PrematureAlgorithmTermination prematureAlgorithmTermination = new PrematureAlgorithmTermination() {
|
||||
|
||||
@Override
|
||||
public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) {
|
||||
|
|
@ -100,15 +132,16 @@ public class VehicleRoutingAlgorithm {
|
|||
* Improvement is what {@link SolutionAcceptor} understands about improvement. Or to put it in other words, the algo breaks prematurely after
|
||||
* the assigned number of iterations without solution-acceptance.
|
||||
*
|
||||
*
|
||||
* @deprecated use setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(int nuIterationsWithoutImprovement));
|
||||
* @param nuIterationsWithoutImprovement
|
||||
*/
|
||||
@Deprecated
|
||||
public void setPrematureBreak(int nuIterationsWithoutImprovement){
|
||||
prematureAlgorithmBreaker = new IterationWithoutImprovementBreaker(nuIterationsWithoutImprovement);
|
||||
prematureAlgorithmTermination = new IterationWithoutImprovementTermination(nuIterationsWithoutImprovement);
|
||||
}
|
||||
|
||||
public void setPrematureAlgorithmBreaker(PrematureAlgorithmBreaker prematureAlgorithmBreaker){
|
||||
this.prematureAlgorithmBreaker = prematureAlgorithmBreaker;
|
||||
public void setPrematureAlgorithmTermination(PrematureAlgorithmTermination prematureAlgorithmTermination){
|
||||
this.prematureAlgorithmTermination = prematureAlgorithmTermination;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -146,7 +179,7 @@ public class VehicleRoutingAlgorithm {
|
|||
SearchStrategy strategy = searchStrategyManager.getRandomStrategy();
|
||||
DiscoveredSolution discoveredSolution = strategy.run(problem, solutions);
|
||||
selectedStrategy(strategy.getName(),problem, solutions);
|
||||
if(prematureAlgorithmBreaker.isPrematureBreak(discoveredSolution)){
|
||||
if(prematureAlgorithmTermination.isPrematureBreak(discoveredSolution)){
|
||||
logger.info("premature break at iteration "+ (i+1));
|
||||
nuOfIterationsThisAlgoIsRunning = (i+1);
|
||||
break;
|
||||
|
|
@ -193,6 +226,12 @@ public class VehicleRoutingAlgorithm {
|
|||
public VehicleRoutingAlgorithmListeners getAlgorithmListeners() {
|
||||
return algoListeners;
|
||||
}
|
||||
|
||||
public void addListener(VehicleRoutingAlgorithmListener l){
|
||||
algoListeners.addListener(l);
|
||||
if(l instanceof SearchStrategyListener) searchStrategyManager.addSearchStrategyListener((SearchStrategyListener) l);
|
||||
if(l instanceof SearchStrategyModuleListener) searchStrategyManager.addSearchStrategyModuleListener((SearchStrategyModuleListener) l);
|
||||
}
|
||||
|
||||
private void iterationEnds(int i, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) {
|
||||
algoListeners.iterationEnds(i,problem, solutions);
|
||||
|
|
@ -14,10 +14,9 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm;
|
||||
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
|
||||
|
||||
public interface VehicleRoutingAlgorithmFactory {
|
||||
|
|
@ -14,11 +14,12 @@
|
|||
* 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 algorithms.acceptors;
|
||||
package jsprit.core.algorithm.acceptor;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
|
||||
|
||||
public class AcceptNewRemoveFirst implements SolutionAcceptor{
|
||||
|
|
@ -0,0 +1,158 @@
|
|||
/*******************************************************************************
|
||||
* 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 jsprit.core.algorithm.acceptor;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.io.AlgorithmConfig;
|
||||
import jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.algorithm.listener.AlgorithmStartsListener;
|
||||
import jsprit.core.algorithm.listener.IterationEndsListener;
|
||||
import jsprit.core.algorithm.listener.IterationStartsListener;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.util.Resource;
|
||||
import jsprit.core.util.Solutions;
|
||||
|
||||
import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
|
||||
|
||||
public class ExperimentalSchrimpfAcceptance implements SolutionAcceptor, IterationStartsListener, AlgorithmStartsListener{
|
||||
|
||||
private static Logger logger = Logger.getLogger(ExperimentalSchrimpfAcceptance.class);
|
||||
|
||||
private final double alpha;
|
||||
|
||||
private int nOfTotalIterations = 1000;
|
||||
|
||||
private int currentIteration = 0;
|
||||
|
||||
private double initialThreshold = 0.0;
|
||||
|
||||
private final int nOfRandomWalks;
|
||||
|
||||
private final int solutionMemory;
|
||||
|
||||
|
||||
public ExperimentalSchrimpfAcceptance(int solutionMemory, double alpha, int nOfWarmupIterations) {
|
||||
super();
|
||||
this.alpha = alpha;
|
||||
this.nOfRandomWalks = nOfWarmupIterations;
|
||||
this.solutionMemory = solutionMemory;
|
||||
logger.info("initialise " + this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean acceptSolution(Collection<VehicleRoutingProblemSolution> solutions, VehicleRoutingProblemSolution newSolution) {
|
||||
boolean solutionAccepted = false;
|
||||
if (solutions.size() < solutionMemory) {
|
||||
solutions.add(newSolution);
|
||||
solutionAccepted = true;
|
||||
} else {
|
||||
VehicleRoutingProblemSolution worst = null;
|
||||
double threshold = getThreshold(currentIteration);
|
||||
for(VehicleRoutingProblemSolution solutionInMemory : solutions){
|
||||
if(worst == null) worst = solutionInMemory;
|
||||
else if(solutionInMemory.getCost() > worst.getCost()) worst = solutionInMemory;
|
||||
}
|
||||
if(newSolution.getRoutes().size() < worst.getRoutes().size()){
|
||||
solutions.remove(worst);
|
||||
solutions.add(newSolution);
|
||||
solutionAccepted = true;
|
||||
}
|
||||
else if(newSolution.getRoutes().size() == worst.getRoutes().size() && newSolution.getCost() < worst.getCost() + threshold){
|
||||
solutions.remove(worst);
|
||||
solutions.add(newSolution);
|
||||
solutionAccepted = true;
|
||||
}
|
||||
}
|
||||
return solutionAccepted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[name=schrimpfAcceptanceFunction][alpha="+alpha+"][warmup=" + nOfRandomWalks + "]";
|
||||
}
|
||||
|
||||
private double getThreshold(int iteration) {
|
||||
double scheduleVariable = (double) iteration / (double) nOfTotalIterations;
|
||||
// logger.debug("iter="+iteration+" totalIter="+nOfTotalIterations+" scheduling="+scheduleVariable);
|
||||
double currentThreshold = initialThreshold * Math.exp(-Math.log(2) * scheduleVariable / alpha);
|
||||
return currentThreshold;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection<VehicleRoutingProblemSolution> solutions) {
|
||||
reset();
|
||||
logger.info("---------------------------------------------------------------------");
|
||||
logger.info("prepare schrimpfAcceptanceFunction, i.e. determine initial threshold");
|
||||
logger.info("start random-walk (see randomWalk.xml)");
|
||||
double now = System.currentTimeMillis();
|
||||
this.nOfTotalIterations = algorithm.getNuOfIterations();
|
||||
|
||||
/*
|
||||
* randomWalk to determine standardDev
|
||||
*/
|
||||
final double[] results = new double[nOfRandomWalks];
|
||||
|
||||
URL resource = Resource.getAsURL("randomWalk.xml");
|
||||
AlgorithmConfig algorithmConfig = new AlgorithmConfig();
|
||||
new AlgorithmConfigXmlReader(algorithmConfig).read(resource);
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig);
|
||||
vra.setNuOfIterations(nOfRandomWalks);
|
||||
vra.getAlgorithmListeners().addListener(new IterationEndsListener() {
|
||||
|
||||
@Override
|
||||
public void informIterationEnds(int iteration, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) {
|
||||
double result = Solutions.getBest(solutions).getCost();
|
||||
// logger.info("result="+result);
|
||||
results[iteration-1] = result;
|
||||
}
|
||||
|
||||
});
|
||||
vra.searchSolutions();
|
||||
|
||||
StandardDeviation dev = new StandardDeviation();
|
||||
double standardDeviation = dev.evaluate(results);
|
||||
initialThreshold = standardDeviation / 2;
|
||||
|
||||
logger.info("warmup done");
|
||||
logger.info("total time: " + ((System.currentTimeMillis()-now)/1000.0) + "s");
|
||||
logger.info("initial threshold: " + initialThreshold);
|
||||
logger.info("---------------------------------------------------------------------");
|
||||
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
currentIteration = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) {
|
||||
currentIteration = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -14,18 +14,19 @@
|
|||
* 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 algorithms.acceptors;
|
||||
package jsprit.core.algorithm.acceptor;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
|
||||
public class AcceptNewIfBetterThanWorst implements SolutionAcceptor{
|
||||
|
||||
public class GreedyAcceptance implements SolutionAcceptor{
|
||||
|
||||
private final int solutionMemory;
|
||||
|
||||
public AcceptNewIfBetterThanWorst(int solutionMemory){
|
||||
public GreedyAcceptance(int solutionMemory){
|
||||
this.solutionMemory = solutionMemory;
|
||||
}
|
||||
|
||||
|
|
@ -47,6 +48,12 @@ public class AcceptNewIfBetterThanWorst implements SolutionAcceptor{
|
|||
if (worstSolution == null) worstSolution = s;
|
||||
else if (s.getCost() > worstSolution.getCost()) worstSolution = s;
|
||||
}
|
||||
// if(newSolution.getRoutes().size() < worstSolution.getRoutes().size()){
|
||||
// solutions.remove(worstSolution);
|
||||
// solutions.add(newSolution);
|
||||
// solutionAccepted = true;
|
||||
// }
|
||||
// else
|
||||
if(newSolution.getCost() < worstSolution.getCost()){
|
||||
solutions.remove(worstSolution);
|
||||
solutions.add(newSolution);
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/*******************************************************************************
|
||||
* 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 jsprit.core.algorithm.acceptor;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
|
||||
|
||||
public class GreedyAcceptance_minVehFirst implements SolutionAcceptor{
|
||||
|
||||
private final int solutionMemory;
|
||||
|
||||
public GreedyAcceptance_minVehFirst(int solutionMemory){
|
||||
this.solutionMemory = solutionMemory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts every solution if solution memory allows. If memory occupied, than accepts new solution only if better than the worst in memory.
|
||||
* Consequently, the worst solution is removed from solutions, and the new solution added.
|
||||
*
|
||||
* <p>Note that this modifies Collection<VehicleRoutingProblemSolution> solutions.
|
||||
*/
|
||||
@Override
|
||||
public boolean acceptSolution(Collection<VehicleRoutingProblemSolution> solutions, VehicleRoutingProblemSolution newSolution) {
|
||||
boolean solutionAccepted = false;
|
||||
if (solutions.size() < solutionMemory) {
|
||||
solutions.add(newSolution);
|
||||
solutionAccepted = true;
|
||||
} else {
|
||||
VehicleRoutingProblemSolution worstSolution = null;
|
||||
for (VehicleRoutingProblemSolution s : solutions) {
|
||||
if (worstSolution == null) worstSolution = s;
|
||||
else if (s.getRoutes().size() > worstSolution.getRoutes().size()) worstSolution = s;
|
||||
}
|
||||
if(newSolution.getRoutes().size() < worstSolution.getRoutes().size()){
|
||||
solutions.remove(worstSolution);
|
||||
solutions.add(newSolution);
|
||||
solutionAccepted = true;
|
||||
}
|
||||
else if(newSolution.getRoutes().size() == worstSolution.getRoutes().size() && newSolution.getCost() < worstSolution.getCost()){
|
||||
solutions.remove(worstSolution);
|
||||
solutions.add(newSolution);
|
||||
solutionAccepted = true;
|
||||
}
|
||||
}
|
||||
return solutionAccepted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[name=greedyAcceptance_minVehFirst]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -14,25 +14,26 @@
|
|||
* 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 algorithms.acceptors;
|
||||
package jsprit.core.algorithm.acceptor;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.io.AlgorithmConfig;
|
||||
import jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.algorithm.listener.AlgorithmStartsListener;
|
||||
import jsprit.core.algorithm.listener.IterationEndsListener;
|
||||
import jsprit.core.algorithm.listener.IterationStartsListener;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.util.Resource;
|
||||
import jsprit.core.util.Solutions;
|
||||
|
||||
import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.Resource;
|
||||
import util.Solutions;
|
||||
import algorithms.VehicleRoutingAlgorithms;
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.algo.AlgorithmStartsListener;
|
||||
import basics.algo.IterationEndsListener;
|
||||
import basics.algo.IterationStartsListener;
|
||||
import basics.io.AlgorithmConfig;
|
||||
import basics.io.AlgorithmConfigXmlReader;
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,11 +14,12 @@
|
|||
* 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 algorithms.acceptors;
|
||||
package jsprit.core.algorithm.acceptor;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
|
||||
/**
|
||||
* Acceptor that decides whether the newSolution is accepted or not.
|
||||
|
|
@ -14,15 +14,17 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.box;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import util.Resource;
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.io.AlgorithmConfig;
|
||||
import basics.io.AlgorithmConfigXmlReader;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.io.AlgorithmConfig;
|
||||
import jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.util.Resource;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -14,15 +14,17 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.box;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import util.Resource;
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.io.AlgorithmConfig;
|
||||
import basics.io.AlgorithmConfigXmlReader;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.io.AlgorithmConfig;
|
||||
import jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.util.Resource;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* 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 basics.io;
|
||||
package jsprit.core.algorithm.io;
|
||||
|
||||
import org.apache.commons.configuration.XMLConfiguration;
|
||||
|
||||
|
|
@ -14,19 +14,20 @@
|
|||
* 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 basics.io;
|
||||
package jsprit.core.algorithm.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
import jsprit.core.util.Resource;
|
||||
|
||||
import org.apache.commons.configuration.ConfigurationException;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import util.Resource;
|
||||
|
||||
public class AlgorithmConfigXmlReader {
|
||||
|
||||
|
|
@ -14,19 +14,24 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.io;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
|
||||
import jsprit.core.algorithm.recreate.BestInsertionBuilder;
|
||||
import jsprit.core.algorithm.recreate.InsertionStrategy;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListener;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
|
||||
import org.apache.commons.configuration.HierarchicalConfiguration;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.algo.InsertionListener;
|
||||
import basics.algo.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
|
||||
import basics.route.VehicleFleetManager;
|
||||
|
||||
class InsertionFactory {
|
||||
|
||||
|
|
@ -44,16 +49,17 @@ class InsertionFactory {
|
|||
List<InsertionListener> insertionListeners = new ArrayList<InsertionListener>();
|
||||
List<PrioritizedVRAListener> algoListeners = new ArrayList<PrioritizedVRAListener>();
|
||||
|
||||
CalculatorBuilder calcBuilder = new CalculatorBuilder(insertionListeners, algorithmListeners);
|
||||
calcBuilder.setStates(routeStates);
|
||||
calcBuilder.setVehicleRoutingProblem(vrp);
|
||||
calcBuilder.setVehicleFleetManager(vehicleFleetManager);
|
||||
calcBuilder.setConstraintManager(constraintManager);
|
||||
BestInsertionBuilder iBuilder = new BestInsertionBuilder(vrp, vehicleFleetManager, routeStates, constraintManager);
|
||||
|
||||
if(executorService != null){
|
||||
iBuilder.setConcurrentMode(executorService, nuOfThreads);
|
||||
}
|
||||
|
||||
if(config.containsKey("level")){
|
||||
String level = config.getString("level");
|
||||
if(level.equals("local")){
|
||||
calcBuilder.setLocalLevel();
|
||||
iBuilder.setLocalLevel();
|
||||
// calcBuilder.setLocalLevel();
|
||||
}
|
||||
else if(level.equals("route")){
|
||||
int forwardLooking = 0;
|
||||
|
|
@ -64,11 +70,12 @@ class InsertionFactory {
|
|||
else log.warn("parameter route[@forwardLooking] is missing. by default it is 0 which equals to local level");
|
||||
if(mem != null) memory = Integer.parseInt(mem);
|
||||
else log.warn("parameter route[@memory] is missing. by default it is 1");
|
||||
calcBuilder.setRouteLevel(forwardLooking, memory);
|
||||
iBuilder.setRouteLevel(forwardLooking, memory);
|
||||
// calcBuilder.setRouteLevel(forwardLooking, memory);
|
||||
}
|
||||
else throw new IllegalStateException("level " + level + " is not known. currently it only knows \"local\" or \"route\"");
|
||||
}
|
||||
else calcBuilder.setLocalLevel();
|
||||
else iBuilder.setLocalLevel();
|
||||
|
||||
if(config.containsKey("considerFixedCosts") || config.containsKey("considerFixedCost")){
|
||||
String val = config.getString("considerFixedCosts");
|
||||
|
|
@ -79,21 +86,19 @@ class InsertionFactory {
|
|||
if(weight == null) weight = config.getString("considerFixedCost[@weight]");
|
||||
if(weight != null) fixedCostWeight = Double.parseDouble(weight);
|
||||
else log.warn("parameter considerFixedCosts[@weight] is missing. by default, it is 0.5.");
|
||||
calcBuilder.considerFixedCosts(fixedCostWeight);
|
||||
iBuilder.considerFixedCosts(fixedCostWeight);
|
||||
}
|
||||
}
|
||||
String timeSliceString = config.getString("experimental[@timeSlice]");
|
||||
String neighbors = config.getString("experimental[@neighboringSlices]");
|
||||
if(timeSliceString != null && neighbors != null){
|
||||
calcBuilder.experimentalTimeScheduler(Double.parseDouble(timeSliceString),Integer.parseInt(neighbors));
|
||||
iBuilder.experimentalTimeScheduler(Double.parseDouble(timeSliceString),Integer.parseInt(neighbors));
|
||||
}
|
||||
|
||||
JobInsertionCostsCalculator jic = calcBuilder.build();
|
||||
|
||||
|
||||
if(insertionName.equals("bestInsertion")){
|
||||
insertionStrategy = new BestInsertion(jic);
|
||||
insertionStrategy = iBuilder.build();
|
||||
}
|
||||
else throw new IllegalStateException("currently only 'bestInsertion' is supported");
|
||||
for(InsertionListener l : insertionListeners) insertionStrategy.addListener(l);
|
||||
|
||||
algorithmListeners.addAll(algoListeners);
|
||||
|
|
@ -14,9 +14,10 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.io;
|
||||
|
||||
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
|
@ -26,48 +27,68 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import jsprit.core.algorithm.InsertionInitialSolutionFactory;
|
||||
import jsprit.core.algorithm.RemoveEmptyVehicles;
|
||||
import jsprit.core.algorithm.ResetAndIniFleetManager;
|
||||
import jsprit.core.algorithm.SearchStrategy;
|
||||
import jsprit.core.algorithm.SearchStrategy.DiscoveredSolution;
|
||||
import jsprit.core.algorithm.SearchStrategyManager;
|
||||
import jsprit.core.algorithm.SearchStrategyModule;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.acceptor.AcceptNewRemoveFirst;
|
||||
import jsprit.core.algorithm.acceptor.ExperimentalSchrimpfAcceptance;
|
||||
import jsprit.core.algorithm.acceptor.GreedyAcceptance;
|
||||
import jsprit.core.algorithm.acceptor.GreedyAcceptance_minVehFirst;
|
||||
import jsprit.core.algorithm.acceptor.SchrimpfAcceptance;
|
||||
import jsprit.core.algorithm.acceptor.SolutionAcceptor;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap.AbstractKey;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap.AcceptorKey;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap.InsertionStrategyKey;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap.RuinStrategyKey;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap.SelectorKey;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap.StrategyModuleKey;
|
||||
import jsprit.core.algorithm.listener.AlgorithmEndsListener;
|
||||
import jsprit.core.algorithm.listener.AlgorithmStartsListener;
|
||||
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
|
||||
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.Priority;
|
||||
import jsprit.core.algorithm.module.RuinAndRecreateModule;
|
||||
import jsprit.core.algorithm.recreate.InsertionStrategy;
|
||||
import jsprit.core.algorithm.recreate.VehicleSwitched;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListener;
|
||||
import jsprit.core.algorithm.ruin.RadialRuinStrategyFactory;
|
||||
import jsprit.core.algorithm.ruin.RandomRuinStrategyFactory;
|
||||
import jsprit.core.algorithm.ruin.RuinStrategy;
|
||||
import jsprit.core.algorithm.ruin.distance.AvgServiceAndShipmentDistance;
|
||||
import jsprit.core.algorithm.ruin.distance.JobDistance;
|
||||
import jsprit.core.algorithm.selector.SelectBest;
|
||||
import jsprit.core.algorithm.selector.SelectRandomly;
|
||||
import jsprit.core.algorithm.selector.SolutionSelector;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.algorithm.state.UpdateActivityTimes;
|
||||
import jsprit.core.algorithm.state.UpdateVariableCosts;
|
||||
import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination;
|
||||
import jsprit.core.algorithm.termination.PrematureAlgorithmTermination;
|
||||
import jsprit.core.algorithm.termination.TimeTermination;
|
||||
import jsprit.core.algorithm.termination.VariationCoefficientTermination;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.solution.SolutionCostCalculator;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.FiniteFleetManagerFactory;
|
||||
import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
import jsprit.core.util.SolutionVerifier;
|
||||
|
||||
import org.apache.commons.configuration.HierarchicalConfiguration;
|
||||
import org.apache.commons.configuration.XMLConfiguration;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import algorithms.VehicleRoutingAlgorithms.TypedMap.AbstractKey;
|
||||
import algorithms.VehicleRoutingAlgorithms.TypedMap.AcceptorKey;
|
||||
import algorithms.VehicleRoutingAlgorithms.TypedMap.InsertionStrategyKey;
|
||||
import algorithms.VehicleRoutingAlgorithms.TypedMap.RuinStrategyKey;
|
||||
import algorithms.VehicleRoutingAlgorithms.TypedMap.SelectorKey;
|
||||
import algorithms.VehicleRoutingAlgorithms.TypedMap.StrategyModuleKey;
|
||||
import algorithms.acceptors.AcceptNewIfBetterThanWorst;
|
||||
import algorithms.acceptors.AcceptNewRemoveFirst;
|
||||
import algorithms.acceptors.SchrimpfAcceptance;
|
||||
import algorithms.acceptors.SolutionAcceptor;
|
||||
import algorithms.selectors.SelectBest;
|
||||
import algorithms.selectors.SelectRandomly;
|
||||
import algorithms.selectors.SolutionSelector;
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblem.FleetSize;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.algo.AlgorithmStartsListener;
|
||||
import basics.algo.InsertionListener;
|
||||
import basics.algo.IterationWithoutImprovementBreaker;
|
||||
import basics.algo.PrematureAlgorithmBreaker;
|
||||
import basics.algo.SearchStrategy;
|
||||
import basics.algo.SearchStrategy.DiscoveredSolution;
|
||||
import basics.algo.SearchStrategyManager;
|
||||
import basics.algo.SearchStrategyModule;
|
||||
import basics.algo.SolutionCostCalculator;
|
||||
import basics.algo.TimeBreaker;
|
||||
import basics.algo.VariationCoefficientBreaker;
|
||||
import basics.algo.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
|
||||
import basics.algo.VehicleRoutingAlgorithmListeners.Priority;
|
||||
import basics.io.AlgorithmConfig;
|
||||
import basics.io.AlgorithmConfigXmlReader;
|
||||
import basics.route.FiniteFleetManagerFactory;
|
||||
import basics.route.InfiniteFleetManagerFactory;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleFleetManager;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
|
|
@ -371,12 +392,12 @@ public class VehicleRoutingAlgorithms {
|
|||
* @return {@link VehicleRoutingAlgorithm}
|
||||
*/
|
||||
public static VehicleRoutingAlgorithm createAlgorithm(final VehicleRoutingProblem vrp, final AlgorithmConfig algorithmConfig){
|
||||
return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),null,0);
|
||||
return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),0);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, final XMLConfiguration config){
|
||||
return createAlgo(vrp,config,null,0);
|
||||
return createAlgo(vrp,config,0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -390,7 +411,7 @@ public class VehicleRoutingAlgorithms {
|
|||
AlgorithmConfig algorithmConfig = new AlgorithmConfig();
|
||||
AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig);
|
||||
xmlReader.read(configURL);
|
||||
return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),null,0);
|
||||
return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -404,26 +425,18 @@ public class VehicleRoutingAlgorithms {
|
|||
AlgorithmConfig algorithmConfig = new AlgorithmConfig();
|
||||
AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig);
|
||||
xmlReader.read(configFileName);
|
||||
return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),null, 0);
|
||||
return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and creates {@link VehicleRoutingAlgorithm} from config-file.
|
||||
*
|
||||
* @param vrp
|
||||
* @param configFileName
|
||||
* @param nuOfThreads TODO
|
||||
* @param {@link ExecutorService}
|
||||
* @return {@link VehicleRoutingAlgorithm}
|
||||
*/
|
||||
private static VehicleRoutingAlgorithm readAndCreateConcurrentAlgorithm(final VehicleRoutingProblem vrp, final String configFileName, final ExecutorService executorService, int nuOfThreads){
|
||||
public static VehicleRoutingAlgorithm readAndCreateAlgorithm(VehicleRoutingProblem vrp, int nThreads, String configFileName) {
|
||||
AlgorithmConfig algorithmConfig = new AlgorithmConfig();
|
||||
AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig);
|
||||
xmlReader.read(configFileName);
|
||||
return createAlgo(vrp,algorithmConfig.getXMLConfiguration(), executorService, nuOfThreads);
|
||||
return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),nThreads);
|
||||
}
|
||||
|
||||
private static VehicleRoutingAlgorithm createAlgo(final VehicleRoutingProblem vrp, XMLConfiguration config, ExecutorService executorService, int nuOfThreads){
|
||||
private static VehicleRoutingAlgorithm createAlgo(final VehicleRoutingProblem vrp, XMLConfiguration config, int nuOfThreads){
|
||||
|
||||
|
||||
// map to store constructed modules
|
||||
TypedMap definedClasses = new TypedMap();
|
||||
|
|
@ -434,11 +447,46 @@ public class VehicleRoutingAlgorithms {
|
|||
// insertion listeners
|
||||
List<InsertionListener> insertionListeners = new ArrayList<InsertionListener>();
|
||||
|
||||
//threading
|
||||
final ExecutorService executorService;
|
||||
if(nuOfThreads > 0){
|
||||
log.info("setup executor-service with " + nuOfThreads + " threads");
|
||||
executorService = Executors.newFixedThreadPool(nuOfThreads);
|
||||
algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, new AlgorithmEndsListener() {
|
||||
|
||||
@Override
|
||||
public void informAlgorithmEnds(VehicleRoutingProblem problem,Collection<VehicleRoutingProblemSolution> solutions) {
|
||||
log.info("shutdown executor-service");
|
||||
executorService.shutdown();
|
||||
}
|
||||
}));
|
||||
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
|
||||
|
||||
@Override
|
||||
public void uncaughtException(Thread arg0, Throwable arg1) {
|
||||
System.err.println(arg1.toString());
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(){
|
||||
public void run(){
|
||||
if(!executorService.isShutdown()){
|
||||
System.err.println("shutdowHook shuts down executorService");
|
||||
executorService.shutdown();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else executorService = null;
|
||||
|
||||
|
||||
//create fleetmanager
|
||||
final VehicleFleetManager vehicleFleetManager = createFleetManager(vrp);
|
||||
|
||||
//create state-manager
|
||||
final StateManager stateManager = new StateManager();
|
||||
final StateManager stateManager = new StateManager(vrp);
|
||||
stateManager.updateLoadStates();
|
||||
stateManager.updateTimeWindowStates();
|
||||
|
||||
/*
|
||||
* define constraints
|
||||
|
|
@ -486,8 +534,8 @@ public class VehicleRoutingAlgorithms {
|
|||
// UpdateLoads loadUpdater = new UpdateLoads(stateManager);
|
||||
// stateManager.addListener(loadUpdater);
|
||||
// stateManager.addActivityVisitor(loadUpdater);
|
||||
stateManager.addActivityVisitor(new UpdateActivityTimes(vrp.getTransportCosts()));
|
||||
stateManager.addActivityVisitor(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
|
||||
stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts()));
|
||||
stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
|
||||
|
||||
// stateManager.addActivityVisitor(new UpdateOccuredDeliveries(stateManager));
|
||||
// stateManager.addActivityVisitor(new TimeWindowUpdater(stateManager, vrp.getTransportCosts()));
|
||||
|
|
@ -501,8 +549,8 @@ public class VehicleRoutingAlgorithms {
|
|||
metaAlgorithm.getSearchStrategyManager().addSearchStrategyModuleListener(new VehicleSwitched(vehicleFleetManager));
|
||||
|
||||
//define prematureBreak
|
||||
PrematureAlgorithmBreaker prematureAlgoBreaker = getPrematureBreaker(config,algorithmListeners);
|
||||
metaAlgorithm.setPrematureAlgorithmBreaker(prematureAlgoBreaker);
|
||||
PrematureAlgorithmTermination prematureAlgoBreaker = getPrematureBreaker(config,algorithmListeners);
|
||||
metaAlgorithm.setPrematureAlgorithmTermination(prematureAlgoBreaker);
|
||||
|
||||
//misc
|
||||
algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, new SolutionVerifier()));
|
||||
|
|
@ -546,11 +594,11 @@ public class VehicleRoutingAlgorithms {
|
|||
"makes sure your config file contains one of these options");
|
||||
}
|
||||
|
||||
private static PrematureAlgorithmBreaker getPrematureBreaker(XMLConfiguration config, Set<PrioritizedVRAListener> algorithmListeners) {
|
||||
private static PrematureAlgorithmTermination getPrematureBreaker(XMLConfiguration config, Set<PrioritizedVRAListener> algorithmListeners) {
|
||||
String basedOn = config.getString("prematureBreak[@basedOn]");
|
||||
if(basedOn == null){
|
||||
log.info("set default prematureBreak, i.e. no premature break at all.");
|
||||
return new PrematureAlgorithmBreaker() {
|
||||
return new PrematureAlgorithmTermination() {
|
||||
|
||||
@Override
|
||||
public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) {
|
||||
|
|
@ -563,14 +611,14 @@ public class VehicleRoutingAlgorithms {
|
|||
String iter = config.getString("prematureBreak.iterations");
|
||||
if(iter == null) throw new IllegalStateException("prematureBreak.iterations is missing");
|
||||
int iterations = Integer.valueOf(iter);
|
||||
return new IterationWithoutImprovementBreaker(iterations);
|
||||
return new IterationWithoutImprovementTermination(iterations);
|
||||
}
|
||||
if(basedOn.equals("time")){
|
||||
log.info("set prematureBreak based on time");
|
||||
String timeString = config.getString("prematureBreak.time");
|
||||
if(timeString == null) throw new IllegalStateException("prematureBreak.time is missing");
|
||||
double time = Double.valueOf(timeString);
|
||||
TimeBreaker timeBreaker = new TimeBreaker(time);
|
||||
TimeTermination timeBreaker = new TimeTermination(time);
|
||||
algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, timeBreaker));
|
||||
return timeBreaker;
|
||||
}
|
||||
|
|
@ -582,7 +630,7 @@ public class VehicleRoutingAlgorithms {
|
|||
if(iterationsString == null) throw new IllegalStateException("prematureBreak.iterations is missing");
|
||||
double threshold = Double.valueOf(thresholdString);
|
||||
int iterations = Integer.valueOf(iterationsString);
|
||||
VariationCoefficientBreaker variationCoefficientBreaker = new VariationCoefficientBreaker(iterations, threshold);
|
||||
VariationCoefficientTermination variationCoefficientBreaker = new VariationCoefficientTermination(iterations, threshold);
|
||||
algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, variationCoefficientBreaker));
|
||||
return variationCoefficientBreaker;
|
||||
}
|
||||
|
|
@ -687,7 +735,7 @@ public class VehicleRoutingAlgorithms {
|
|||
SolutionAcceptor definedAcceptor = typedMap.get(acceptorKey);
|
||||
if(definedAcceptor != null) return definedAcceptor;
|
||||
if(acceptorName.equals("acceptNewRemoveWorst")){
|
||||
AcceptNewIfBetterThanWorst acceptor = new AcceptNewIfBetterThanWorst(solutionMemory);
|
||||
GreedyAcceptance acceptor = new GreedyAcceptance(solutionMemory);
|
||||
typedMap.put(acceptorKey, acceptor);
|
||||
return acceptor;
|
||||
}
|
||||
|
|
@ -696,6 +744,16 @@ public class VehicleRoutingAlgorithms {
|
|||
typedMap.put(acceptorKey, acceptor);
|
||||
return acceptor;
|
||||
}
|
||||
if(acceptorName.equals("greedyAcceptance")){
|
||||
GreedyAcceptance acceptor = new GreedyAcceptance(solutionMemory);
|
||||
typedMap.put(acceptorKey, acceptor);
|
||||
return acceptor;
|
||||
}
|
||||
if(acceptorName.equals("greedyAcceptance_minVehFirst")){
|
||||
GreedyAcceptance_minVehFirst acceptor = new GreedyAcceptance_minVehFirst(solutionMemory);
|
||||
typedMap.put(acceptorKey, acceptor);
|
||||
return acceptor;
|
||||
}
|
||||
if(acceptorName.equals("schrimpfAcceptance")){
|
||||
int iterOfSchrimpf = strategyConfig.getInt("acceptor.warmup");
|
||||
double alpha = strategyConfig.getDouble("acceptor.alpha");
|
||||
|
|
@ -704,6 +762,14 @@ public class VehicleRoutingAlgorithms {
|
|||
typedMap.put(acceptorKey, schrimpf);
|
||||
return schrimpf;
|
||||
}
|
||||
if(acceptorName.equals("experimentalSchrimpfAcceptance")){
|
||||
int iterOfSchrimpf = strategyConfig.getInt("acceptor.warmup");
|
||||
double alpha = strategyConfig.getDouble("acceptor.alpha");
|
||||
ExperimentalSchrimpfAcceptance schrimpf = new ExperimentalSchrimpfAcceptance(solutionMemory, alpha, iterOfSchrimpf);
|
||||
algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, schrimpf));
|
||||
typedMap.put(acceptorKey, schrimpf);
|
||||
return schrimpf;
|
||||
}
|
||||
else{
|
||||
throw new IllegalStateException("solution acceptor " + acceptorName + " is not known");
|
||||
}
|
||||
|
|
@ -735,7 +801,7 @@ public class VehicleRoutingAlgorithms {
|
|||
}
|
||||
else if(ruin_name.equals("radialRuin")){
|
||||
String ruin_distance = moduleConfig.getString("ruin.distance");
|
||||
JobDistance jobDistance = new AvgJobDistance(vrp.getTransportCosts());
|
||||
JobDistance jobDistance = new AvgServiceAndShipmentDistance(vrp.getTransportCosts());
|
||||
// if(ruin_distance == null) jobDistance
|
||||
// else {
|
||||
// if(ruin_distance.equals("euclidean")){
|
||||
|
|
@ -768,39 +834,40 @@ public class VehicleRoutingAlgorithms {
|
|||
return rrModule;
|
||||
}
|
||||
if(moduleName.equals("gendreau")){
|
||||
int iterations = moduleConfig.getInt("iterations");
|
||||
double share = moduleConfig.getDouble("share");
|
||||
String ruinName = moduleConfig.getString("ruin[@name]");
|
||||
if(ruinName == null) throw new IllegalStateException("gendreau.ruin[@name] is missing. set it to \"radialRuin\" or \"randomRuin\"");
|
||||
String ruinId = moduleConfig.getString("ruin[@id]");
|
||||
if(ruinId == null) ruinId = "noId";
|
||||
ModKey ruinKey = makeKey(ruinName,ruinId);
|
||||
RuinStrategyKey stratKey = new RuinStrategyKey(ruinKey);
|
||||
RuinStrategy ruin = definedClasses.get(stratKey);
|
||||
if(ruin == null){
|
||||
ruin = new RuinRadial(vrp, 0.3, new AvgJobDistance(vrp.getTransportCosts()));
|
||||
definedClasses.put(stratKey, ruin);
|
||||
}
|
||||
|
||||
String insertionName = moduleConfig.getString("insertion[@name]");
|
||||
if(insertionName == null) throw new IllegalStateException("gendreau.insertion[@name] is missing. set it to \"regretInsertion\" or \"bestInsertion\"");
|
||||
String insertionId = moduleConfig.getString("insertion[@id]");
|
||||
if(insertionId == null) insertionId = "noId";
|
||||
ModKey insertionKey = makeKey(insertionName,insertionId);
|
||||
InsertionStrategyKey insertionStrategyKey = new InsertionStrategyKey(insertionKey);
|
||||
InsertionStrategy insertion = definedClasses.get(insertionStrategyKey);
|
||||
if(insertion == null){
|
||||
List<HierarchicalConfiguration> insertionConfigs = moduleConfig.configurationsAt("insertion");
|
||||
if(insertionConfigs.size() != 1) throw new IllegalStateException("this should be 1");
|
||||
List<PrioritizedVRAListener> prioListeners = new ArrayList<PrioritizedVRAListener>();
|
||||
insertion = createInsertionStrategy(insertionConfigs.get(0), vrp, vehicleFleetManager, routeStates, prioListeners, executorService, nuOfThreads, constraintManager);
|
||||
algorithmListeners.addAll(prioListeners);
|
||||
}
|
||||
Gendreau gendreau = new Gendreau(vrp, ruin, insertion, vehicleFleetManager);
|
||||
gendreau.setShareOfJobsToRuin(share);
|
||||
gendreau.setNuOfIterations(iterations);
|
||||
definedClasses.put(strategyModuleKey, gendreau);
|
||||
return gendreau;
|
||||
throw new UnsupportedOperationException("gendreau is not supported yet");
|
||||
// int iterations = moduleConfig.getInt("iterations");
|
||||
// double share = moduleConfig.getDouble("share");
|
||||
// String ruinName = moduleConfig.getString("ruin[@name]");
|
||||
// if(ruinName == null) throw new IllegalStateException("gendreau.ruin[@name] is missing. set it to \"radialRuin\" or \"randomRuin\"");
|
||||
// String ruinId = moduleConfig.getString("ruin[@id]");
|
||||
// if(ruinId == null) ruinId = "noId";
|
||||
// ModKey ruinKey = makeKey(ruinName,ruinId);
|
||||
// RuinStrategyKey stratKey = new RuinStrategyKey(ruinKey);
|
||||
// RuinStrategy ruin = definedClasses.get(stratKey);
|
||||
// if(ruin == null){
|
||||
// ruin = new RadialRuinStrategyFactory(0.3, new AvgJobDistance(vrp.getTransportCosts())).createStrategy(vrp);
|
||||
// definedClasses.put(stratKey, ruin);
|
||||
// }
|
||||
//
|
||||
// String insertionName = moduleConfig.getString("insertion[@name]");
|
||||
// if(insertionName == null) throw new IllegalStateException("gendreau.insertion[@name] is missing. set it to \"regretInsertion\" or \"bestInsertion\"");
|
||||
// String insertionId = moduleConfig.getString("insertion[@id]");
|
||||
// if(insertionId == null) insertionId = "noId";
|
||||
// ModKey insertionKey = makeKey(insertionName,insertionId);
|
||||
// InsertionStrategyKey insertionStrategyKey = new InsertionStrategyKey(insertionKey);
|
||||
// InsertionStrategy insertion = definedClasses.get(insertionStrategyKey);
|
||||
// if(insertion == null){
|
||||
// List<HierarchicalConfiguration> insertionConfigs = moduleConfig.configurationsAt("insertion");
|
||||
// if(insertionConfigs.size() != 1) throw new IllegalStateException("this should be 1");
|
||||
// List<PrioritizedVRAListener> prioListeners = new ArrayList<PrioritizedVRAListener>();
|
||||
// insertion = createInsertionStrategy(insertionConfigs.get(0), vrp, vehicleFleetManager, routeStates, prioListeners, executorService, nuOfThreads, constraintManager);
|
||||
// algorithmListeners.addAll(prioListeners);
|
||||
// }
|
||||
// Gendreau gendreau = new Gendreau(vrp, ruin, insertion, vehicleFleetManager);
|
||||
// gendreau.setShareOfJobsToRuin(share);
|
||||
// gendreau.setNuOfIterations(iterations);
|
||||
// definedClasses.put(strategyModuleKey, gendreau);
|
||||
// return gendreau;
|
||||
}
|
||||
throw new NullPointerException("no module found with moduleName=" + moduleName +
|
||||
"\n\tcheck config whether the correct names are used" +
|
||||
|
|
@ -815,7 +882,7 @@ public class VehicleRoutingAlgorithms {
|
|||
RuinStrategyKey stratKey = new RuinStrategyKey(modKey);
|
||||
RuinStrategy ruin = definedClasses.get(stratKey);
|
||||
if(ruin == null){
|
||||
ruin = new RuinRadial(vrp, shareToRuin, jobDistance);
|
||||
ruin = new RadialRuinStrategyFactory(shareToRuin, jobDistance).createStrategy(vrp);
|
||||
definedClasses.put(stratKey, ruin);
|
||||
}
|
||||
return ruin;
|
||||
|
|
@ -825,7 +892,7 @@ public class VehicleRoutingAlgorithms {
|
|||
RuinStrategyKey stratKey = new RuinStrategyKey(modKey);
|
||||
RuinStrategy ruin = definedClasses.get(stratKey);
|
||||
if(ruin == null){
|
||||
ruin = new RuinRandom(vrp, shareToRuin);
|
||||
ruin = new RandomRuinStrategyFactory(shareToRuin).createStrategy(vrp);
|
||||
definedClasses.put(stratKey, ruin);
|
||||
}
|
||||
return ruin;
|
||||
|
|
@ -14,12 +14,13 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm.listener;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,13 +14,14 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm.listener;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,12 +14,13 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm.listener;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,12 +14,13 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm.listener;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm.listener;
|
||||
|
||||
public interface SearchStrategyListener extends VehicleRoutingAlgorithmListener{
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm.listener;
|
||||
|
||||
public interface SearchStrategyModuleListener extends VehicleRoutingAlgorithmListener{
|
||||
|
||||
|
|
@ -14,12 +14,13 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm.listener;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm.listener;
|
||||
|
||||
public interface VehicleRoutingAlgorithmListener {
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
|
@ -23,9 +23,10 @@ import java.util.Comparator;
|
|||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,224 @@
|
|||
///*******************************************************************************
|
||||
// * 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 jsprit.core.algorithm.module;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Arrays;
|
||||
//import java.util.Collection;
|
||||
//import java.util.Collections;
|
||||
//import java.util.HashSet;
|
||||
//import java.util.List;
|
||||
//import java.util.Random;
|
||||
//import java.util.Set;
|
||||
//
|
||||
//import jsprit.core.algorithm.SearchStrategyModule;
|
||||
//import jsprit.core.algorithm.listener.SearchStrategyModuleListener;
|
||||
//import jsprit.core.algorithm.recreate.InsertionStrategy;
|
||||
//import jsprit.core.algorithm.recreate.listener.InsertionListener;
|
||||
//import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
//import jsprit.core.algorithm.ruin.RuinStrategy;
|
||||
//import jsprit.core.algorithm.ruin.listener.RuinListener;
|
||||
//import jsprit.core.problem.Job;
|
||||
//import jsprit.core.problem.VehicleRoutingProblem;
|
||||
//import jsprit.core.problem.VehicleRoutingProblemSolution;
|
||||
//import jsprit.core.problem.route.TourActivity;
|
||||
//import jsprit.core.problem.route.TourActivity.JobActivity;
|
||||
//import jsprit.core.problem.route.VehicleFleetManager;
|
||||
//import jsprit.core.problem.route.VehicleRoute;
|
||||
//import jsprit.core.util.RandomNumberGeneration;
|
||||
//
|
||||
//import org.apache.log4j.Logger;
|
||||
//
|
||||
//
|
||||
//final class Gendreau implements SearchStrategyModule{
|
||||
//
|
||||
// private final static Logger log = Logger.getLogger(Gendreau.class);
|
||||
//
|
||||
// private final static String NAME = "gendreauPostOpt";
|
||||
//
|
||||
// private final RuinStrategy ruin;
|
||||
//
|
||||
// private final VehicleRoutingProblem vrp;
|
||||
//
|
||||
// private final InsertionStrategy insertionStrategy;
|
||||
//
|
||||
// private VehicleFleetManager fleetManager;
|
||||
//
|
||||
// private Random random = RandomNumberGeneration.getRandom();
|
||||
//
|
||||
// private int nOfIterations = 10;
|
||||
//
|
||||
// private double shareOfJobsToRuin = 0.15;
|
||||
//
|
||||
// public void setShareOfJobsToRuin(double shareOfJobsToRuin) {
|
||||
// this.shareOfJobsToRuin = shareOfJobsToRuin;
|
||||
// }
|
||||
//
|
||||
// public Gendreau(VehicleRoutingProblem vrp, RuinStrategy ruin, InsertionStrategy insertionStrategy, VehicleFleetManager vehicleFleetManager) {
|
||||
// super();
|
||||
// InsertionListeners insertionListeners = new InsertionListeners();
|
||||
// insertionListeners.addAllListeners(insertionStrategy.getListeners());
|
||||
// new Inserter(insertionListeners);
|
||||
// this.ruin = ruin;
|
||||
// this.vrp = vrp;
|
||||
// this.insertionStrategy = insertionStrategy;
|
||||
// this.fleetManager = vehicleFleetManager;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString() {
|
||||
// return "[name=gendreau][iterations="+nOfIterations+"][share2ruin="+shareOfJobsToRuin+"]";
|
||||
// }
|
||||
//
|
||||
// public void setRandom(Random random) {
|
||||
// this.random = random;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public void setNuOfIterations(int nOfIterations) {
|
||||
// this.nOfIterations = nOfIterations;
|
||||
// }
|
||||
//
|
||||
//// public void setFleetManager(VehicleFleetManager vehicleFleetManager) {
|
||||
//// this.fleetManager = vehicleFleetManager;
|
||||
////
|
||||
//// }
|
||||
//
|
||||
// @Override
|
||||
// public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) {
|
||||
//// log.info("run gendreau postopt");
|
||||
// VehicleRoutingProblemSolution bestSolution = vrpSolution;
|
||||
// int itersWithoutImprovement = 0;
|
||||
//
|
||||
// for(int i=0;i<nOfIterations;i++){
|
||||
// List<VehicleRoute> copiedRoutes = copyRoutes(bestSolution.getRoutes());
|
||||
// iniFleet(copiedRoutes);
|
||||
//
|
||||
// VehicleRoute route2split = pickRouteThatHasAtLeastTwoJobs(copiedRoutes);
|
||||
// if(route2split == null) continue;
|
||||
// List<Job> jobsInRoute = getJobs(route2split);
|
||||
// Set<Job> unassignedJobs = new HashSet<Job>();
|
||||
// unassignedJobs.addAll(jobsInRoute);
|
||||
// copiedRoutes.remove(route2split);
|
||||
//
|
||||
// Collections.shuffle(jobsInRoute,random);
|
||||
// Job targetJob = jobsInRoute.get(0);
|
||||
// int nOfJobs2BeRemovedAdditionally = (int) (shareOfJobsToRuin*(double)vrp.getJobs().size());
|
||||
// Collection<Job> unassignedJobsList = ruin.ruin(copiedRoutes, targetJob, nOfJobs2BeRemovedAdditionally);
|
||||
// unassignedJobs.addAll(unassignedJobsList);
|
||||
//
|
||||
// VehicleRoute emptyRoute1 = VehicleRoute.emptyRoute();
|
||||
// copiedRoutes.add(emptyRoute1);
|
||||
// insertionStrategy.insertJobs(Arrays.asList(emptyRoute1), Arrays.asList(targetJob));
|
||||
//
|
||||
// unassignedJobs.remove(targetJob);
|
||||
//
|
||||
// VehicleRoute emptyRoute2 = VehicleRoute.emptyRoute();
|
||||
// copiedRoutes.add(emptyRoute2);
|
||||
// Job job2 = jobsInRoute.get(1);
|
||||
// insertionStrategy.insertJobs(Arrays.asList(emptyRoute2), Arrays.asList(job2));
|
||||
//
|
||||
// unassignedJobs.remove(job2);
|
||||
//
|
||||
// insertionStrategy.insertJobs(copiedRoutes, unassignedJobs);
|
||||
// double cost = getCost(copiedRoutes);
|
||||
//
|
||||
// if(cost < bestSolution.getCost()){
|
||||
//// log.info("BING - new: " + cost + " old: " + bestSolution.getCost());
|
||||
// bestSolution = new VehicleRoutingProblemSolution(copiedRoutes, cost);
|
||||
// itersWithoutImprovement=0;
|
||||
// }
|
||||
// else{
|
||||
// itersWithoutImprovement++;
|
||||
// if(itersWithoutImprovement > 200){
|
||||
//// log.info("BREAK i="+i);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return bestSolution;
|
||||
// }
|
||||
//
|
||||
// private List<VehicleRoute> copyRoutes(Collection<VehicleRoute> routes) {
|
||||
// List<VehicleRoute> routeList = new ArrayList<VehicleRoute>();
|
||||
// for(VehicleRoute r : routes){
|
||||
// routeList.add(VehicleRoute.copyOf(r));
|
||||
// }
|
||||
// return routeList;
|
||||
// }
|
||||
//
|
||||
// private void iniFleet(Collection<VehicleRoute> routes) {
|
||||
// fleetManager.unlockAll();
|
||||
// for(VehicleRoute route : routes){
|
||||
// if(!route.isEmpty()){
|
||||
// fleetManager.lock(route.getVehicle());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private double getCost(Collection<VehicleRoute> routes) {
|
||||
// double c = 0.0;
|
||||
// for(VehicleRoute r : routes){
|
||||
// c+=r.getCost();
|
||||
// }
|
||||
// return c;
|
||||
// }
|
||||
//
|
||||
// private List<Job> getJobs(VehicleRoute route2split) {
|
||||
// Set<Job> jobs = new HashSet<Job>();
|
||||
// for(TourActivity act : route2split.getTourActivities().getActivities()){
|
||||
// if(act instanceof JobActivity){
|
||||
// jobs.add(((JobActivity) act).getJob());
|
||||
// }
|
||||
// }
|
||||
// return new ArrayList<Job>(jobs);
|
||||
// }
|
||||
//
|
||||
// private VehicleRoute pickRouteThatHasAtLeastTwoJobs(Collection<VehicleRoute> routeList) {
|
||||
// List<VehicleRoute> routes = new ArrayList<VehicleRoute>();
|
||||
// for(VehicleRoute r : routeList){
|
||||
// if(getJobs(r).size() > 1){
|
||||
// routes.add(r);
|
||||
// }
|
||||
// }
|
||||
// if(routes.isEmpty()) return null;
|
||||
// Collections.shuffle(routes,random);
|
||||
// return routes.get(0);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getName() {
|
||||
// return NAME;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void addModuleListener(SearchStrategyModuleListener moduleListener) {
|
||||
// if(moduleListener instanceof InsertionListener){
|
||||
// InsertionListener iListener = (InsertionListener) moduleListener;
|
||||
// if(!insertionStrategy.getListeners().contains(iListener)){
|
||||
// insertionStrategy.addListener(iListener);
|
||||
// }
|
||||
// }
|
||||
// if(moduleListener instanceof RuinListener){
|
||||
// RuinListener rListener = (RuinListener) moduleListener;
|
||||
// if(!ruin.getListeners().contains(rListener)){
|
||||
// ruin.addListener(rListener);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
|
@ -14,16 +14,19 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.module;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.Job;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.algo.InsertionListener;
|
||||
import basics.algo.RuinListener;
|
||||
import basics.algo.SearchStrategyModule;
|
||||
import basics.algo.SearchStrategyModuleListener;
|
||||
import jsprit.core.algorithm.SearchStrategyModule;
|
||||
import jsprit.core.algorithm.listener.SearchStrategyModuleListener;
|
||||
import jsprit.core.algorithm.recreate.InsertionStrategy;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListener;
|
||||
import jsprit.core.algorithm.ruin.RuinStrategy;
|
||||
import jsprit.core.algorithm.ruin.listener.RuinListener;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
|
||||
public class RuinAndRecreateModule implements SearchStrategyModule{
|
||||
|
||||
|
|
@ -18,9 +18,10 @@
|
|||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import basics.route.TourActivity;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
|
||||
public interface ActivityInsertionCostsCalculator {
|
||||
|
||||
|
|
@ -50,6 +51,6 @@ public interface ActivityInsertionCostsCalculator {
|
|||
|
||||
}
|
||||
|
||||
public ActivityInsertionCosts getCosts(InsertionContext iContext, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct);
|
||||
public ActivityInsertionCosts getCosts(JobInsertionContext iContext, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct);
|
||||
|
||||
}
|
||||
|
|
@ -14,16 +14,17 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import basics.costs.VehicleRoutingActivityCosts;
|
||||
import basics.costs.VehicleRoutingTransportCosts;
|
||||
import basics.route.Driver;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.Vehicle;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
|
||||
|
||||
final class AuxilliaryCostCalculator {
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
|
@ -22,15 +22,17 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import jsprit.core.algorithm.recreate.InsertionData.NoInsertionFound;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListener;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.util.RandomNumberGeneration;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.RandomNumberGeneration;
|
||||
import algorithms.InsertionData.NoInsertionFound;
|
||||
import basics.Job;
|
||||
import basics.algo.InsertionListener;
|
||||
import basics.route.Driver;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,13 +1,16 @@
|
|||
package algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.algo.InsertionListener;
|
||||
import basics.algo.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
|
||||
import basics.route.VehicleFleetManager;
|
||||
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListener;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
|
||||
|
||||
public class BestInsertionBuilder {
|
||||
|
||||
|
|
@ -34,6 +37,12 @@ public class BestInsertionBuilder {
|
|||
private ExecutorService executor;
|
||||
|
||||
private int nuOfThreads;
|
||||
|
||||
private double timeSlice;
|
||||
|
||||
private int nNeighbors;
|
||||
|
||||
private boolean timeScheduling=false;
|
||||
|
||||
public BestInsertionBuilder(VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager, StateManager stateManager, ConstraintManager constraintManager) {
|
||||
super();
|
||||
|
|
@ -92,6 +101,9 @@ public class BestInsertionBuilder {
|
|||
if(considerFixedCosts) {
|
||||
calcBuilder.considerFixedCosts(weightOfFixedCosts);
|
||||
}
|
||||
if(timeScheduling){
|
||||
calcBuilder.experimentalTimeScheduler(timeSlice, nNeighbors);
|
||||
}
|
||||
JobInsertionCostsCalculator jobInsertions = calcBuilder.build();
|
||||
InsertionStrategy bestInsertion;
|
||||
if(executor == null){
|
||||
|
|
@ -107,6 +119,18 @@ public class BestInsertionBuilder {
|
|||
return bestInsertion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated this is experimental and can disappear.
|
||||
* @param parseDouble
|
||||
* @param parseInt
|
||||
*/
|
||||
@Deprecated
|
||||
public void experimentalTimeScheduler(double timeSlice, int nNeighbors) {
|
||||
this.timeSlice=timeSlice;
|
||||
this.nNeighbors=nNeighbors;
|
||||
timeScheduling=true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
|
@ -27,15 +27,17 @@ import java.util.concurrent.ExecutorCompletionService;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import jsprit.core.algorithm.recreate.InsertionData.NoInsertionFound;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListener;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.util.RandomNumberGeneration;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.RandomNumberGeneration;
|
||||
import algorithms.InsertionData.NoInsertionFound;
|
||||
import basics.Job;
|
||||
import basics.algo.InsertionListener;
|
||||
import basics.route.Driver;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
|
|
@ -170,7 +172,7 @@ final class BestInsertionConcurrent implements InsertionStrategy{
|
|||
bestInsertion = new Insertion(newRoute,newIData);
|
||||
bestInsertionCost = newIData.getInsertionCost();
|
||||
vehicleRoutes.add(newRoute);
|
||||
batches.get(0).routes.add(newRoute);
|
||||
batches.get(random.nextInt(batches.size())).routes.add(newRoute);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -14,18 +14,19 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.Job;
|
||||
import basics.route.Driver;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
class CalculatesServiceInsertionWithTimeScheduling implements JobInsertionCostsCalculator{
|
||||
|
|
@ -14,20 +14,23 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import basics.Delivery;
|
||||
import basics.Job;
|
||||
import basics.Pickup;
|
||||
import basics.Service;
|
||||
import basics.Shipment;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.algo.InsertionListener;
|
||||
import basics.algo.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
|
||||
import basics.route.VehicleFleetManager;
|
||||
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListener;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -64,7 +67,7 @@ class CalculatorBuilder {
|
|||
|
||||
private VehicleRoutingProblem vrp;
|
||||
|
||||
private StateGetter states;
|
||||
private RouteAndActivityStateGetter states;
|
||||
|
||||
private boolean local = true;
|
||||
|
||||
|
|
@ -109,7 +112,7 @@ class CalculatorBuilder {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
public CalculatorBuilder setStates(StateGetter states){
|
||||
public CalculatorBuilder setStates(RouteAndActivityStateGetter states){
|
||||
this.states = states;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -235,7 +238,7 @@ class CalculatorBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
private CalculatorPlusListeners createStandardLocal(VehicleRoutingProblem vrp, StateGetter statesManager){
|
||||
private CalculatorPlusListeners createStandardLocal(VehicleRoutingProblem vrp, RouteAndActivityStateGetter statesManager){
|
||||
if(constraintManager == null) throw new IllegalStateException("constraint-manager is null");
|
||||
|
||||
|
||||
|
|
@ -263,7 +266,7 @@ class CalculatorBuilder {
|
|||
return calcPlusListeners;
|
||||
}
|
||||
|
||||
private CalculatorPlusListeners createCalculatorConsideringFixedCosts(VehicleRoutingProblem vrp, JobInsertionCostsCalculator baseCalculator, StateGetter activityStates2, double weightOfFixedCosts){
|
||||
private CalculatorPlusListeners createCalculatorConsideringFixedCosts(VehicleRoutingProblem vrp, JobInsertionCostsCalculator baseCalculator, RouteAndActivityStateGetter activityStates2, double weightOfFixedCosts){
|
||||
final JobInsertionConsideringFixCostsCalculator withFixCost = new JobInsertionConsideringFixCostsCalculator(baseCalculator, activityStates2);
|
||||
withFixCost.setWeightOfFixCost(weightOfFixedCosts);
|
||||
CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(withFixCost);
|
||||
|
|
@ -271,7 +274,7 @@ class CalculatorBuilder {
|
|||
return calcPlusListeners;
|
||||
}
|
||||
|
||||
private CalculatorPlusListeners createStandardRoute(VehicleRoutingProblem vrp, StateGetter activityStates2, int forwardLooking, int solutionMemory){
|
||||
private CalculatorPlusListeners createStandardRoute(VehicleRoutingProblem vrp, RouteAndActivityStateGetter activityStates2, int forwardLooking, int solutionMemory){
|
||||
int after = forwardLooking;
|
||||
ActivityInsertionCostsCalculator routeLevelCostEstimator;
|
||||
if(activityInsertionCostCalculator == null){
|
||||
|
|
@ -289,7 +292,7 @@ class CalculatorBuilder {
|
|||
return calcPlusListener;
|
||||
}
|
||||
|
||||
private JobInsertionCostsCalculator createFinalInsertion(VehicleFleetManager fleetManager, JobInsertionCostsCalculator baseCalc, StateGetter activityStates2){
|
||||
private JobInsertionCostsCalculator createFinalInsertion(VehicleFleetManager fleetManager, JobInsertionCostsCalculator baseCalc, RouteAndActivityStateGetter activityStates2){
|
||||
return new VehicleTypeDependentJobInsertionCalculator(fleetManager, baseCalc);
|
||||
}
|
||||
|
||||
|
|
@ -14,18 +14,19 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionStartsListener;
|
||||
import jsprit.core.algorithm.recreate.listener.JobInsertedListener;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.Job;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.algo.InsertionStartsListener;
|
||||
import basics.algo.JobInsertedListener;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,18 +14,19 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import algorithms.InsertionData.NoInsertionFound;
|
||||
import basics.Job;
|
||||
import basics.Service;
|
||||
import basics.Shipment;
|
||||
import basics.route.DefaultShipmentActivityFactory;
|
||||
import basics.route.DefaultTourActivityFactory;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.TourActivityFactory;
|
||||
import basics.route.TourShipmentActivityFactory;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.algorithm.recreate.InsertionData.NoInsertionFound;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.DefaultShipmentActivityFactory;
|
||||
import jsprit.core.problem.solution.route.activity.DefaultTourActivityFactory;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivityFactory;
|
||||
import jsprit.core.problem.solution.route.activity.TourShipmentActivityFactory;
|
||||
|
||||
class Inserter {
|
||||
|
||||
|
|
@ -14,10 +14,10 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import basics.route.Driver;
|
||||
import basics.route.Vehicle;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
/**
|
||||
* Data object that collects insertion information. It collects insertionCosts, insertionIndeces, vehicle and driver to be employed
|
||||
|
|
@ -14,13 +14,14 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.Job;
|
||||
import basics.algo.InsertionListener;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListener;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,9 +14,9 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
|
||||
public interface InsertionStrategyFactory {
|
||||
|
||||
|
|
@ -1,14 +1,15 @@
|
|||
package algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import basics.Job;
|
||||
import basics.route.Driver;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
public class JobCalculatorSwitcher implements JobInsertionCostsCalculator{
|
||||
|
||||
class JobCalculatorSwitcher implements JobInsertionCostsCalculator{
|
||||
|
||||
private Map<Class<? extends Job>,JobInsertionCostsCalculator> calcMap = new HashMap<Class<? extends Job>, JobInsertionCostsCalculator>();
|
||||
|
||||
|
|
@ -14,16 +14,19 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import jsprit.core.algorithm.recreate.InsertionData.NoInsertionFound;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import algorithms.InsertionData.NoInsertionFound;
|
||||
import basics.Job;
|
||||
import basics.route.Driver;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl.NoVehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
|
|
@ -37,9 +40,9 @@ final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCos
|
|||
|
||||
private double solution_completeness_ratio = 0.5;
|
||||
|
||||
private StateGetter stateGetter;
|
||||
private RouteAndActivityStateGetter stateGetter;
|
||||
|
||||
public JobInsertionConsideringFixCostsCalculator(final JobInsertionCostsCalculator standardInsertionCalculator, StateGetter stateGetter) {
|
||||
public JobInsertionConsideringFixCostsCalculator(final JobInsertionCostsCalculator standardInsertionCalculator, RouteAndActivityStateGetter stateGetter) {
|
||||
super();
|
||||
this.standardServiceInsertion = standardInsertionCalculator;
|
||||
this.stateGetter = stateGetter;
|
||||
|
|
@ -14,12 +14,12 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import basics.Job;
|
||||
import basics.route.Driver;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
|
||||
public interface JobInsertionCostsCalculator {
|
||||
|
|
@ -18,11 +18,13 @@
|
|||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import basics.costs.VehicleRoutingActivityCosts;
|
||||
import basics.costs.VehicleRoutingTransportCosts;
|
||||
import basics.route.TourActivity;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.util.CalculationUtils;
|
||||
|
||||
/**
|
||||
* Calculates activity insertion costs locally, i.e. by comparing the additional costs of insertion the new activity k between
|
||||
|
|
@ -34,7 +36,7 @@ import basics.route.TourActivity;
|
|||
* @author stefan
|
||||
*
|
||||
*/
|
||||
public class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCalculator{
|
||||
class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCalculator{
|
||||
|
||||
private VehicleRoutingTransportCosts routingCosts;
|
||||
|
||||
|
|
@ -48,7 +50,7 @@ public class LocalActivityInsertionCostsCalculator implements ActivityInsertionC
|
|||
}
|
||||
|
||||
@Override
|
||||
public ActivityInsertionCosts getCosts(InsertionContext iFacts, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct) {
|
||||
public ActivityInsertionCosts getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct) {
|
||||
|
||||
double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocationId(), newAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
package jsprit.core.algorithm.recreate;
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
package jsprit.core.algorithm.recreate;
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
|
|
@ -18,17 +18,21 @@
|
|||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import basics.costs.VehicleRoutingActivityCosts;
|
||||
import basics.costs.VehicleRoutingTransportCosts;
|
||||
import basics.route.End;
|
||||
import basics.route.Start;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.End;
|
||||
import jsprit.core.problem.solution.route.activity.Start;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
|
||||
class RouteLevelActivityInsertionCostsEstimator implements ActivityInsertionCostsCalculator{
|
||||
|
||||
|
|
@ -36,11 +40,11 @@ class RouteLevelActivityInsertionCostsEstimator implements ActivityInsertionCost
|
|||
|
||||
private AuxilliaryCostCalculator auxilliaryPathCostCalculator;
|
||||
|
||||
private StateGetter stateManager;
|
||||
private RouteAndActivityStateGetter stateManager;
|
||||
|
||||
private int nuOfActivities2LookForward = 0;
|
||||
|
||||
public RouteLevelActivityInsertionCostsEstimator(VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts actCosts, StateGetter stateManager) {
|
||||
public RouteLevelActivityInsertionCostsEstimator(VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts actCosts, RouteAndActivityStateGetter stateManager) {
|
||||
super();
|
||||
this.activityCosts = actCosts;
|
||||
this.stateManager = stateManager;
|
||||
|
|
@ -48,7 +52,7 @@ class RouteLevelActivityInsertionCostsEstimator implements ActivityInsertionCost
|
|||
}
|
||||
|
||||
@Override
|
||||
public ActivityInsertionCosts getCosts(InsertionContext iFacts, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct) {
|
||||
public ActivityInsertionCosts getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct) {
|
||||
List<TourActivity> path = new ArrayList<TourActivity>();
|
||||
path.add(prevAct); path.add(newAct); path.add(nextAct);
|
||||
int actIndex;
|
||||
|
|
@ -14,25 +14,30 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import jsprit.core.algorithm.recreate.ActivityInsertionCostsCalculator.ActivityInsertionCosts;
|
||||
import jsprit.core.problem.constraint.HardActivityStateLevelConstraint;
|
||||
import jsprit.core.problem.constraint.HardActivityStateLevelConstraint.ConstraintsStatus;
|
||||
import jsprit.core.problem.constraint.HardRouteStateLevelConstraint;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.DefaultTourActivityFactory;
|
||||
import jsprit.core.problem.solution.route.activity.End;
|
||||
import jsprit.core.problem.solution.route.activity.Start;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivityFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
|
||||
import jsprit.core.util.CalculationUtils;
|
||||
import jsprit.core.util.Neighborhood;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.Neighborhood;
|
||||
import algorithms.ActivityInsertionCostsCalculator.ActivityInsertionCosts;
|
||||
import algorithms.HardActivityStateLevelConstraint.ConstraintsStatus;
|
||||
import basics.Job;
|
||||
import basics.Service;
|
||||
import basics.costs.VehicleRoutingTransportCosts;
|
||||
import basics.route.DefaultTourActivityFactory;
|
||||
import basics.route.Driver;
|
||||
import basics.route.End;
|
||||
import basics.route.Start;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.TourActivityFactory;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl.NoVehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
|
|
@ -89,7 +94,7 @@ final class ServiceInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
if(jobToInsert == null) throw new IllegalStateException("jobToInsert is missing.");
|
||||
if(newVehicle == null || newVehicle instanceof NoVehicle) throw new IllegalStateException("newVehicle is missing.");
|
||||
|
||||
InsertionContext insertionContext = new InsertionContext(currentRoute, jobToInsert, newVehicle, newDriver, newVehicleDepartureTime);
|
||||
JobInsertionContext insertionContext = new JobInsertionContext(currentRoute, jobToInsert, newVehicle, newDriver, newVehicleDepartureTime);
|
||||
if(!hardRouteLevelConstraint.fulfilled(insertionContext)){
|
||||
return InsertionData.createEmptyInsertionData();
|
||||
}
|
||||
|
|
@ -155,7 +160,7 @@ final class ServiceInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
return insertionData;
|
||||
}
|
||||
|
||||
public ActivityInsertionCosts calculate(InsertionContext iFacts, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double departureTimeAtPrevAct) {
|
||||
public ActivityInsertionCosts calculate(JobInsertionContext iFacts, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double departureTimeAtPrevAct) {
|
||||
return activityInsertionCostsCalculator.getCosts(iFacts, prevAct, nextAct, newAct, departureTimeAtPrevAct);
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
|
|
@ -23,25 +23,31 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.PriorityQueue;
|
||||
|
||||
import jsprit.core.algorithm.recreate.ActivityInsertionCostsCalculator.ActivityInsertionCosts;
|
||||
import jsprit.core.problem.constraint.HardActivityStateLevelConstraint;
|
||||
import jsprit.core.problem.constraint.HardActivityStateLevelConstraint.ConstraintsStatus;
|
||||
import jsprit.core.problem.constraint.HardRouteStateLevelConstraint;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.DefaultTourActivityFactory;
|
||||
import jsprit.core.problem.solution.route.activity.End;
|
||||
import jsprit.core.problem.solution.route.activity.Start;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivities;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivityFactory;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
|
||||
import jsprit.core.util.Neighborhood;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.Neighborhood;
|
||||
import algorithms.ActivityInsertionCostsCalculator.ActivityInsertionCosts;
|
||||
import algorithms.HardActivityStateLevelConstraint.ConstraintsStatus;
|
||||
import basics.Job;
|
||||
import basics.Service;
|
||||
import basics.costs.VehicleRoutingActivityCosts;
|
||||
import basics.costs.VehicleRoutingTransportCosts;
|
||||
import basics.route.DefaultTourActivityFactory;
|
||||
import basics.route.Driver;
|
||||
import basics.route.End;
|
||||
import basics.route.Start;
|
||||
import basics.route.TourActivities;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.TourActivityFactory;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl.NoVehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
|
|
@ -57,7 +63,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
|
|||
|
||||
private TourActivityFactory tourActivityFactory = new DefaultTourActivityFactory();
|
||||
|
||||
private StateGetter stateManager;
|
||||
private RouteAndActivityStateGetter stateManager;
|
||||
|
||||
private HardRouteStateLevelConstraint hardRouteLevelConstraint;
|
||||
|
||||
|
|
@ -108,7 +114,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
|
|||
}
|
||||
|
||||
|
||||
public void setStates(StateGetter stateManager){
|
||||
public void setStates(RouteAndActivityStateGetter stateManager){
|
||||
this.stateManager = stateManager;
|
||||
}
|
||||
|
||||
|
|
@ -135,7 +141,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
|
|||
if(jobToInsert == null) throw new IllegalStateException("job is null. cannot calculate the insertion of a null-job.");
|
||||
if(newVehicle == null || newVehicle instanceof NoVehicle) throw new IllegalStateException("no vehicle given. set para vehicle!");
|
||||
|
||||
InsertionContext insertionContext = new InsertionContext(currentRoute, jobToInsert, newVehicle, newDriver, newVehicleDepartureTime);
|
||||
JobInsertionContext insertionContext = new JobInsertionContext(currentRoute, jobToInsert, newVehicle, newDriver, newVehicleDepartureTime);
|
||||
if(!hardRouteLevelConstraint.fulfilled(insertionContext)){
|
||||
return InsertionData.createEmptyInsertionData();
|
||||
}
|
||||
|
|
@ -14,27 +14,32 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jsprit.core.algorithm.recreate.ActivityInsertionCostsCalculator.ActivityInsertionCosts;
|
||||
import jsprit.core.problem.constraint.HardActivityStateLevelConstraint;
|
||||
import jsprit.core.problem.constraint.HardActivityStateLevelConstraint.ConstraintsStatus;
|
||||
import jsprit.core.problem.constraint.HardRouteStateLevelConstraint;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.DefaultShipmentActivityFactory;
|
||||
import jsprit.core.problem.solution.route.activity.End;
|
||||
import jsprit.core.problem.solution.route.activity.Start;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.activity.TourShipmentActivityFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
|
||||
import jsprit.core.util.CalculationUtils;
|
||||
import jsprit.core.util.Neighborhood;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.Neighborhood;
|
||||
import algorithms.ActivityInsertionCostsCalculator.ActivityInsertionCosts;
|
||||
import algorithms.HardActivityStateLevelConstraint.ConstraintsStatus;
|
||||
import basics.Job;
|
||||
import basics.Shipment;
|
||||
import basics.costs.VehicleRoutingTransportCosts;
|
||||
import basics.route.DefaultShipmentActivityFactory;
|
||||
import basics.route.Driver;
|
||||
import basics.route.End;
|
||||
import basics.route.Start;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.TourShipmentActivityFactory;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl.NoVehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
|
|
@ -91,7 +96,7 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
if(newVehicle == null || newVehicle instanceof NoVehicle) throw new IllegalStateException("newVehicle is missing.");
|
||||
if(!(jobToInsert instanceof Shipment)) throw new IllegalStateException("jobToInsert should be of type Shipment!");
|
||||
|
||||
InsertionContext insertionContext = new InsertionContext(currentRoute, jobToInsert, newVehicle, newDriver, newVehicleDepartureTime);
|
||||
JobInsertionContext insertionContext = new JobInsertionContext(currentRoute, jobToInsert, newVehicle, newDriver, newVehicleDepartureTime);
|
||||
if(!hardRouteLevelConstraint.fulfilled(insertionContext)){
|
||||
return InsertionData.createEmptyInsertionData();
|
||||
}
|
||||
|
|
@ -201,7 +206,7 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
return insertionData;
|
||||
}
|
||||
|
||||
private ActivityInsertionCosts calculate(InsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double departureTimeAtPrevAct) {
|
||||
private ActivityInsertionCosts calculate(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double departureTimeAtPrevAct) {
|
||||
return activityInsertionCostsCalculator.getCosts(iFacts, prevAct, nextAct, newAct, departureTimeAtPrevAct);
|
||||
|
||||
}
|
||||
|
|
@ -14,18 +14,19 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleFleetManager;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.algorithm.recreate.listener.VehicleSwitchedListener;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
|
||||
|
||||
class VehicleSwitched implements VehicleSwitchedListener{
|
||||
public class VehicleSwitched implements VehicleSwitchedListener{
|
||||
|
||||
private VehicleFleetManager fleetManager;
|
||||
|
||||
VehicleSwitched(VehicleFleetManager fleetManager){
|
||||
public VehicleSwitched(VehicleFleetManager fleetManager){
|
||||
this.fleetManager = fleetManager;
|
||||
}
|
||||
|
||||
|
|
@ -14,20 +14,21 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.algorithm.recreate.InsertionData.NoInsertionFound;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import algorithms.InsertionData.NoInsertionFound;
|
||||
import basics.Job;
|
||||
import basics.route.Driver;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleFleetManager;
|
||||
import basics.route.VehicleImpl.NoVehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,11 +14,11 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate.listener;
|
||||
|
||||
import basics.Job;
|
||||
import basics.algo.InsertionListener;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.algorithm.recreate.InsertionData;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
||||
interface BeforeJobInsertionListener extends InsertionListener{
|
||||
|
||||
|
|
@ -14,11 +14,12 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm.recreate.listener;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
public interface InsertionEndsListener extends InsertionListener {
|
||||
|
|
@ -14,7 +14,9 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm.recreate.listener;
|
||||
|
||||
import jsprit.core.algorithm.listener.SearchStrategyModuleListener;
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,20 +14,18 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.Job;
|
||||
import basics.algo.InsertionEndsListener;
|
||||
import basics.algo.InsertionListener;
|
||||
import basics.algo.InsertionStartsListener;
|
||||
import basics.algo.JobInsertedListener;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.algorithm.recreate.InsertionData;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
class InsertionListeners {
|
||||
|
||||
public class InsertionListeners {
|
||||
|
||||
private Collection<InsertionListener> listeners = new ArrayList<InsertionListener>();
|
||||
|
||||
|
|
@ -14,12 +14,13 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm.recreate.listener;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.Job;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
public interface InsertionStartsListener extends InsertionListener {
|
||||
|
|
@ -14,10 +14,10 @@
|
|||
* 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 basics.algo;
|
||||
package jsprit.core.algorithm.recreate.listener;
|
||||
|
||||
import basics.Job;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,13 +14,12 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.recreate.listener;
|
||||
|
||||
import basics.algo.InsertionListener;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
interface VehicleSwitchedListener extends InsertionListener{
|
||||
public interface VehicleSwitchedListener extends InsertionListener{
|
||||
|
||||
public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle);
|
||||
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package algorithms;
|
||||
package jsprit.core.algorithm.ruin;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
import jsprit.core.algorithm.ruin.distance.JobDistance;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
|
||||
public class RadialRuinStrategyFactory implements RuinStrategyFactory{
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package algorithms;
|
||||
package jsprit.core.algorithm.ruin;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
|
||||
public class RandomRuinStrategyFactory implements RuinStrategyFactory{
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.ruin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
|
@ -27,15 +27,17 @@ import java.util.Map;
|
|||
import java.util.Random;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import jsprit.core.algorithm.ruin.distance.JobDistance;
|
||||
import jsprit.core.algorithm.ruin.listener.RuinListener;
|
||||
import jsprit.core.algorithm.ruin.listener.RuinListeners;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.util.RandomNumberGeneration;
|
||||
import jsprit.core.util.StopWatch;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.RandomNumberGeneration;
|
||||
import util.StopWatch;
|
||||
import basics.Job;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.algo.RuinListener;
|
||||
import basics.algo.RuinListeners;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.ruin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
|
@ -22,14 +22,15 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import jsprit.core.algorithm.ruin.listener.RuinListener;
|
||||
import jsprit.core.algorithm.ruin.listener.RuinListeners;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.util.RandomNumberGeneration;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.RandomNumberGeneration;
|
||||
import basics.Job;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.algo.RuinListener;
|
||||
import basics.algo.RuinListeners;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -14,13 +14,14 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.ruin;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.Job;
|
||||
import basics.algo.RuinListener;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.algorithm.ruin.listener.RuinListener;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,9 +14,9 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.ruin;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
|
||||
public interface RuinStrategyFactory {
|
||||
|
||||
|
|
@ -14,16 +14,17 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.ruin.distance;
|
||||
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.EuclideanDistanceCalculator;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.Coordinate;
|
||||
import util.EuclideanDistanceCalculator;
|
||||
import basics.Job;
|
||||
import basics.Service;
|
||||
import basics.Shipment;
|
||||
import basics.costs.VehicleRoutingTransportCosts;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -34,13 +35,13 @@ import basics.costs.VehicleRoutingTransportCosts;
|
|||
* @author stefan schroeder
|
||||
*
|
||||
*/
|
||||
public class AvgJobDistance implements JobDistance {
|
||||
public class AvgServiceAndShipmentDistance implements JobDistance {
|
||||
|
||||
private static Logger log = Logger.getLogger(AvgJobDistance.class);
|
||||
private static Logger log = Logger.getLogger(AvgServiceAndShipmentDistance.class);
|
||||
|
||||
private VehicleRoutingTransportCosts costs;
|
||||
|
||||
public AvgJobDistance(VehicleRoutingTransportCosts costs) {
|
||||
public AvgServiceAndShipmentDistance(VehicleRoutingTransportCosts costs) {
|
||||
super();
|
||||
this.costs = costs;
|
||||
|
||||
|
|
@ -14,13 +14,14 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.ruin.distance;
|
||||
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.Job;
|
||||
import basics.Service;
|
||||
import basics.costs.VehicleRoutingTransportCosts;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -31,13 +32,13 @@ import basics.costs.VehicleRoutingTransportCosts;
|
|||
* @author stefan schroeder
|
||||
*
|
||||
*/
|
||||
public class JobDistanceAvgCosts implements JobDistance {
|
||||
public class AvgServiceDistance implements JobDistance {
|
||||
|
||||
private static Logger log = Logger.getLogger(JobDistanceAvgCosts.class);
|
||||
private static Logger log = Logger.getLogger(AvgServiceDistance.class);
|
||||
|
||||
private VehicleRoutingTransportCosts costs;
|
||||
|
||||
public JobDistanceAvgCosts(VehicleRoutingTransportCosts costs) {
|
||||
public AvgServiceDistance(VehicleRoutingTransportCosts costs) {
|
||||
super();
|
||||
this.costs = costs;
|
||||
|
||||
|
|
@ -61,7 +62,7 @@ public class JobDistanceAvgCosts implements JobDistance {
|
|||
}
|
||||
} else {
|
||||
throw new UnsupportedOperationException(
|
||||
"currently, this class just works with shipments and services.");
|
||||
"currently, this class just works services.");
|
||||
}
|
||||
return avgCost;
|
||||
}
|
||||
|
|
@ -14,13 +14,13 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.ruin.distance;
|
||||
|
||||
import util.EuclideanDistanceCalculator;
|
||||
import basics.Job;
|
||||
import basics.Service;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.util.EuclideanDistanceCalculator;
|
||||
|
||||
class EuclideanServiceDistance implements JobDistance {
|
||||
public class EuclideanServiceDistance implements JobDistance {
|
||||
|
||||
public EuclideanServiceDistance() {
|
||||
super();
|
||||
|
|
@ -14,9 +14,9 @@
|
|||
* 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 algorithms;
|
||||
package jsprit.core.algorithm.ruin.distance;
|
||||
|
||||
import basics.Job;
|
||||
import jsprit.core.problem.job.Job;
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
package basics.algo;
|
||||
package jsprit.core.algorithm.ruin.listener;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.Job;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.algorithm.listener.SearchStrategyModuleListener;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
||||
|
||||
/**
|
||||
* Listener that listens to the ruin-process. It informs whoever is interested about start, end and about a removal of a job.
|
||||
|
|
@ -18,14 +18,15 @@
|
|||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package basics.algo;
|
||||
package jsprit.core.algorithm.ruin.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import basics.Job;
|
||||
import basics.route.VehicleRoute;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
||||
|
||||
public class RuinListeners {
|
||||
|
||||
|
|
@ -14,11 +14,12 @@
|
|||
* 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 algorithms.selectors;
|
||||
package jsprit.core.algorithm.selector;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,15 +14,16 @@
|
|||
* 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 algorithms.selectors;
|
||||
package jsprit.core.algorithm.selector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import util.RandomNumberGeneration;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.util.RandomNumberGeneration;
|
||||
|
||||
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue