smartgrid.util.bounded.decrease_bounded

smartgrid.util.bounded.decrease_bounded(original_quantity, amount, lower_bound)[source]

Decrease a bounded quantity by an amount, enforcing a lower bound.

Parameters:
  • original_quantity – The original quantity, before we decrease it. It must be a number, e.g., int or float.

  • amount – The amount we want to subtract from original_quantity. The actual decrease may be lower than this (because of the constraints), but cannot be higher. It must be a number, e.g., int or float, which can be subtracted to the quantity (compatible types).

  • lower_bound – The lower bound we want to enforce on the quantity. The new quantity is guaranteed to be greater or equal to this bound.

Return type:

(float, float, float)

Returns:

  • new_quantity – The new value of the quantity, after the decrease.

  • actual_amount – The actual amount that was subtracted to the original_quantity, i.e., original_quantity - actual_amount = new_quantity.

  • missing – The quantity that could not be subtracted (because it would have exceeded the bound), i.e., actual_amount + missing = amount.