Class InsertionCostBreakdown

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

public class InsertionCostBreakdown extends Object
Captures a breakdown of insertion costs by component.

This allows full transparency into why an insertion costs what it costs, showing contributions from each soft constraint and the base activity insertion cost.

  • Constructor Details

    • InsertionCostBreakdown

      public InsertionCostBreakdown()
  • Method Details

    • add

      public void add(String name, double cost)
      Add a cost component.
      Parameters:
      name - The component name (e.g., "Route:SpatialCompactness", "ActivityInsertion")
      cost - The cost value (positive = penalty, negative = bonus)
    • merge

      public void merge(InsertionCostBreakdown other)
      Merge another breakdown into this one. Costs for components with the same name are summed.
      Parameters:
      other - The breakdown to merge
    • getComponents

      public Map<String,Double> getComponents()
      Get all cost components.
      Returns:
      Unmodifiable map of component name to cost
    • get

      public double get(String name)
      Get the cost for a specific component.
      Parameters:
      name - The component name
      Returns:
      The cost, or 0 if not present
    • getTotal

      public double getTotal()
      Get the total cost (sum of all components).
      Returns:
      Total cost
    • isEmpty

      public boolean isEmpty()
      Check if this breakdown has any components.
      Returns:
      true if at least one component was added
    • print

      public void print()
      Print the breakdown to stdout.
    • toString

      public String toString()
      Overrides:
      toString in class Object