Class AdaptiveSpatialFilter
During the learning phase, it compares filtered vs full search results to determine: - Hit rate: How often filtering finds the same best route as full search - Cost deviation: When filtering misses, how much worse is the cost - Miss rate: How often filtering misses feasible insertions entirely
Based on learning results, it adaptively enables/disables filtering: - If filtering works well (high hit rate, low cost deviation): use 95% filtering - If filtering works partially: use 50% filtering with larger k - If filtering doesn't work: disable entirely
Thread-safety: This class is NOT thread-safe. Each thread should have its own instance, or external synchronization is required.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classResult of filtering decision. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an adaptive spatial filter with default settings.AdaptiveSpatialFilter(int learningRounds, int initialK) Creates an adaptive spatial filter. -
Method Summary
Modifier and TypeMethodDescriptionintgetK()Returns the current k value (number of nearest routes to consider).getNearestRoutes(Job job, Collection<VehicleRoute> routes, int limit) Gets the k nearest routes to a job based on minimum distance to any activity.getRelevantRoutes(Job job, Collection<VehicleRoute> routes) Decides whether to use filtering for this job and returns relevant routes.getStats()Returns learning statistics for debugging.booleanReturns whether filtering is currently enabled.booleanReturns whether learning is complete.voidrecordComparison(InsertionData filteredBest, VehicleRoute filteredRoute, InsertionData fullBest, VehicleRoute fullRoute) Records comparison data for learning.voidreset()Resets the filter to initial state for a new problem.
-
Constructor Details
-
AdaptiveSpatialFilter
public AdaptiveSpatialFilter()Creates an adaptive spatial filter with default settings. -
AdaptiveSpatialFilter
public AdaptiveSpatialFilter(int learningRounds, int initialK) Creates an adaptive spatial filter.- Parameters:
learningRounds- number of comparison rounds for learninginitialK- initial number of nearest routes to consider
-
-
Method Details
-
getRelevantRoutes
public AdaptiveSpatialFilter.FilterResult getRelevantRoutes(Job job, Collection<VehicleRoute> routes) Decides whether to use filtering for this job and returns relevant routes.During learning phase: returns full routes but marks for comparison. After learning: deterministically applies filtering based on learned effectiveness.
- Parameters:
job- the job to find routes forroutes- all available routes- Returns:
- FilterResult containing routes to consider and whether comparison is needed
-
getNearestRoutes
Gets the k nearest routes to a job based on minimum distance to any activity. -
recordComparison
public void recordComparison(InsertionData filteredBest, VehicleRoute filteredRoute, InsertionData fullBest, VehicleRoute fullRoute) Records comparison data for learning. This method is thread-safe for use in concurrent execution.- Parameters:
filteredBest- best insertion from filtered routes (null if none found)filteredRoute- route for filtered best (null if none found)fullBest- best insertion from full search (null if none found)fullRoute- route for full best (null if none found)
-
isLearningComplete
public boolean isLearningComplete()Returns whether learning is complete. -
isFilteringEnabled
public boolean isFilteringEnabled()Returns whether filtering is currently enabled. -
getK
public int getK()Returns the current k value (number of nearest routes to consider). -
getStats
Returns learning statistics for debugging. -
reset
public void reset()Resets the filter to initial state for a new problem.
-