Class AdaptiveSpatialFilter

java.lang.Object
com.graphhopper.jsprit.core.algorithm.recreate.AdaptiveSpatialFilter

public class AdaptiveSpatialFilter extends Object
Adaptive spatial filter that learns whether spatial filtering is effective for a given problem.

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.

  • 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 learning
      initialK - 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 for
      routes - all available routes
      Returns:
      FilterResult containing routes to consider and whether comparison is needed
    • getNearestRoutes

      public List<VehicleRoute> getNearestRoutes(Job job, Collection<VehicleRoute> routes, int limit)
      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

      public String getStats()
      Returns learning statistics for debugging.
    • reset

      public void reset()
      Resets the filter to initial state for a new problem.