From c3155a0938812d4d5fb316c831c9119671cfcdd6 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Sat, 9 Aug 2014 23:17:41 +0200
Subject: [PATCH] add bad job list
---
.../NeighborhoodThresholdInitialiser.java | 125 ------------------
...lusFixedSolutionCostCalculatorFactory.java | 2 +-
.../core/problem/VehicleRoutingProblem.java | 4 +
.../jsprit/examples/BicycleMessenger.java | 2 +-
...ltipleDepotExampleWithPenaltyVehicles.java | 2 +-
5 files changed, 7 insertions(+), 128 deletions(-)
delete mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/NeighborhoodThresholdInitialiser.java
diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/NeighborhoodThresholdInitialiser.java b/jsprit-core/src/main/java/jsprit/core/algorithm/NeighborhoodThresholdInitialiser.java
deleted file mode 100644
index 183a659d..00000000
--- a/jsprit-core/src/main/java/jsprit/core/algorithm/NeighborhoodThresholdInitialiser.java
+++ /dev/null
@@ -1,125 +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 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.*;
-import org.apache.commons.math.stat.descriptive.moment.Mean;
-import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.util.Collection;
-
-
-class NeighborhoodThresholdInitialiser implements AlgorithmStartsListener{
-
- private static Logger log = LogManager.getLogger(NeighborhoodThresholdInitialiser.class);
-
- private NeighborhoodImpl neighborhood;
-
- private VehicleRoutingAlgorithmFactory routingAlgorithmFactory = new VehicleRoutingAlgorithmFactory() {
-
- @Override
- public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) {
- VehicleRoutingAlgorithm algorithm = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "resources/config.xml");
- return algorithm;
- }
- };
-
- private int crowFlySpeed = 20;
-
- public NeighborhoodThresholdInitialiser(NeighborhoodImpl neighborhood) {
- this.neighborhood = neighborhood;
- }
-
-
- /**
- * @param crowFlySpeed the crowFlySpeed to set
- */
- public void setCrowFlySpeed(int crowFlySpeed) {
- this.crowFlySpeed = crowFlySpeed;
- }
-
-
- /**
- * @param routingAlgorithmFactory the routingAlgorithm to set
- */
- public void setRoutingAlgorithmFactory(VehicleRoutingAlgorithmFactory routingAlgorithmFactory) {
- this.routingAlgorithmFactory = routingAlgorithmFactory;
- }
-
- public void initialise(VehicleRoutingProblem problem){
- informAlgorithmStarts(problem, null, null);
- }
-
- @Override
- public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) {
- VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
- builder.addAllJobs(problem.getJobs().values());
- builder.addAllVehicles(problem.getVehicles());
- CrowFlyCosts crowFly = new CrowFlyCosts(builder.getLocations());
- crowFly.speed = crowFlySpeed;
- builder.setRoutingCost(crowFly);
- VehicleRoutingProblem pblm = builder.build();
-
- VehicleRoutingAlgorithm algo = routingAlgorithmFactory.createAlgorithm(pblm);
- Collection mySolutions = algo.searchSolutions();
-
- double threshold = determineThreshold(pblm,builder.getLocations(), mySolutions);
- neighborhood.setThreshold(threshold);
- neighborhood.initialise();
- }
-
- private double determineThreshold(VehicleRoutingProblem pblm, Locations locations, Collection mySolutions) {
- VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(mySolutions);
- double[] distances = new double[bestSolution.getRoutes().size()+pblm.getJobs().size()];
- getDistances(distances,bestSolution,locations);
- Mean mean = new Mean();
- double meanValue = mean.evaluate(distances);
- StandardDeviation dev = new StandardDeviation();
- double devValue = dev.evaluate(distances, meanValue);
- log.info("mean="+meanValue+", dev="+devValue);
- return meanValue + devValue;
-// + 2*devValue;
-// return Double.MAX_VALUE;
- }
-
- private void getDistances(double[] distances, VehicleRoutingProblemSolution bestSolution, Locations locations) {
- int index = 0;
- for(VehicleRoute route : bestSolution.getRoutes()){
- TourActivity prev = null;
- for(TourActivity act : route.getTourActivities().getActivities()){
- if(prev == null){ prev = act; continue; }
- double dist = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(prev.getLocationId()), locations.getCoord(act.getLocationId()));
-// log.info("dist="+dist);
- distances[index] = dist;
- index++;
- prev = act;
- }
-// double dist = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(prev.getLocationId()), locations.getCoord(route.getEnd().getLocationId()));
-// distances[index] = dist;
-// index++;
- }
- }
-
-}
diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/VariablePlusFixedSolutionCostCalculatorFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/VariablePlusFixedSolutionCostCalculatorFactory.java
index 2ab22785..8a061faf 100644
--- a/jsprit-core/src/main/java/jsprit/core/algorithm/VariablePlusFixedSolutionCostCalculatorFactory.java
+++ b/jsprit-core/src/main/java/jsprit/core/algorithm/VariablePlusFixedSolutionCostCalculatorFactory.java
@@ -52,7 +52,7 @@ public class VariablePlusFixedSolutionCostCalculatorFactory {
c += stateManager.getRouteState(r, InternalStates.COSTS, Double.class);
c += getFixedCosts(r.getVehicle());
}
- c += solution.getBadJobs().size() * c * .1;
+ c += solution.getBadJobs().size() * c * .05;
return c;
}
diff --git a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java
index f4404433..ee48759b 100644
--- a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java
+++ b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java
@@ -526,7 +526,9 @@ public class VehicleRoutingProblem {
*
* @param penaltyFactor penaltyFactor of penaltyVehicle
* @return this builder
+ * @deprecated since 1.3.2-SNAPSHOT bad job list replaces penalty vehicles
*/
+ @Deprecated
public Builder addPenaltyVehicles(double penaltyFactor){
this.addPenaltyVehicles = true;
this.penaltyFactor = penaltyFactor;
@@ -543,7 +545,9 @@ public class VehicleRoutingProblem {
* @param penaltyFactor the penaltyFactor of penaltyVehicle
* @param penaltyFixedCosts which is an absolute penaltyValue (in contrary to penaltyFactor)
* @return this builder
+ * @deprecated since 1.3.2-SNAPSHOT bad job list replaces penalty vehicles
*/
+ @Deprecated
public Builder addPenaltyVehicles(double penaltyFactor, double penaltyFixedCosts){
this.addPenaltyVehicles = true;
this.penaltyFactor = penaltyFactor;
diff --git a/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java b/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java
index 513c603f..818e609d 100644
--- a/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java
+++ b/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java
@@ -272,7 +272,7 @@ public class BicycleMessenger {
vraBuilder.addDefaultCostCalculators();
vraBuilder.setStateAndConstraintManager(stateManager, constraintManager);
VehicleRoutingAlgorithm algorithm = vraBuilder.build();
- algorithm.setMaxIterations(2000);
+ algorithm.setMaxIterations(5000);
VariationCoefficientTermination prematureAlgorithmTermination = new VariationCoefficientTermination(200, 0.001);
// algorithm.setPrematureAlgorithmTermination(prematureAlgorithmTermination);
// algorithm.addListener(prematureAlgorithmTermination);
diff --git a/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExampleWithPenaltyVehicles.java b/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExampleWithPenaltyVehicles.java
index e255418b..6aa3d626 100644
--- a/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExampleWithPenaltyVehicles.java
+++ b/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExampleWithPenaltyVehicles.java
@@ -105,7 +105,7 @@ public class MultipleDepotExampleWithPenaltyVehicles {
* solve the problem
*/
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig.xml");
- vra.setMaxIterations(2000);
+ vra.setMaxIterations(5000);
vra.getAlgorithmListeners().addListener(new StopWatch(),Priority.HIGH);
vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/progress.png"));
Collection solutions = vra.searchSolutions();