1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

make objective function available from algorithm

This commit is contained in:
oblonski 2016-08-02 20:14:58 +02:00
parent 91298022ab
commit 1cbdb353f0
2 changed files with 19 additions and 0 deletions

View file

@ -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<PrematureAlgorithmTermination> terminationCriteria = new ArrayList<PrematureAlgorithmTermination>();
@ -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<VehicleRoutingProblemSolution>();
objectiveFunction = null;
}
public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> 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<VehicleRoutingProblemSolution>();
this.objectiveFunction = objectiveFunction;
}
/**
@ -319,5 +334,8 @@ public class VehicleRoutingAlgorithm {
return maxIterations;
}
public SolutionCostCalculator getObjectiveFunction(){
return objectiveFunction;
}
}

View file

@ -588,6 +588,7 @@ public class Jsprit {
} else {
prettyBuilder.constructInitialSolutionWith(regret, objectiveFunction);
}
prettyBuilder.withObjectiveFunction(objectiveFunction);
VehicleRoutingAlgorithm vra = prettyBuilder.build();