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:
parent
91298022ab
commit
1cbdb353f0
2 changed files with 19 additions and 0 deletions
|
|
@ -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.algorithm.termination.PrematureAlgorithmTermination;
|
||||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
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.VehicleRoutingProblemSolution;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
||||||
|
|
@ -43,6 +44,8 @@ import java.util.Collection;
|
||||||
*/
|
*/
|
||||||
public class VehicleRoutingAlgorithm {
|
public class VehicleRoutingAlgorithm {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static class TerminationManager implements PrematureAlgorithmTermination {
|
private static class TerminationManager implements PrematureAlgorithmTermination {
|
||||||
|
|
||||||
private Collection<PrematureAlgorithmTermination> terminationCriteria = new ArrayList<PrematureAlgorithmTermination>();
|
private Collection<PrematureAlgorithmTermination> terminationCriteria = new ArrayList<PrematureAlgorithmTermination>();
|
||||||
|
|
@ -105,11 +108,14 @@ public class VehicleRoutingAlgorithm {
|
||||||
|
|
||||||
private VehicleRoutingProblemSolution bestEver = null;
|
private VehicleRoutingProblemSolution bestEver = null;
|
||||||
|
|
||||||
|
private final SolutionCostCalculator objectiveFunction;
|
||||||
|
|
||||||
public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, SearchStrategyManager searchStrategyManager) {
|
public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, SearchStrategyManager searchStrategyManager) {
|
||||||
super();
|
super();
|
||||||
this.problem = problem;
|
this.problem = problem;
|
||||||
this.searchStrategyManager = searchStrategyManager;
|
this.searchStrategyManager = searchStrategyManager;
|
||||||
initialSolutions = new ArrayList<VehicleRoutingProblemSolution>();
|
initialSolutions = new ArrayList<VehicleRoutingProblemSolution>();
|
||||||
|
objectiveFunction = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> initialSolutions, SearchStrategyManager searchStrategyManager) {
|
public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> initialSolutions, SearchStrategyManager searchStrategyManager) {
|
||||||
|
|
@ -117,6 +123,15 @@ public class VehicleRoutingAlgorithm {
|
||||||
this.problem = problem;
|
this.problem = problem;
|
||||||
this.searchStrategyManager = searchStrategyManager;
|
this.searchStrategyManager = searchStrategyManager;
|
||||||
this.initialSolutions = initialSolutions;
|
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;
|
return maxIterations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SolutionCostCalculator getObjectiveFunction(){
|
||||||
|
return objectiveFunction;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -588,6 +588,7 @@ public class Jsprit {
|
||||||
} else {
|
} else {
|
||||||
prettyBuilder.constructInitialSolutionWith(regret, objectiveFunction);
|
prettyBuilder.constructInitialSolutionWith(regret, objectiveFunction);
|
||||||
}
|
}
|
||||||
|
prettyBuilder.withObjectiveFunction(objectiveFunction);
|
||||||
|
|
||||||
|
|
||||||
VehicleRoutingAlgorithm vra = prettyBuilder.build();
|
VehicleRoutingAlgorithm vra = prettyBuilder.build();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue