PCG icon indicating copy to clipboard operation
PCG copied to clipboard

Add a Cost type

Open recursion-ninja opened this issue 6 years ago • 1 comments

Currently, our "cost" type is a Double or a new-typed Double labeled ExtendedReal.

Our use-case for Cost does not overlap well with the Num and related "numeric" type-class instances.

Our Cost should have the following invariants:

  • Non-negative
  • Monotonically non-decreasing "addition"
  • Equatable
  • Total ordering
  • An "infinite value" representation
  • Perfect precision for rational numbers
  • Reasonable efficiency

We could represent Cost as a non-negative rational number and a Monoid under addition.

recursion-ninja avatar Apr 25 '19 18:04 recursion-ninja

I added the module Numeric.Cost in the pcg-utility package along with an accompanying test suite. See this commit f6d0b1f .

We should consider using this Cost type for the weights of characters along with the resulting cost of our scored graph objects. This would be the next step for this issue. The result would be no rounding errors in our codebase. The only possible exception to this is for continuous character optimization, as they are still implemented using Double values.

recursion-ninja avatar May 31 '19 15:05 recursion-ninja