Ejemplo n.º 1
0
def protection_levels(fares, demands, sigmas=None, cap=None, method='EMSRb'):
    """Calculate protection levels.

    Parameters
    ----------

    `fares`: array of fares (decreasing order)
    `demands`: array of predicted demands for the fares in `fares`
    `cap`: capacity of the resource (e.g. number of seats)
    `sigmas`: array of standard deviations of the demand predictions
    `method`: optimization method ('EMSRb', 'EMSRb_MR')

    Returns
    -------

    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))
Ejemplo n.º 2
0
def calc_EMSRb_MR(fares, demands, sigmas=None, cap=None):
    return calc_EMSRb(fares, demands, sigmas)
Ejemplo n.º 3
0
 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())
Ejemplo n.º 4
0
 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())
Ejemplo n.º 5
0
 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())