diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/VehicleRoutingAlgorithm.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/VehicleRoutingAlgorithm.java index ca82ddd5..37918884 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/VehicleRoutingAlgorithm.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/VehicleRoutingAlgorithm.java @@ -25,6 +25,7 @@ import com.graphhopper.jsprit.core.algorithm.listener.VehicleRoutingAlgorithmLis import com.graphhopper.jsprit.core.algorithm.termination.PrematureAlgorithmTermination; import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; import com.graphhopper.jsprit.core.problem.job.Job; +import com.graphhopper.jsprit.core.problem.solution.SolutionCostCalculator; import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution; import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute; import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; @@ -43,6 +44,8 @@ import java.util.Collection; */ public class VehicleRoutingAlgorithm { + + private static class TerminationManager implements PrematureAlgorithmTermination { private Collection terminationCriteria = new ArrayList(); @@ -105,11 +108,14 @@ public class VehicleRoutingAlgorithm { private VehicleRoutingProblemSolution bestEver = null; + private final SolutionCostCalculator objectiveFunction; + public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, SearchStrategyManager searchStrategyManager) { super(); this.problem = problem; this.searchStrategyManager = searchStrategyManager; initialSolutions = new ArrayList(); + objectiveFunction = null; } public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, Collection initialSolutions, SearchStrategyManager searchStrategyManager) { @@ -117,6 +123,15 @@ public class VehicleRoutingAlgorithm { this.problem = problem; this.searchStrategyManager = searchStrategyManager; this.initialSolutions = initialSolutions; + objectiveFunction = null; + } + + public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, SearchStrategyManager searchStrategyManager, SolutionCostCalculator objectiveFunction) { + super(); + this.problem = problem; + this.searchStrategyManager = searchStrategyManager; + initialSolutions = new ArrayList(); + this.objectiveFunction = objectiveFunction; } /** @@ -319,5 +334,8 @@ public class VehicleRoutingAlgorithm { return maxIterations; } + public SolutionCostCalculator getObjectiveFunction(){ + return objectiveFunction; + } } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java index 5df8bd71..818767f2 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java @@ -588,6 +588,7 @@ public class Jsprit { } else { prettyBuilder.constructInitialSolutionWith(regret, objectiveFunction); } + prettyBuilder.withObjectiveFunction(objectiveFunction); VehicleRoutingAlgorithm vra = prettyBuilder.build();