Enum Class PathCostSemiring

java.lang.Object
java.lang.Enum<PathCostSemiring>
com.darkcollective.relix.provenance.PathCostSemiring
All Implemented Interfaces:
Semiring<PathCost>, Serializable, Comparable<PathCostSemiring>, Constable

public enum PathCostSemiring extends Enum<PathCostSemiring> implements Semiring<PathCost>
The cheapest-route semiring ((ℝ ∪ {+∞}) × ℘(Route), ⊕, ⊗, (+∞, ∅), (0, {ε})) — the combined cost-and-witness algebra: a single weighted closure run carries both a path's cheapest cost and the route(s) achieving it. It is the standard arg-min / Viterbi "best value + witness set" construction lifted onto the tropical cost, closing the gap that tropical (cost, no route) and lineage (routes, no cost) leave when used alone.

⊕ keeps the cheaper alternative, unioning the witness routes on a cost tie (so all co-cheapest routes survive); ⊗ composes two hops in series — costs add and the route-sets multiply (each pair's edge sets unioned). 0 is (+∞, ∅) (unreachable), 1 is (0.0, {ε}) (the free derivation). The laws hold: ⊕ is a min-with-union and ⊗ is cost-addition with route-set union, both commutative and associative (a Route is an unordered edge set precisely so ⊗ stays commutative — the K-relation contract a sequence concatenation would break); ⊗ distributes over ⊕ (the prepended cost shifts both branches equally, so the arg-min winner is unchanged); and (+∞, ∅) annihilates ⊗ (the +∞ absorbs the cost, the empty route-set empties the product).

Bounded representation (the degraded mode)

A cyclic graph can enumerate unboundedly many co-cheapest routes (mirroring lineage/counting). To stay bounded, an operation leaving more than MAX_ROUTES distinct routes keeps the smallest MAX_ROUTES (in Route's deterministic order) and marks the result truncated — a sound under-approximation (surviving routes are real, and the cost stays exact because min is idempotent; only the route-set can grow). Truncation is contagious. The --max-fixpoint-rounds cut-off bounds iteration as for every weighted closure.

  • Enum Constant Details

    • INSTANCE

      public static final PathCostSemiring INSTANCE
      The singleton instance.
  • Field Details

    • MAX_ROUTES

      public static final int MAX_ROUTES
      Maximum distinct co-cheapest routes retained before a result is truncated.
      See Also:
  • Method Details

    • values

      public static PathCostSemiring[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static PathCostSemiring valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • zero

      public PathCost zero()
      Description copied from interface: Semiring
      Returns the additive identity 0. It is the identity of Semiring.plus(K, K) and the annihilator of Semiring.times(K, K), and denotes an absent tuple.
      Specified by:
      zero in interface Semiring<PathCost>
      Returns:
      the additive identity 0
    • one

      public PathCost one()
      Description copied from interface: Semiring
      Returns the multiplicative identity 1. It is the identity of Semiring.times(K, K).
      Specified by:
      one in interface Semiring<PathCost>
      Returns:
      the multiplicative identity 1
    • plus

      public PathCost plus(PathCost a, PathCost b)
      Description copied from interface: Semiring
      Combines two annotations with ⊕ — the way alternative derivations of the same tuple (union, projection) are merged. Associative and commutative, with identity Semiring.zero().
      Specified by:
      plus in interface Semiring<PathCost>
      Parameters:
      a - the first annotation
      b - the second annotation
      Returns:
      a ⊕ b
    • times

      public PathCost times(PathCost a, PathCost b)
      Description copied from interface: Semiring
      Combines two annotations with ⊗ — the way the joint requirements of a tuple (join, product) are merged. Associative and commutative, with identity Semiring.one(), annihilated by Semiring.zero().
      Specified by:
      times in interface Semiring<PathCost>
      Parameters:
      a - the first annotation
      b - the second annotation
      Returns:
      a ⊗ b
    • base

      public PathCost base(BaseTuple tuple)
      Returns the annotation a base tuple lifts to. This is how a semiring reads the data: the engine hands over each leaf tuple and the semiring says what it is worth.

      The default lifts every base tuple to Semiring.one(), which is correct for any semiring whose annotation does not depend on the data — boolean existence and the security lattice, whose answers are decided entirely by how derivations combine. Override it to read BaseTuple.weight() (a cost, a multiplicity, a probability) or to mint a per-occurrence token from BaseTuple.source() and BaseTuple.ordinal() (a route, a lineage variable).

      A semiring that reads a weight must decide for itself what an absent one means, because the two defensible answers differ: Semiring.one() leaves the tuple neutral, while a fixed constant makes an unweighted graph a defined special case rather than a degenerate one.

      Each base tuple is minted a token distinguishing it from every other edge, so that the cheapest route can name the edges it travelled rather than only its cost. An edge with no numeric weight costs 0 — every route then weighs its hop count of zero, which makes an unweighted graph a defined reachability-with-witness rather than an error.

      Specified by:
      base in interface Semiring<PathCost>
      Parameters:
      tuple - the base tuple; never null
      Returns:
      the tuple's base annotation; never null