def demand_mass_balance_c(host_odemand, class_odemand, avail, host_recapture):
"""Solve Demand Mass Balance equation for class-level
Parameters
----------
host_odemand: int
Observerd host demand
class_odemand: int
Observed class demand
avail: dict
Availability of demand open during period considered
host_recapture: float
Estimated host level recapture
Returns
-------
tuple
Estimated demand, spill and recapture
"""
# if observed demand of a class is 0 demand mass balance can't
# estimate demand and spill alone without additioanl information
demand = spill = recapture = 0
if class_odemand:
recapture = host_recapture * class_odemand / host_odemand
# availability of demand closed during period considered
k = 1 - avail
A = np.array([[1, -1], [-k, 1]])
B = np.array([class_odemand - recapture, 0])
demand, spill = solve(A, B)
return demand, spill, recapture
评论列表
文章目录