def protection_levels(fares, demands, sigmas=None, cap=None, method='EMSRb'): """Calculate protection levels. Parameters ---------- fares: np array fares provided in decreasing order demands: np array demands for the fares in `fares` cap: int, capacity sigmas: np array standard deviations of demands method: str optimization method ('EMSRb'or 'EMSRb_MR') Returns ------- np array of protection levels for each fare class """ check_fares_decreasing(fares) if method == 'EMSRb': return calc_EMSRb(fares, demands, sigmas) elif method == 'EMSRb_MR': prot_levels = calc_EMSRb_MR(fares, demands, sigmas, cap) return prot_levels else: raise ValueError('method "{}" not supported'.format(method))
def protection_levels(fares, demands, sigmas=None, cap=None, method='EMSRb'): check_fares_decreasing(fares) if method == 'EMSRb': return calc_EMSRb(fares, demands, sigmas) elif method == 'EMSRb_MR': prot_levels = calc_EMSRb_MR(fares, demands, sigmas, cap) return prot_levels else: raise ValueError('method "{}" not supported'.format(method))
def test_emsrb_nan_demand(self): demands = np.full(self.demands.shape, np.nan) p = optimizers.calc_EMSRb(self.fares, demands, self.sigmas) self.assertEqual(np.zeros(demands.shape).tolist(), p.tolist())
def test_emsrb_partly_zero_demand(self): demands = np.array([31.2, 0, 14.8, 19.9, 0, 36.3]) sigmas = np.zeros(demands.shape) p = optimizers.calc_EMSRb(self.fares, demands, sigmas) self.assertEqual([0.0, 31.0, 31.0, 46.0, 66.0, 66.0], p.tolist())
def test_emsrb_stochastic_demand(self): p = optimizers.calc_EMSRb(self.fares, self.demands, self.sigmas) self.assertEqual([0., 20., 35., 54., 80., 117.], p.tolist())
def calc_EMSRb_MR(fares, demands, sigmas=None, cap=None): return calc_EMSRb(fares, demands, sigmas)
def test_emsrb_stochastic_demand(self): # test example data from above mentioned paper p = optimizers.calc_EMSRb(self.fares, self.demands, self.sigmas) self.assertEqual([0., 20., 35., 54., 80., 117.], p.tolist())