Class VehicleRoutingAlgorithm
VehicleRoutingProblem.- Author:
- stefan schroeder
-
Constructor Summary
ConstructorsConstructorDescriptionVehicleRoutingAlgorithm(VehicleRoutingProblem problem, SearchStrategyManager searchStrategyManager) VehicleRoutingAlgorithm(VehicleRoutingProblem problem, SearchStrategyManager searchStrategyManager, SolutionCostCalculator objectiveFunction) VehicleRoutingAlgorithm(VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> initialSolutions, SearchStrategyManager searchStrategyManager) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEventListener(AlgorithmEventListener listener) Adds an event listener for receiving algorithm events.voidAdds a solution spec as an initial solution.voidAdds solution to the collection of initial solutions.voidvoidaddTerminationCriterion(PrematureAlgorithmTermination terminationCriterion) Adds a termination criterion to the collection of already specified termination criteria.voidemit(AlgorithmEvent event) Emits an event to all registered event listeners.intGets max number of iterations.Gets theSearchStrategyManager.booleanReturns whether any event listeners are registered.voidremoveEventListener(AlgorithmEventListener listener) Removes an event listener.Runs the vehicle routing algorithm and returns a number of generated solutions.voidsetMaxIterations(int maxIterations) Sets max number of iterations.voidsetPrematureAlgorithmTermination(PrematureAlgorithmTermination prematureAlgorithmTermination) Sets premature termination and overrides existing termination criteria.
-
Constructor Details
-
VehicleRoutingAlgorithm
public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, SearchStrategyManager searchStrategyManager) -
VehicleRoutingAlgorithm
public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> initialSolutions, SearchStrategyManager searchStrategyManager) -
VehicleRoutingAlgorithm
public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, SearchStrategyManager searchStrategyManager, SolutionCostCalculator objectiveFunction)
-
-
Method Details
-
addInitialSolution
Adds solution to the collection of initial solutions. This method may lead to errors if tour activities in the solution are different to the ones in the VRP (including differences in indexing)- Parameters:
solution- the solution to be added
-
addInitialSolution
Adds a solution spec as an initial solution.The spec will be materialized into a solution using the VRP's vehicles and jobs. This is the preferred way to provide an initial solution as it avoids issues with activity indexing and object references.
Unlike locked routes set via
VRP.Builder.setInitialRouteSpecs(), this initial solution is fully optimizable - jobs can be moved between routes freely.- Parameters:
spec- the solution specification- Throws:
IllegalArgumentException- if the spec references missing vehicles or jobs
-
setPrematureAlgorithmTermination
public void setPrematureAlgorithmTermination(PrematureAlgorithmTermination prematureAlgorithmTermination) Sets premature termination and overrides existing termination criteria. If existing ones should not be overridden use.addTerminationCriterion(...).- Parameters:
prematureAlgorithmTermination- the termination criterion
-
addTerminationCriterion
Adds a termination criterion to the collection of already specified termination criteria. If one of the termination criteria is fulfilled, the algorithm terminates prematurely.- Parameters:
terminationCriterion- the termination criterion
-
getSearchStrategyManager
Gets theSearchStrategyManager.- Returns:
- SearchStrategyManager
-
searchSolutions
Runs the vehicle routing algorithm and returns a number of generated solutions.The algorithm runs as long as it is specified in nuOfIterations and prematureBreak. In each iteration it selects a searchStrategy according to searchStrategyManager and runs the strategy to improve solutions.
Note that clients are allowed to observe/listen the algorithm. See
VehicleRoutingAlgorithmListenerand its according listeners.- Returns:
- Collection
the solutions
-
getAlgorithmListeners
-
addListener
-
addEventListener
Adds an event listener for receiving algorithm events.Event listeners provide a unified way to observe all aspects of the algorithm's execution, including iteration lifecycle, ruin/recreate phases, and acceptance decisions.
- Parameters:
listener- the event listener to add
-
removeEventListener
Removes an event listener.- Parameters:
listener- the event listener to remove
-
emit
Emits an event to all registered event listeners.This method is intended for internal use by the algorithm and its components. It has minimal overhead when no listeners are registered.
- Parameters:
event- the event to emit
-
hasEventListeners
public boolean hasEventListeners()Returns whether any event listeners are registered.This can be used to avoid creating event objects when no listeners are registered, minimizing performance overhead.
- Returns:
- true if at least one event listener is registered
-
setMaxIterations
public void setMaxIterations(int maxIterations) Sets max number of iterations.- Parameters:
maxIterations- max number of iteration the algorithm runs
-
getMaxIterations
public int getMaxIterations()Gets max number of iterations.- Returns:
- max number of iterations
-
getObjectiveFunction
-