Skip to content

Cost Functions

deepbullwhip.cost.base.CostFunction

Bases: ABC

Abstract per-period cost function.

Source code in deepbullwhip/cost/base.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
class CostFunction(ABC):
    """Abstract per-period cost function."""

    @abstractmethod
    def compute(self, inventory: float) -> float:
        """Compute cost for a single period given ending inventory.

        Parameters
        ----------
        inventory : float
            On-hand inventory (negative means backorders).

        Returns
        -------
        float
            Non-negative cost for this period.
        """
        ...

compute(inventory) abstractmethod

Compute cost for a single period given ending inventory.

Parameters:

Name Type Description Default
inventory float

On-hand inventory (negative means backorders).

required

Returns:

Type Description
float

Non-negative cost for this period.

Source code in deepbullwhip/cost/base.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
@abstractmethod
def compute(self, inventory: float) -> float:
    """Compute cost for a single period given ending inventory.

    Parameters
    ----------
    inventory : float
        On-hand inventory (negative means backorders).

    Returns
    -------
    float
        Non-negative cost for this period.
    """
    ...

deepbullwhip.cost.newsvendor.NewsvendorCost

Bases: CostFunction

Newsvendor-style cost: h * inventory^+ + b * inventory^-.

Parameters:

Name Type Description Default
holding_cost float

Per-unit per-period holding cost (applied when inventory >= 0).

required
backorder_cost float

Per-unit per-period backorder cost (applied when inventory < 0).

required
Source code in deepbullwhip/cost/newsvendor.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@register("cost", "newsvendor")
class NewsvendorCost(CostFunction):
    """Newsvendor-style cost: h * inventory^+ + b * inventory^-.

    Parameters
    ----------
    holding_cost : float
        Per-unit per-period holding cost (applied when inventory >= 0).
    backorder_cost : float
        Per-unit per-period backorder cost (applied when inventory < 0).
    """

    def __init__(self, holding_cost: float, backorder_cost: float) -> None:
        self.h = holding_cost
        self.b = backorder_cost

    def compute(self, inventory: float) -> float:
        if inventory >= 0:
            return self.h * inventory
        return self.b * abs(inventory)