예제 #1
0
 def test_emsrbmr_protecion_levels_increasing(self):
     demands = np.array([1, 0, 0, 1, 0, 17, 2, 6])
     sigmas = np.array([4, 4, 4, 4, 4, 4, 4, 4])
     fares = np.array([12.97, 9.07, 8.65, 7.92, 7.66, 6.25, 6.08, 5.91])
     cap = 55
     y = meta_optimizers.calc_EMSRb_MR(fares, demands, sigmas)
     self.assertTrue(is_increasing(y[~np.isnan(y)]))
예제 #2
0
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))
예제 #3
0
 def test_emsrbmr_stochastic_demand_with_cap(self):
     cap = 50
     # test example data from above mentioned paper
     p = meta_optimizers.calc_EMSRb_MR(self.fares, self.demands,
                                       self.sigmas, cap)
     np.testing.assert_equal(
         np.array([0.0, 35.0, np.nan, np.nan, np.nan, np.nan]), p)
예제 #4
0
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))
예제 #5
0
 def test_emsrbmr_zero_demand(self):
     demands = np.zeros(self.fares.shape)
     p = meta_optimizers.calc_EMSRb_MR(self.fares, demands, self.sigmas)
     np.testing.assert_equal(
         np.array([0, np.nan, np.nan, np.nan, np.nan, np.nan]), p)