Class AlgorithmEventAdapter
java.lang.Object
com.graphhopper.jsprit.core.algorithm.listener.AlgorithmEventAdapter
- All Implemented Interfaces:
IterationStartsListener,SearchStrategyModuleListener,StrategySelectedListener,VehicleRoutingAlgorithmListener,InsertionEndsListener,InsertionListener,InsertionStartsListener,JobInsertedListener,JobUnassignedListener,RuinListener
public class AlgorithmEventAdapter
extends Object
implements VehicleRoutingAlgorithmListener, IterationStartsListener, StrategySelectedListener, RuinListener, InsertionStartsListener, JobInsertedListener, JobUnassignedListener, InsertionEndsListener
Adapter that bridges the existing fragmented listener interfaces to the unified event system.
This adapter implements all the existing listener interfaces (RuinListener, JobInsertedListener, etc.) and translates their callbacks into unified AlgorithmEvent instances that are emitted via the VehicleRoutingAlgorithm's event system.
Usage:
VehicleRoutingAlgorithm algorithm = ...;
AlgorithmEventAdapter adapter = new AlgorithmEventAdapter(algorithm);
algorithm.addListener(adapter);
// Now add event listeners for the unified events
algorithm.addEventListener(event -> {
switch (event) {
case JobRemoved e -> System.out.println("Job removed: " + e.job().getId());
case JobInserted e -> System.out.println("Job inserted: " + e.job().getId());
default -> {}
}
});
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidinformInsertionEnds(Collection<VehicleRoute> vehicleRoutes, Collection<Job> badJobs) voidinformInsertionStarts(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) voidinformIterationStarts(int i, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) voidinformJobInserted(Job job, VehicleRoute inRoute, InsertionData insertionData) voidinformJobUnassigned(Job unassigned, Collection<String> failedConstraintNames) voidinformSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) voidremoved(Job job, VehicleRoute fromRoute) informs if aJobhas been removed from aVehicleRoute.voidruinEnds(Collection<VehicleRoute> routes, Collection<Job> unassignedJobs) informs about ruin-end.voidruinStarts(Collection<VehicleRoute> routes) informs about ruin-start.voidSets the name of the current insertion strategy (for event metadata).voidsetRuinStrategyName(String name) Sets the name of the current ruin strategy (for event metadata).
-
Constructor Details
-
AlgorithmEventAdapter
-
-
Method Details
-
setRuinStrategyName
Sets the name of the current ruin strategy (for event metadata). -
setInsertionStrategyName
Sets the name of the current insertion strategy (for event metadata). -
informIterationStarts
public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) - Specified by:
informIterationStartsin interfaceIterationStartsListener
-
informSelectedStrategy
public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) - Specified by:
informSelectedStrategyin interfaceStrategySelectedListener
-
ruinStarts
Description copied from interface:RuinListenerinforms about ruin-start.- Specified by:
ruinStartsin interfaceRuinListener- Parameters:
routes-
-
removed
Description copied from interface:RuinListenerinforms if aJobhas been removed from aVehicleRoute.- Specified by:
removedin interfaceRuinListener- Parameters:
job-fromRoute-
-
ruinEnds
Description copied from interface:RuinListenerinforms about ruin-end.- Specified by:
ruinEndsin interfaceRuinListener- Parameters:
routes-unassignedJobs-
-
informInsertionStarts
public void informInsertionStarts(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) - Specified by:
informInsertionStartsin interfaceInsertionStartsListener
-
informJobInserted
- Specified by:
informJobInsertedin interfaceJobInsertedListener
-
informJobUnassigned
- Specified by:
informJobUnassignedin interfaceJobUnassignedListener
-
informInsertionEnds
- Specified by:
informInsertionEndsin interfaceInsertionEndsListener
-