diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/FindCheaperVehicle.java b/jsprit-core/src/main/java/jsprit/core/algorithm/FindCheaperVehicle.java deleted file mode 100644 index 155fa90e..00000000 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/FindCheaperVehicle.java +++ /dev/null @@ -1,54 +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 . -// ******************************************************************************/ -//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 vehicleRoutes, Collection unassignedJobs) { -// List newRoutes = new ArrayList(); -// 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]"; -// } -// -//} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/FindCheaperVehicleAlgo.java b/jsprit-core/src/main/java/jsprit/core/algorithm/FindCheaperVehicleAlgo.java deleted file mode 100644 index c40165bf..00000000 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/FindCheaperVehicleAlgo.java +++ /dev/null @@ -1,114 +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 . -// ******************************************************************************/ -//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 availableVehicleTypes = fleetManager.getAvailableVehicleTypes(new TypeKey(vehicleRoute.getVehicle().getType(),vehicleRoute.getVehicle().getLocationId())); -// double bestSaving = 0.0; -// Vehicle bestVehicle = null; -// List path = new ArrayList(); -// 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; -// } -// -//} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/module/Gendreau.java b/jsprit-core/src/main/java/jsprit/core/algorithm/module/Gendreau.java deleted file mode 100644 index 2a933c19..00000000 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/module/Gendreau.java +++ /dev/null @@ -1,224 +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 . -// ******************************************************************************/ -//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 copiedRoutes = copyRoutes(bestSolution.getRoutes()); -// iniFleet(copiedRoutes); -// -// VehicleRoute route2split = pickRouteThatHasAtLeastTwoJobs(copiedRoutes); -// if(route2split == null) continue; -// List jobsInRoute = getJobs(route2split); -// Set unassignedJobs = new HashSet(); -// unassignedJobs.addAll(jobsInRoute); -// copiedRoutes.remove(route2split); -// -// Collections.shuffle(jobsInRoute,random); -// Job targetJob = jobsInRoute.get(0); -// int nOfJobs2BeRemovedAdditionally = (int) (shareOfJobsToRuin*(double)vrp.getJobs().size()); -// Collection 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 copyRoutes(Collection routes) { -// List routeList = new ArrayList(); -// for(VehicleRoute r : routes){ -// routeList.add(VehicleRoute.copyOf(r)); -// } -// return routeList; -// } -// -// private void iniFleet(Collection routes) { -// fleetManager.unlockAll(); -// for(VehicleRoute route : routes){ -// if(!route.isEmpty()){ -// fleetManager.lock(route.getVehicle()); -// } -// } -// } -// -// private double getCost(Collection routes) { -// double c = 0.0; -// for(VehicleRoute r : routes){ -// c+=r.getCost(); -// } -// return c; -// } -// -// private List getJobs(VehicleRoute route2split) { -// Set jobs = new HashSet(); -// for(TourActivity act : route2split.getTourActivities().getActivities()){ -// if(act instanceof JobActivity){ -// jobs.add(((JobActivity) act).getJob()); -// } -// } -// return new ArrayList(jobs); -// } -// -// private VehicleRoute pickRouteThatHasAtLeastTwoJobs(Collection routeList) { -// List routes = new ArrayList(); -// 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); -// } -// } -// -// } -//} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ParRegretInsertion.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ParRegretInsertion.java deleted file mode 100644 index 9d7fcafd..00000000 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ParRegretInsertion.java +++ /dev/null @@ -1,226 +0,0 @@ -package jsprit.core.algorithm.recreate; -/******************************************************************************* - * 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 . - ******************************************************************************/ -///******************************************************************************* -// * Copyright (c) 2011 Stefan Schroeder. -// * eMail: stefan.schroeder@kit.edu -// * -// * All rights reserved. This program and the accompanying materials -// * are made available under the terms of the GNU Public License v2.0 -// * which accompanies this distribution, and is available at -// * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html -// * -// * Contributors: -// * Stefan Schroeder - initial API and implementation -// ******************************************************************************/ -//package algorithms; -// -//import java.util.ArrayList; -//import java.util.Collection; -//import java.util.List; -//import java.util.concurrent.Callable; -//import java.util.concurrent.CompletionService; -//import java.util.concurrent.ExecutionException; -//import java.util.concurrent.ExecutorCompletionService; -//import java.util.concurrent.ExecutorService; -//import java.util.concurrent.Future; -// -//import org.apache.log4j.Logger; -// -//import basics.InsertionData; -//import basics.Job; -//import basics.Service; -//import basics.Shipment; -//import basics.VehicleRoute; -//import basics.InsertionData.NoInsertionFound; -// -// -// -// -// -// -// -///** -// * Simplest recreation strategy. All removed customers are inserted where insertion costs are minimal. I.e. each tour-agent is asked for -// * minimal marginal insertion costs. The tour-agent offering the lowest marginal insertion costs gets the customer/shipment. -// * -// * @author stefan schroeder -// * -// */ -// -//final class ParRegretInsertion extends AbstractRecreationStrategy{ -// -// -// private Logger logger = Logger.getLogger(ParRegretInsertion.class); -// -// -// public static double scoreParam_of_timeWindowLegth = 0.0; -// -// private ExecutorService executor; -// -// public static double scoreParam_of_distance = 0.5; -// -// private DepotDistance depotDistance; -// -// private RouteAlgorithm routeAlgorithm; -// -// private VehicleRouteFactory vehicleRouteFactory; -// -// public ParRegretInsertion(ExecutorService executor, RouteAlgorithm routeAlgorithm, VehicleRouteFactory routeFactory, DepotDistance depotDistance) { -// super(); -// this.executor = executor; -// this.routeAlgorithm = routeAlgorithm; -// this.depotDistance = depotDistance; -// this.vehicleRouteFactory = routeFactory; -// } -// -// -// @Override -// public void recreate(final Collection vehicleRoutes, Collection unassignedJobs, double result2beat) { -// List jobs = new ArrayList(unassignedJobs); -// informRecreationStart(unassignedJobs.size()); -// -// while(!jobs.isEmpty()){ -// List unassignedJobList = new ArrayList(jobs); -// ScoredJob bestScoredJob = null; -// double bestScore = -1*Double.MAX_VALUE; -// CompletionService completionService = new ExecutorCompletionService(executor); -// -// for(final Job unassignedJob : unassignedJobList){ -// completionService.submit(new Callable(){ -// -// @Override -// public ScoredJob call() throws Exception { -// return getScoredJob(vehicleRoutes, unassignedJob); -// } -// -// }); -// -// } -// try{ -// for(int i=0;i fsj = completionService.take(); -// ScoredJob scoredJob = fsj.get(); -// if(scoredJob == null){ -// continue; -// } -// if(scoredJob.getScore() > bestScore){ -// bestScoredJob = scoredJob; -// bestScore = scoredJob.getScore(); -// } -// } -// } -// catch(InterruptedException e){ -// Thread.currentThread().interrupt(); -// } -// catch (ExecutionException e) { -// e.printStackTrace(); -// logger.error(e.getCause().toString()); -// System.exit(1); -// } -// if(bestScoredJob == null){ -// Job job = unassignedJobList.get(0); -// VehicleRoute newRoute = vehicleRouteFactory.createVehicleRoute(); -// InsertionData bestI = routeAlgorithm.calculateBestInsertion(newRoute, job, Double.MAX_VALUE); -// if(bestI instanceof InsertionData.NoInsertionFound) throw new IllegalStateException("given the vehicles, could not create a valid solution"); -// routeAlgorithm.insertJob(job,bestI,newRoute); -// vehicleRoutes.add(newRoute); -// jobs.remove(job); -// -// } -// else{ -// routeAlgorithm.insertJob(bestScoredJob.getJob(),bestScoredJob.getInsertionData(),bestScoredJob.getRoute()); -// jobs.remove(bestScoredJob.getJob()); -// } -// informJobInsertion(null, (unassignedJobList.size()-1), null); -// } -// } -// -// private ScoredJob getScoredJob(Collection vehicleRoutes, Job job){ -// InsertionData best = null; -// InsertionData secondBest = null; -// VehicleRoute bestRoute = null; -// double benchmark = Double.MAX_VALUE; -// for(VehicleRoute route : vehicleRoutes){ -// if(secondBest != null){ -// benchmark = secondBest.getInsertionCost(); -// } -// InsertionData iData = routeAlgorithm.calculateBestInsertion(route, job, benchmark); -// if(iData instanceof NoInsertionFound) continue; -// if(best == null) { -// best = iData; -// bestRoute = route; -// } -// else if(iData.getInsertionCost() < best.getInsertionCost()){ -// secondBest = best; -// best = iData; -// bestRoute = route; -// } -// else if(secondBest == null) secondBest = iData; -// else if(iData.getInsertionCost() < secondBest.getInsertionCost()) secondBest = iData; -// } -// if(best == null){ -// return null; -// } -// double score = score(job,best,secondBest); -// return new ScoredJob(job, score, best, bestRoute); -// } -// -// private double score(Job unassignedJob, InsertionData best, InsertionData secondBest) { -// /* -// * wieder so eine bescheuerte fallunterscheidung. hier will ich -// * doch einfach nur das maßgebende zeitfenster des jobs -// * job.getTimeWindow() -// * Problem: eine Shipment hat zwei TWs, sowohl ein PickupTW als auch -// * ein DeliveryTW -// */ -// double twStart = 0.0; -// double twEnd = 0.0; -// if(unassignedJob instanceof Shipment){ -// twStart = ((Shipment) unassignedJob).getDeliveryTW().getStart(); -// twEnd = ((Shipment) unassignedJob).getDeliveryTW().getEnd(); -// } -// else if(unassignedJob instanceof Service){ -// twStart = ((Service) unassignedJob).getTimeWindow().getStart(); -// twEnd = ((Service) unassignedJob).getTimeWindow().getEnd(); -// } -// if(best == null){ -// throw new IllegalStateException("cannot insert job " + unassignedJob.getId()); -// } -// if(secondBest == null){ -// return Double.MAX_VALUE; -// } -//// double score = (secondBest.getInsertionCost()-best.getInsertionCost()) + scoreParam_of_distance*getDistance(unassignedJob) - scoreParam_of_timeWindowLegth*(twEnd-twStart); -//// logger.info("priceDiff="+ (secondBest.getPrice()-best.getPrice()) + "; param*dist=" -// double timeWindowInfluence = scoreParam_of_timeWindowLegth*(twEnd-twStart); -// double distanceInfluence = scoreParam_of_distance*getDistance(unassignedJob); -// double score = (secondBest.getInsertionCost()-best.getInsertionCost()) - timeWindowInfluence -// + distanceInfluence; -// return score; -// } -// -// private double getDistance(Job unassignedJob) { -// return depotDistance.calcDistance(unassignedJob); -// } -// -// -// public double getTimeParam() { -// return scoreParam_of_timeWindowLegth; -// } -// -// -//} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertion.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertion.java deleted file mode 100644 index cbac3d07..00000000 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertion.java +++ /dev/null @@ -1,246 +0,0 @@ -package jsprit.core.algorithm.recreate; -/******************************************************************************* - * 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 . - ******************************************************************************/ -///******************************************************************************* -// * Copyright (c) 2011 Stefan Schroeder. -// * eMail: stefan.schroeder@kit.edu -// * -// * All rights reserved. This program and the accompanying materials -// * are made available under the terms of the GNU Public License v2.0 -// * which accompanies this distribution, and is available at -// * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html -// * -// * Contributors: -// * Stefan Schroeder - initial API and implementation -// ******************************************************************************/ -//package algorithms; -// -//import java.util.ArrayList; -//import java.util.Collection; -//import java.util.List; -// -//import org.apache.log4j.Logger; -// -//import algorithms.InsertionData.NoInsertionFound; -//import basics.Job; -//import basics.Service; -//import basics.algo.InsertionListener; -//import basics.route.VehicleRoute; -// -// -///** -// * Insertion based an regret approach. -// * -// *

Basically calculates the insertion cost of the firstBest and the secondBest alternative. The score is then calculated as difference -// * between secondBest and firstBest, plus additional scoring variables that can defined in this.ScoringFunction. -// * The idea is that if the cost of the secondBest alternative is way higher than the first best, it seems to be important to insert this -// * customer immediatedly. If difference is not that high, it might not impact solution if this customer is inserted later. -// * -// * @author stefan schroeder -// * -// */ -//final class RegretInsertion implements InsertionStrategy{ -// -// /** -// * Scorer to include other impacts on score such as time-window length or distance to depot. -// * -// * @author schroeder -// * -// */ -// static interface ScoringFunction { -// -// public double score(Job job); -// -// } -// -// /** -// * Scorer that includes the length of the time-window when scoring a job. The wider the time-window, the lower the score. -// * -// *

This is the default scorer, i.e.: score = (secondBest - firstBest) + this.TimeWindowScorer.score(job) -// * -// * @author schroeder -// * -// */ -// static class TimeWindowScorer implements ScoringFunction { -// -// private double tw_scoringParam = - 0.1; -// -// @Override -// public double score(Job job) { -// double twStart = 0.0; -// double twEnd = 0.0; -//// if(job instanceof Shipment){ -//// twStart = ((Shipment) job).getDeliveryTW().getStart(); -//// twEnd = ((Shipment) job).getDeliveryTW().getEnd(); -//// } -//// else -// if(job instanceof Service){ -// twStart = ((Service) job).getTimeWindow().getStart(); -// twEnd = ((Service) job).getTimeWindow().getEnd(); -// } -// return (twEnd-twStart)*tw_scoringParam; -// } -// -// @Override -// public String toString() { -// return "[name=timeWindowScorer][scoringParam="+tw_scoringParam+"]"; -// } -// -// } -// -// public static RegretInsertion newInstance(RouteAlgorithm routeAlgorithm) { -// return new RegretInsertion(routeAlgorithm); -// } -// -// private Logger logger = Logger.getLogger(RegretInsertion.class); -// -// private RouteAlgorithm routeAlgorithm; -// -// private ScoringFunction scoringFunction = new TimeWindowScorer(); -// -// /** -// * Sets the scoring function. -// * -// *

By default, the this.TimeWindowScorer is used. -// * -// * @param scoringFunction -// */ -// public void setScoringFunction(ScoringFunction scoringFunction) { -// this.scoringFunction = scoringFunction; -// } -// -// public RegretInsertion(RouteAlgorithm routeAlgorithm) { -// super(); -// this.routeAlgorithm = routeAlgorithm; -// logger.info("initialise " + this); -// } -// -// @Override -// public String toString() { -// return "[name=regretInsertion][additionalScorer="+scoringFunction+"]"; -// } -// -// public RouteAlgorithm getRouteAlgorithm(){ -// return routeAlgorithm; -// } -// -// /** -// * Runs insertion. -// * -// *

Before inserting a job, all unassigned jobs are scored according to its best- and secondBest-insertion plus additional scoring variables. -// * -// */ -// @Override -// public void insertJobs(Collection routes, Collection unassignedJobs) { -// List jobs = new ArrayList(unassignedJobs); -//// informInsertionStarts(routes,unassignedJobs); -// int inserted = 0; -// while(!jobs.isEmpty()){ -// List unassignedJobList = new ArrayList(jobs); -// ScoredJob bestScoredJob = null; -// double bestScore = -1*Double.MAX_VALUE; -// VehicleRoute insertIn = null; -// -// for(Job unassignedJob : unassignedJobList){ -// InsertionData best = null; -// InsertionData secondBest = null; -// VehicleRoute bestRoute = null; -// -// double benchmark = Double.MAX_VALUE; -// for(VehicleRoute route : routes){ -// if(secondBest != null){ -// benchmark = secondBest.getInsertionCost(); -// } -// InsertionData iData = routeAlgorithm.calculateBestInsertion(route, unassignedJob, benchmark); -// if(iData instanceof NoInsertionFound) continue; -// if(best == null){ -// best = iData; -// bestRoute = route; -// } -// else if(iData.getInsertionCost() < best.getInsertionCost()){ -// secondBest = best; -// best = iData; -// bestRoute = route; -// } -// else if(secondBest == null || (iData.getInsertionCost() < secondBest.getInsertionCost())){ -// secondBest = iData; -// } -// } -// if(best == null){ -// break; -// } -// double score = score(unassignedJob,best,secondBest); -// if(score > bestScore){ -// bestScoredJob = new ScoredJob(unassignedJob,score,best,bestRoute); -// bestScore = score; -// } -// } -// Job assignedJob; -// if(bestScoredJob == null){ -// Job job = unassignedJobList.get(0); -// VehicleRoute newRoute = VehicleRoute.emptyRoute(); -// InsertionData bestI = routeAlgorithm.calculateBestInsertion(newRoute, job, Double.MAX_VALUE); -// if(bestI instanceof InsertionData.NoInsertionFound) throw new IllegalStateException("given the vehicles, could not create a valid solution"); -// insertIn=newRoute; -// assignedJob=job; -// routeAlgorithm.insertJob(job,bestI,newRoute); -// routes.add(newRoute); -// jobs.remove(job); -// -// } -// else{ -// routeAlgorithm.insertJob(bestScoredJob.getJob(),bestScoredJob.getInsertionData(), bestScoredJob.getRoute()); -// insertIn=bestScoredJob.getRoute(); -// assignedJob=bestScoredJob.getJob(); -// jobs.remove(bestScoredJob.getJob()); -// } -// inserted++; -//// informJobInserted(assignedJob, insertIn); -// -// } -// } -// -// private double score(Job unassignedJob, InsertionData best, InsertionData secondBest) { -// if(best == null){ -// throw new IllegalStateException("cannot insert job " + unassignedJob.getId()); -// } -// if(secondBest == null){ -// return Double.MAX_VALUE; -// } -// return (secondBest.getInsertionCost()-best.getInsertionCost()) + scoringFunction.score(unassignedJob); -// -// } -// -// @Override -// public void removeListener(InsertionListener insertionListener) { -// // TODO Auto-generated method stub -// -// } -// -// @Override -// public Collection getListeners() { -// // TODO Auto-generated method stub -// return null; -// } -// -// @Override -// public void addListener(InsertionListener insertionListener) { -// // TODO Auto-generated method stub -// -// } -// -//} diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/FindCheaperVehicleTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/FindCheaperVehicleTest.java deleted file mode 100644 index 2146984c..00000000 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/FindCheaperVehicleTest.java +++ /dev/null @@ -1,256 +0,0 @@ -package jsprit.core.algorithm; -/******************************************************************************* - * 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 . - ******************************************************************************/ -//package algorithms; -// -//import static org.hamcrest.CoreMatchers.is; -//import static org.junit.Assert.assertThat; -// -//import java.util.ArrayList; -//import java.util.Collection; -// -//import org.junit.Before; -//import org.junit.Test; -// -//import util.ManhattanDistanceCalculator; -//import algorithms.FindCheaperVehicleAlgo; -//import algorithms.TourStateUpdater; -//import basics.Coordinate; -//import basics.Driver; -//import basics.Service; -//import basics.TimeWindow; -//import basics.Tour; -//import basics.TourBuilder; -//import basics.Vehicle; -//import basics.VehicleFleetManager; -//import basics.VehicleFleetManagerImpl; -//import basics.VehicleImpl; -//import basics.VehicleRoute; -//import basics.VehicleRoutingCosts; -//import basics.VehicleImpl.Type; -// -// -//public class FindCheaperVehicleTest { -// -// Tour tour; -// -// Vehicle heavyVehicle; -// -// Vehicle lightVehicle; -// -// VehicleRoutingCosts cost; -// -// @Before -// public void setUp(){ -// -// cost = new VehicleRoutingCosts() { -// -// @Override -// public double getBackwardTransportTime(String fromId, String toId, -// double arrivalTime, Driver driver, Vehicle vehicle) { -// // TODO Auto-generated method stub -// return 0; -// } -// -// @Override -// public double getBackwardTransportCost(String fromId, String toId, -// double arrivalTime, Driver driver, Vehicle vehicle) { -// // TODO Auto-generated method stub -// return 0; -// } -// -// @Override -// public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { -// -// String[] fromTokens = fromId.split(","); -// String[] toTokens = toId.split(","); -// double fromX = Double.parseDouble(fromTokens[0]); -// double fromY = Double.parseDouble(fromTokens[1]); -// -// double toX = Double.parseDouble(toTokens[0]); -// double toY = Double.parseDouble(toTokens[1]); -// -// return vehicle.getType().vehicleCostParams.perDistanceUnit*ManhattanDistanceCalculator.calculateDistance(new Coordinate(fromX, fromY), new Coordinate(toX, toY)); -// } -// -// @Override -// public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { -// return 0; -// } -// }; -// -// Type lightType = VehicleImpl.TypeBuilder.newInstance().setId("light").setCapacity(10).setFixedCost(1.0).setCostPerDistance(1.0).build(); -// lightVehicle = VehicleImpl.VehicleBuilder.newInstance("light").setLocationId("0,0").setType(lightType).build(); -// -// Type heavyType = VehicleImpl.TypeBuilder.newInstance().setId("heavy").setCapacity(10).setFixedCost(2.0).setCostPerDistance(2.0).build(); -// heavyVehicle = VehicleImpl.VehicleBuilder.newInstance("heavy").setLocationId("0,0").setType(heavyType).build(); -// } -// -// @Test -// public void runCheaperVehicle_lightIsCheaperThanHeavy_changeVehicle(){ -// TourStateUpdater tourStateCalculator = new TourStateUpdater(cost, new ExampleTransportCostFunction()); -// -// TourBuilder tourBuilder = new TourBuilder(); -// Service firstShipment = getService("10,0"); -// tourBuilder.scheduleStart("0,0", 0.0, Double.MAX_VALUE); -// tourBuilder.scheduleDeliveryService(firstShipment); -// tourBuilder.scheduleEnd("0,0", 0.0, Double.MAX_VALUE); -// -// Tour tour = tourBuilder.build(); -// -// VehicleRoute route = new VehicleRoute(tour,new Driver(){},heavyVehicle); -// tourStateCalculator.updateTour(route); -// -// Collection vehicles = new ArrayList(); -// vehicles.add(lightVehicle); -// vehicles.add(heavyVehicle); -// VehicleFleetManager fleetManager = new VehicleFleetManagerImpl(vehicles); -// fleetManager.lock(heavyVehicle); -// -// FindCheaperVehicleAlgo findCheaperVehicle = new FindCheaperVehicleAlgo(fleetManager, tourStateCalculator); -// VehicleRoute newRoute = findCheaperVehicle.runAndGetVehicleRoute(route); -// -// assertThat(lightVehicle, is(newRoute.getVehicle())); -// } -// -// @Test -// public void runCheaperVehicle_costComparisonBetweenHeavyAndLight_keepHeavy(){ -// -// -// Type lightType = VehicleImpl.TypeBuilder.newInstance().setId("light").setCapacity(10).setFixedCost(1.0).setCostPerDistance(1.0).build(); -// lightVehicle = VehicleImpl.VehicleBuilder.newInstance("light").setLocationId("0,0").setType(lightType).build(); -// -// Type heavyType = VehicleImpl.TypeBuilder.newInstance().setId("heavy").setCapacity(10).setFixedCost(2.0).setCostPerDistance(1.0).build(); -// heavyVehicle = VehicleImpl.VehicleBuilder.newInstance("heavy").setLocationId("0,0").setType(heavyType).build(); -// -// -// TourStateUpdater tourStateCalculator = new TourStateUpdater(cost, new ExampleTransportCostFunction()); -// -// TourBuilder tourBuilder = new TourBuilder(); -// Service firstShipment = getService("10,0"); -// tourBuilder.scheduleStart("0,0", 0.0, Double.MAX_VALUE); -// tourBuilder.scheduleDeliveryService(firstShipment); -// tourBuilder.scheduleEnd("0,0", 0.0, Double.MAX_VALUE); -// -// Tour tour = tourBuilder.build(); -// -// -// VehicleRoute route = new VehicleRoute(tour,new Driver(){},heavyVehicle); -// tourStateCalculator.updateTour(route); -// -// Collection vehicles = new ArrayList(); -// vehicles.add(lightVehicle); -// vehicles.add(heavyVehicle); -// VehicleFleetManager fleetManager = new VehicleFleetManagerImpl(vehicles); -// fleetManager.lock(heavyVehicle); -// -// FindCheaperVehicleAlgo findCheaperVehicle = new FindCheaperVehicleAlgo(fleetManager, tourStateCalculator); -// findCheaperVehicle.setWeightFixCosts(0.0); -// VehicleRoute newRoute = findCheaperVehicle.runAndGetVehicleRoute(route); -// -// assertThat(heavyVehicle, is(newRoute.getVehicle())); -// -// } -// -// @Test -// public void runCheaperVehicle_lightIsTheCheapest_doNotChangeVehicle(){ -// TourBuilder tourBuilder = new TourBuilder(); -// Service firstShipment = getService("10,0"); -// tourBuilder.scheduleStart("0,0", 0.0, Double.MAX_VALUE); -// tourBuilder.scheduleDeliveryService(firstShipment); -// tourBuilder.scheduleEnd("0,0", 0.0, Double.MAX_VALUE); -// -// VehicleRoute route = new VehicleRoute(tourBuilder.build(),new Driver(){},lightVehicle); -// -// Collection vehicles = new ArrayList(); -// vehicles.add(lightVehicle); -// vehicles.add(heavyVehicle); -// VehicleFleetManager fleetManager = new VehicleFleetManagerImpl(vehicles); -// fleetManager.lock(heavyVehicle); -// -// TourStateUpdater tourStateCalculator = new TourStateUpdater(cost, new ExampleTransportCostFunction()); -// FindCheaperVehicleAlgo findCheaperVehicle = new FindCheaperVehicleAlgo(fleetManager, tourStateCalculator); -// VehicleRoute newRoute = findCheaperVehicle.runAndGetVehicleRoute(route); -// -// assertThat(lightVehicle, is(newRoute.getVehicle())); -// -// -// } -// -// @Test -// public void runCheaperVehicle_noAlterativeVehicle_doNotChangeVehicle(){ -// TourBuilder tourBuilder = new TourBuilder(); -// Service firstShipment = getService("10,0"); -// tourBuilder.scheduleStart("0,0", 0.0, Double.MAX_VALUE); -// tourBuilder.scheduleDeliveryService(firstShipment); -// tourBuilder.scheduleEnd("0,0", 0.0, Double.MAX_VALUE); -// -// VehicleRoute route = new VehicleRoute(tourBuilder.build(),new Driver(){},heavyVehicle); -// -// Collection vehicles = new ArrayList(); -//// vehicles.add(lightVehicle); -// vehicles.add(heavyVehicle); -// VehicleFleetManager fleetManager = new VehicleFleetManagerImpl(vehicles); -// fleetManager.lock(heavyVehicle); -// -// TourStateUpdater tourStateCalculator = new TourStateUpdater(cost, new ExampleTransportCostFunction()); -// FindCheaperVehicleAlgo findCheaperVehicle = new FindCheaperVehicleAlgo(fleetManager, tourStateCalculator); -// VehicleRoute newRoute = findCheaperVehicle.runAndGetVehicleRoute(route); -// -// -// assertThat(heavyVehicle, is(newRoute.getVehicle())); -// -// } -// -// @Test -// public void runCheaperVehicle_noTour_throwException(){ -// TourBuilder tourBuilder = new TourBuilder(); -// Service firstShipment = getService("10,0"); -// tourBuilder.scheduleStart("0,0", 0.0, Double.MAX_VALUE); -// tourBuilder.scheduleDeliveryService(firstShipment); -// tourBuilder.scheduleEnd("0,0", 0.0, Double.MAX_VALUE); -// -// VehicleRoute route = new VehicleRoute(null,null,heavyVehicle); -// -// Collection vehicles = new ArrayList(); -//// vehicles.add(lightVehicle); -// vehicles.add(heavyVehicle); -// VehicleFleetManager fleetManager = new VehicleFleetManagerImpl(vehicles); -// fleetManager.lock(heavyVehicle); -// -// TourStateUpdater tourStateCalculator = new TourStateUpdater(cost, new ExampleTransportCostFunction()); -// FindCheaperVehicleAlgo findCheaperVehicle = new FindCheaperVehicleAlgo(fleetManager, tourStateCalculator); -// VehicleRoute newRoute = findCheaperVehicle.runAndGetVehicleRoute(route); -// -// assertThat(heavyVehicle, is(newRoute.getVehicle())); -// } -// -// private Service getService(String to, double serviceTime) { -// Service s = Service.Builder.newInstance("s", 0).setLocationId(to).setServiceTime(serviceTime).setTimeWindow(TimeWindow.newInstance(0.0, 20.0)).build(); -// return s; -// } -// -// private Service getService(String to) { -// Service s = getService(to, 0.0); -// return s; -// } -// -// -// -// -// -//} diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/GendreauPostOptTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/GendreauPostOptTest.java deleted file mode 100644 index c96ccf38..00000000 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/GendreauPostOptTest.java +++ /dev/null @@ -1,305 +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 . -// ******************************************************************************/ -//package jsprit.core.algorithm; -// -//import static org.junit.Assert.assertEquals; -// -//import java.util.ArrayList; -//import java.util.Arrays; -//import java.util.Collection; -//import java.util.List; -// -//import jsprit.core.algorithm.module.Gendreau; -//import jsprit.core.algorithm.recreate.BestInsertion; -//import jsprit.core.algorithm.recreate.InsertionStrategy; -//import jsprit.core.algorithm.recreate.JobInsertionConsideringFixCostsCalculator; -//import jsprit.core.algorithm.recreate.JobInsertionCostsCalculator; -//import jsprit.core.algorithm.recreate.LocalActivityInsertionCostsCalculator; -//import jsprit.core.algorithm.recreate.ServiceInsertionCalculator; -//import jsprit.core.algorithm.recreate.VehicleSwitched; -//import jsprit.core.algorithm.recreate.VehicleTypeDependentJobInsertionCalculator; -//import jsprit.core.algorithm.ruin.RuinRadial; -//import jsprit.core.algorithm.ruin.distance.JobDistanceAvgCosts; -//import jsprit.core.algorithm.state.StateFactory; -//import jsprit.core.algorithm.state.StateManager; -//import jsprit.core.problem.VehicleRoutingProblem; -//import jsprit.core.problem.constraint.TimeWindowConstraint; -//import jsprit.core.problem.cost.VehicleRoutingActivityCosts; -//import jsprit.core.problem.cost.VehicleRoutingTransportCosts; -//import jsprit.core.problem.driver.Driver; -//import jsprit.core.problem.driver.DriverImpl; -//import jsprit.core.problem.job.Job; -//import jsprit.core.problem.job.Service; -//import jsprit.core.problem.solution.VehicleRoutingProblemSolution; -//import jsprit.core.problem.solution.route.VehicleRoute; -//import jsprit.core.problem.solution.route.activity.ServiceActivity; -//import jsprit.core.problem.solution.route.activity.TimeWindow; -//import jsprit.core.problem.solution.route.activity.TourActivities; -//import jsprit.core.problem.vehicle.FiniteFleetManagerFactory; -//import jsprit.core.problem.vehicle.Vehicle; -//import jsprit.core.problem.vehicle.VehicleFleetManager; -//import jsprit.core.problem.vehicle.VehicleImpl; -//import jsprit.core.problem.vehicle.VehicleTypeImpl; -//import jsprit.core.util.Coordinate; -//import jsprit.core.util.ManhattanDistanceCalculator; -//import jsprit.core.util.RouteUtils; -// -//import org.junit.Before; -//import org.junit.Test; -// -// -//public class GendreauPostOptTest { -// -// TourActivities tour; -// -// Vehicle heavyVehicle; -// -// Vehicle lightVehicle1; -// -// Vehicle lightVehicle2; -// -// VehicleRoutingTransportCosts cost; -// -// VehicleRoutingActivityCosts activityCosts; -// -// VehicleRoutingProblem vrp; -// -// Service job1; -// -// Service job2; -// -// Service job3; -// -// private StateManager states; -// -// private List vehicles; -// -// private VehicleFleetManager fleetManager; -// -// private JobInsertionCostsCalculator insertionCalc; -// -// @Before -// public void setUp(){ -// -// cost = new VehicleRoutingTransportCosts() { -// -// @Override -// public double getBackwardTransportTime(String fromId, String toId, -// double arrivalTime, Driver driver, Vehicle vehicle) { -// // TODO Auto-generated method stub -// return 0; -// } -// -// @Override -// public double getBackwardTransportCost(String fromId, String toId, -// double arrivalTime, Driver driver, Vehicle vehicle) { -// // TODO Auto-generated method stub -// return 0; -// } -// -// @Override -// public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { -// -// String[] fromTokens = fromId.split(","); -// String[] toTokens = toId.split(","); -// double fromX = Double.parseDouble(fromTokens[0]); -// double fromY = Double.parseDouble(fromTokens[1]); -// -// double toX = Double.parseDouble(toTokens[0]); -// double toY = Double.parseDouble(toTokens[1]); -// -// double costPerDistanceUnit; -// if(vehicle != null){ -// costPerDistanceUnit = vehicle.getType().getVehicleCostParams().perDistanceUnit; -// } -// else{ -// costPerDistanceUnit = 1; -// } -// -// return costPerDistanceUnit*ManhattanDistanceCalculator.calculateDistance(new Coordinate(fromX, fromY), new Coordinate(toX, toY)); -// } -// -// @Override -// public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { -// return 0; -// } -// }; -// -// VehicleTypeImpl lightType = VehicleTypeImpl.Builder.newInstance("light", 10).setFixedCost(10).setCostPerDistance(1.0).build(); -// VehicleTypeImpl heavyType = VehicleTypeImpl.Builder.newInstance("heavy", 10).setFixedCost(30).setCostPerDistance(2.0).build(); -// -// lightVehicle1 = VehicleImpl.Builder.newInstance("light").setLocationId("0,0").setType(lightType).build(); -// lightVehicle2 = VehicleImpl.Builder.newInstance("light2").setLocationId("0,0").setType(lightType).build(); -// heavyVehicle = VehicleImpl.Builder.newInstance("heavy").setLocationId("0,0").setType(heavyType).build(); -// -// -// job1 = getService("10,0"); -// job2 = getService("10,10"); -// job3 = getService("0,10"); -// -// Collection jobs = new ArrayList(); -// jobs.add(job1); -// jobs.add(job2); -// jobs.add(job3); -// -// vehicles = Arrays.asList(lightVehicle1,lightVehicle2, heavyVehicle); -// -//// Collection vehicles = Arrays.asList(lightVehicle1,lightVehicle2, heavyVehicle); -// fleetManager = new FiniteFleetManagerFactory(vehicles).createFleetManager(); -// states = new StateManager(); -// -// activityCosts = new ExampleActivityCostFunction(); -// -// -// ServiceInsertionCalculator standardServiceInsertion = new ServiceInsertionCalculator(cost, new LocalActivityInsertionCostsCalculator(cost, activityCosts), new LoadConstraint(states), new TimeWindowConstraint(states, cost)); -// -// -// -// -// JobInsertionConsideringFixCostsCalculator withFixCost = new JobInsertionConsideringFixCostsCalculator(standardServiceInsertion, states); -// withFixCost.setWeightOfFixCost(1.2); -// -// insertionCalc = new VehicleTypeDependentJobInsertionCalculator(fleetManager, withFixCost); -// -//// updater = new TourStateUpdater(states, cost, activityCosts); -// -// } -// -// @Test -// public void whenPostOpt_splitsTour_oneActiveTourBecomeTwoSeperateActiveTours(){ -// Collection jobs = new ArrayList(); -// jobs.add(job1); -// jobs.add(job2); -// -// vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addAllVehicles(vehicles).setRoutingCost(cost).build(); -// -// TourActivities tour = new TourActivities(); -// tour.addActivity(ServiceActivity.newInstance(job1)); -// tour.addActivity(ServiceActivity.newInstance(job2)); -// -// VehicleRoute route = VehicleRoute.newInstance(tour,DriverImpl.noDriver(),heavyVehicle); -// -// fleetManager.lock(heavyVehicle); -// -// UpdateStates stateUpdater = new UpdateStates(states, vrp.getTransportCosts(), vrp.getActivityCosts()); -// stateUpdater.update(route); -// -// Collection routes = new ArrayList(); -// routes.add(route); -//// routes.add(new VehicleRoute(getEmptyTour(),getDriver(),getNoVehicle())); -//// routes.add(new VehicleRoute(getEmptyTour(),getDriver(),getNoVehicle())); -// -// -// VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(routes, states.getRouteState(route, StateFactory.COSTS).toDouble() + getFixedCosts(routes)); -// -// -// assertEquals(110.0, sol.getCost(), 0.5); -// -// -// RuinRadial radialRuin = new RuinRadial(vrp, 0.2, new JobDistanceAvgCosts(vrp.getTransportCosts())); -//// radialRuin.addListener(stateUpdater); -// -// InsertionStrategy insertionStrategy = new BestInsertion(insertionCalc); -// insertionStrategy.addListener(stateUpdater); -// insertionStrategy.addListener(new VehicleSwitched(fleetManager)); -// Gendreau postOpt = new Gendreau(vrp, radialRuin, insertionStrategy, fleetManager); -// -// VehicleRoutingProblemSolution newSolution = postOpt.runAndGetSolution(sol); -// newSolution.setCost(getCosts(newSolution,states)); -// -// assertEquals(2,RouteUtils.getNuOfActiveRoutes(newSolution.getRoutes())); -// assertEquals(2,newSolution.getRoutes().size()); -// assertEquals(80.0,newSolution.getCost(),0.5); -// } -// -// private double getFixedCosts(Collection routes) { -// double c = 0.0; -// for(VehicleRoute r : routes){ c += r.getVehicle().getType().getVehicleCostParams().fix; } -// return c; -// } -// -// private double getCosts(VehicleRoutingProblemSolution newSolution, StateManager states) { -// double c = 0.0; -// for(VehicleRoute r : newSolution.getRoutes()){ -// -// c += states.getRouteState(r, StateFactory.COSTS).toDouble() + r.getVehicle().getType().getVehicleCostParams().fix; -// -// } -// return c; -// } -// -// @Test -// public void whenPostOpt_optsRoutesWithMoreThanTwoJobs_oneRouteBecomesTwoRoutes(){ -// Collection jobs = new ArrayList(); -// jobs.add(job1); -// jobs.add(job2); -// jobs.add(job3); -// -// vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addAllVehicles(vehicles).setRoutingCost(cost).build(); -// -// TourActivities tour = new TourActivities(); -// tour.addActivity(ServiceActivity.newInstance(job1)); -// tour.addActivity(ServiceActivity.newInstance(job2)); -// tour.addActivity(ServiceActivity.newInstance(job3)); -// -// VehicleRoute route = VehicleRoute.newInstance(tour,DriverImpl.noDriver(),heavyVehicle); -// -// UpdateStates stateUpdater = new UpdateStates(states, vrp.getTransportCosts(), vrp.getActivityCosts()); -// stateUpdater.update(route); -// -// fleetManager.lock(heavyVehicle); -// -// Collection routes = new ArrayList(); -// routes.add(route); -// -// VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(routes, route.getCost()); -// sol.setCost(getCosts(sol,states)); -// -// assertEquals(110.0, sol.getCost(), 0.5); -// -// RuinRadial radialRuin = new RuinRadial(vrp, 0.2, new JobDistanceAvgCosts(vrp.getTransportCosts())); -// InsertionStrategy insertionStrategy = new BestInsertion(insertionCalc); -// insertionStrategy.addListener(stateUpdater); -// insertionStrategy.addListener(new VehicleSwitched(fleetManager)); -// Gendreau postOpt = new Gendreau(vrp, radialRuin, insertionStrategy, fleetManager); -// postOpt.setShareOfJobsToRuin(1.0); -// postOpt.setNuOfIterations(1); -// -//// postOpt.setWithFix(withFixCost); -// VehicleRoutingProblemSolution newSolution = postOpt.runAndGetSolution(sol); -// newSolution.setCost(getCosts(newSolution,states)); -// -// assertEquals(2,RouteUtils.getNuOfActiveRoutes(newSolution.getRoutes())); -// assertEquals(2,newSolution.getRoutes().size()); -// assertEquals(80.0,newSolution.getCost(),0.5); -// } -// -// private Service getService(String to, double serviceTime) { -// Service s = Service.Builder.newInstance(to, 0).setLocationId(to).setServiceTime(serviceTime).setTimeWindow(TimeWindow.newInstance(0.0, 20.0)).build(); -// -// return s; -// } -// -// private Service getService(String to) { -// Service s = getService(to, 0.0); -// return s; -// } -// -// -// -// -//} diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestAuxilliaryCostCalculatorWithServices.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestAuxilliaryCostCalculatorWithServices.java deleted file mode 100644 index 4f332cd4..00000000 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestAuxilliaryCostCalculatorWithServices.java +++ /dev/null @@ -1,215 +0,0 @@ -package jsprit.core.algorithm.recreate; -/******************************************************************************* - * 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 . - ******************************************************************************/ -//package algorithms; -// -//import java.util.ArrayList; -//import java.util.Collection; -//import java.util.List; -// -//import junit.framework.TestCase; -// -//import org.junit.Test; -// -//import util.EuclideanDistanceCalculator; -//import basics.Coordinate; -//import basics.Driver; -//import basics.Job; -//import basics.Service; -//import basics.TimeWindow; -//import basics.Tour; -//import basics.TourActivity; -//import basics.TourBuilder; -//import basics.Vehicle; -//import basics.VehicleRoutingTransportCosts; - -// -// -//public class TestAuxilliaryCostCalculatorWithServices extends TestCase{ -// -// AuxilliaryCostCalculator costCalc; -// -// Tour tour; -// -// public void setUp(){ -// -// VehicleRoutingTransportCosts cost = new VehicleRoutingTransportCosts() { -// -// @Override -// public double getBackwardTransportTime(String fromId, String toId, -// double arrivalTime, Driver driver, Vehicle vehicle) { -// // TODO Auto-generated method stub -// return 0; -// } -// -// @Override -// public double getBackwardTransportCost(String fromId, String toId, -// double arrivalTime, Driver driver, Vehicle vehicle) { -// // TODO Auto-generated method stub -// return 0; -// } -// -// @Override -// public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { -// String[] fromTokens = fromId.split(","); -// String[] toTokens = toId.split(","); -// double fromX = Double.parseDouble(fromTokens[0]); -// double fromY = Double.parseDouble(fromTokens[1]); -// -// double toX = Double.parseDouble(toTokens[0]); -// double toY = Double.parseDouble(toTokens[1]); -// -// return EuclideanDistanceCalculator.calculateDistance(new Coordinate(fromX, fromY), new Coordinate(toX, toY)); -// } -// -// @Override -// public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { -// -// return 0; -// } -// }; -// -// costCalc = AuxilliaryCostCalculator.newInstance(cost, new ExampleTransportCostFunction()); -// -// Service firstService = Service.Builder.newInstance("1", 0).setLocationId("10,0").setTimeWindow(TimeWindow.newInstance(0, 20)).build(); -// Service secondService = Service.Builder.newInstance("2", 0).setLocationId("0,10").setTimeWindow(TimeWindow.newInstance(0, 20)).build(); -// -// Collection services = new ArrayList(); -// services.add(firstService); -// services.add(secondService); -// -// ActivityStates states = new ActivityStates(); -// states.initialiseStateOfJobs(services); -// -// TourBuilder tourBuilder = new TourBuilder(); -// -// tourBuilder.scheduleStart("0,0", 0.0, Double.MAX_VALUE); -// tourBuilder.addActivity(states.getActivity(firstService,true)); -// tourBuilder.addActivity(states.getActivity(secondService,true)); -// tourBuilder.scheduleEnd("0,0", 0.0, Double.MAX_VALUE); -// -// tour = tourBuilder.build(); -// costCalc.setActivityStates(states); -// -// } -// -//// @Test -//// public void testGetPath(){ -//// List path = AuxilliaryCostCalculator.getPath(tour,tour.getStart(), tour.getActivities().get(1)); -//// assertEquals(3,path.size()); -//// } -//// -//// @Test -//// public void testGetPath_withEnd(){ -//// List path = AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(0), tour.getEnd()); -//// assertEquals(3,path.size()); -//// } -// -// -//// public void testCalcTourCost(){ -//// List path = AuxilliaryCostCalculator.getPath(tour,tour.getStart(), tour.getActivities().get(1)); -//// assertEquals(0.0, costCalc.costOfPath(path,0.0,null,null)); -//// } -// -//// public void testCalcTourCost2(){ -//// assertEquals(10.0, costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(0), tour.getActivities().get(2)),0.0,null,null)); -//// } -//// -//// public void testCalcTourCost3(){ -//// assertEquals(20.0, costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(2), tour.getActivities().get(6)),0.0,null,null)); -//// } -//// -//// public void testCalcTourCost4(){ -//// assertEquals(30.0, costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(0), tour.getActivities().get(6)),0.0,null,null)); -//// } -//// -//// public void testCalcTourCost5(){ -//// assertEquals(40.0, costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(1), tour.getActivities().get(7)),0.0,null,null)); -//// } -// -//// public void testCalcTourCost6(){ -//// assertEquals(0.0, costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(1), tour.getActivities().get(1)),0.0,null,null)); -//// } -//// -//// public void testCalcTourCost7(){ -//// try{ -//// double c =costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(1), tour.getActivities().get(0)),0.0,null,null); -//// assertTrue(false); -//// } -//// catch(AssertionError e){ -//// assertTrue(true); -//// } -//// catch(IllegalArgumentException e){ -//// assertTrue(true); -//// } -//// } -//// -//// public void testCalcTourCost8(){ -//// try{ -//// Shipment s = getShipment("10,10","0,10"); -//// TourActivity pickup = new Pickup(s); -//// -//// double c = costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(0), pickup),0.0,null,null); -//// assertTrue(false); -//// } -//// catch(AssertionError e){ -//// assertTrue(true); -//// } -//// catch(IllegalArgumentException e){ -//// assertTrue(true); -//// } -//// } -//// -//// public void testBoundary1(){ -//// assertEquals(40.0, costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(1), tour.getActivities().get(tour.getActivities().size()-1)),0.0,null,null)); -//// } -//// -//// public void testBoundary2(){ -//// try{ -//// costCalc.costOfPath(AuxilliaryCostCalculator.getPath(tour,tour.getActivities().get(tour.getActivities().size()-1), tour.getActivities().get(0)),0.0,null,null); -//// assertTrue(false); -//// } -//// catch(AssertionError e){ -//// assertTrue(true); -//// } -//// catch(IllegalArgumentException e){ -//// assertTrue(true); -//// } -//// } -//// -////// public void testBoundary3(){ -////// assertEquals(40.0, costCalc.calculateCost(tour, tour.getActivities().getFirst(), tour.getActivities().getLast(), Double.MAX_VALUE, null, null)); -////// } -////// -////// public void testBoundary4(){ -////// try{ -////// costCalc.calculateCost(tour, tour.getActivities().getFirst(), tour.getActivities().getLast(), (-1)*Double.MAX_VALUE, null, null); -////// assertTrue(false); -////// } -////// catch(AssertionError e){ -////// assertTrue(true); -////// } -////// } -//// -//// -//// -//// private Shipment getShipment(String string, String string2) { -//// Shipment s = Shipment.Builder.newInstance("first", 0).setFromId(string).setToId(string2).setPickupTW(TimeWindow.newInstance(0.0, 20.0)).setDeliveryTW(TimeWindow.newInstance(0.0, 20.0)).build(); -//// return s; -//// } -//// -//}