java.lang.Object
java.lang.Record
com.darkcollective.relix.provenance.PathCost
Record Components:
cost - the cheapest derivation cost; +∞ for an absent tuple
routes - the co-cheapest routes (the witness set); never null
truncated - whether routes were dropped to stay within the representation bound

public record PathCost(double cost, SortedSet<Route> routes, boolean truncated) extends Record
An element of the cheapest-route semiring PathCostSemiring — a path's minimum cost and the set of co-cheapest routes that achieve it. It answers "what is the cheapest itinerary and what is it?" in one annotation, where tropical keeps only the cost and lineage only the routes.

Held canonically: 0 is (+∞, ∅) (unreachable / absent) and 1 is (0.0, {ε}) (the free derivation). Every non-zero value's routes are the derivations of exactly cost — the witness set of the arg-min. The truncated flag records that the route-set hit the representation cap and dropped some co-cheapest routes — a sound under-approximation (the surviving routes are real, each of cost cost; the cost itself is always exact, since min stays idempotent and only the route-set can grow).

  • Constructor Summary

    Constructors
    Constructor
    Description
    PathCost(double cost, SortedSet<Route> routes, boolean truncated)
    Canonicalises routes into an immutable sorted copy.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the value of the cost record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    boolean
    Returns whether this is the zero element (no routes — an absent tuple).
    static PathCost
    of(double cost, Route route)
    Returns a single-route value (cost, {route}).
    static PathCost
    one()
    Returns the one element (0.0, {ε}) — the free (empty-path) derivation.
    Returns the value of the routes record component.
    Returns the value rendered as 320.0 via r1 | r2.
    boolean
    Returns the value of the truncated record component.
    static PathCost
    Returns the zero element (+∞, ∅) — an unreachable / absent tuple.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PathCost

      public PathCost(double cost, SortedSet<Route> routes, boolean truncated)
      Canonicalises routes into an immutable sorted copy.
      Parameters:
      cost - the cheapest derivation cost
      routes - the witness routes; never null
      truncated - whether some routes were dropped to honour the bound
  • Method Details

    • zero

      public static PathCost zero()
      Returns the zero element (+∞, ∅) — an unreachable / absent tuple.
      Returns:
      the zero element (+∞, ∅) — an unreachable / absent tuple
    • one

      public static PathCost one()
      Returns the one element (0.0, {ε}) — the free (empty-path) derivation.
      Returns:
      the one element (0.0, {ε}) — the free (empty-path) derivation
    • of

      public static PathCost of(double cost, Route route)
      Returns a single-route value (cost, {route}). The base annotation of one weighted edge.
      Parameters:
      cost - the edge weight
      route - the edge's route (typically a one-token route)
      Returns:
      a single-route value (cost, {route})
    • isZero

      public boolean isZero()
      Returns whether this is the zero element (no routes — an absent tuple).
      Returns:
      whether this is the zero element (no routes — an absent tuple)
    • toString

      public String toString()
      Returns the value rendered as 320.0 via r1 | r2. ∞ for the zero element; a trailing | ⋯ when truncated().
      Specified by:
      toString in class Record
      Returns:
      the value rendered as 320.0 via r1 | r2
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • cost

      public double cost()
      Returns the value of the cost record component.
      Returns:
      the value of the cost record component
    • routes

      public SortedSet<Route> routes()
      Returns the value of the routes record component.
      Returns:
      the value of the routes record component
    • truncated

      public boolean truncated()
      Returns the value of the truncated record component.
      Returns:
      the value of the truncated record component