def test_run_with_categorical_dmus_invalid_data(categorical_from_book):
    data = categorical_from_book
    model = MultiplierModelBase(data, 0,
                                MultiplierInputOrientedModel())
    with pytest.raises(ValueError) as excinfo:
        categorical_model = ModelWithCategoricalDMUs(model, 'Non-existant')
    assert str(excinfo.value) == 'Category <Non-existant> does not exist'
def test_abs_weight_restrictions_multiplier_model(data):

    base_model = MultiplierModelBase(data, 0, MultiplierInputOrientedModel())

    bounds = {'I2': (0.01, 0.5)}
    model = MultiplierModelWithAbsoluteWeightRestrictions(base_model, bounds)
    start_time = datetime.datetime.now()
    model_solution = model.run()
    end_time = datetime.datetime.now()
    utils_for_tests.check_if_category_is_within_abs_limits(
        model_solution, bounds)

    work_book = Workbook()
    writer = XLSWriter(Parameters(), work_book, datetime.datetime.today(),
                       (end_time - start_time).total_seconds())
    writer.write_data(model_solution)
    work_book.save('tests/test_abs_weights_multi_output.xls')

    bounds = {'I2': (None, 0.05)}
    model = MultiplierModelWithAbsoluteWeightRestrictions(base_model, bounds)

    start_time = datetime.datetime.now()
    model_solution = model.run()
    end_time = datetime.datetime.now()

    utils_for_tests.check_if_category_is_within_abs_limits(
        model_solution, bounds)

    work_book2 = Workbook()
    writer = XLSWriter(Parameters(), work_book2, datetime.datetime.today(),
                       (end_time - start_time).total_seconds())
    writer.write_data(model_solution)
    work_book2.save('tests/test_abs_weights_upper_bound_multi_output.xls')
def test_all_constraints_multiplier_model(data):

    model = MultiplierModelBase(data, 0, MultiplierInputOrientedModel())

    bounds = {'I1': (None, 0.4)}
    model = MultiplierModelWithVirtualWeightRestrictions(model, bounds)

    abs_bounds = {'I2': (None, 0.2)}
    model = MultiplierModelWithAbsoluteWeightRestrictions(model, abs_bounds)

    ratio_bounds = {('I1', 'I2'): (None, 0.4), ('O1', 'O2'): (0.01, None)}
    model = MultiplierModelWithPriceRatioConstraints(model, ratio_bounds)
    start_time = datetime.datetime.now()
    model_solution = model.run()
    end_time = datetime.datetime.now()
    utils_for_tests.check_if_category_is_within_abs_limits(
        model_solution, abs_bounds)
    utils_for_tests.check_if_category_is_within_virtual_limits(
        model_solution, bounds)
    utils_for_tests.check_if_category_is_within_price_ratio_constraints(
        model_solution, ratio_bounds)

    work_book = Workbook()
    writer = XLSWriter(Parameters(), work_book, datetime.datetime.today(),
                       (end_time - start_time).total_seconds())
    writer.write_data(model_solution)
    work_book.save('tests/test_all_constraints_multi_output.xls')
def test_run_with_categorical_dmus(categorical_from_book):
    data = categorical_from_book
    model = MultiplierModelBase(data, 0,
                                MultiplierInputOrientedModel())
    categorical_model = ModelWithCategoricalDMUs(model, 'Category')
    start_time = datetime.datetime.now()
    solution = categorical_model.run()
    end_time = datetime.datetime.now()
    dmus = ['L1', 'L2', 'L3', 'L4', 'L5', 'L6', 'L7', 'L8', 'L9', 'L10',
            'L11', 'L12',
            'L13', 'L14', 'L15', 'L16', 'L17', 'L18', 'L19', 'L20',
            'L21', 'L22', 'L23']
    utils_for_tests.check_efficiency_scores(dmus, [0.377, 0.879, 0.936, 1, 1, 1,
                                                   0.743, 0.648, 1, 0.815,
                                                   0.646,
                                                   0.835, 0.794, 0.835, 1,
                                                   0.687, 1, 0.787, 1,
                                                   0.849, 0.787, 0.681, 1],
                                            solution, data, 1e-3)
    work_book = Workbook()
    writer = XLSWriter(Parameters(), work_book, datetime.datetime.today(),
                       (end_time - start_time).total_seconds(),
                       categorical='Category')
    writer.write_data(solution)
    work_book.save('tests/test_categorical_output.xls')
def test_with_zero_data():
    categories, xls_data, dmu_name, sheet_name = read_data(
        'tests/with_zeros.xls')
    coefficients, has_same_dmus = convert_to_dictionary(xls_data)
    assert has_same_dmus is False
    assert validate_data(categories, coefficients) is True
    data = construct_input_data_instance(categories, coefficients)
    data.add_input_category('rein')
    data.add_output_category('aus')
    model = MultiplierModelBase(data, 0, MultiplierInputOrientedModel())
    model_solution = model.run()
    clean_up_pickled_files()
示例#6
0
def test_peel_the_onion_VRS_multi(categorical_data):
    categorical_data.add_input_category('rein')
    categorical_data.add_output_category('aus')
    model = MultiplierModelVRSDecorator(
        MultiplierModelBase(categorical_data, 0,
                            MultiplierInputOrientedModel()))

    solution, ranks, state = peel_the_onion_method(model)
    utils_for_tests.check_optimal_solution_status_and_sizes(
        solution, categorical_data)
    dmus = ['B', 'C', 'D', 'E', 'F', 'G']
    utils_for_tests.check_efficiency_scores(dmus, [1, 0.5, 1, 0.99999998,
                                                   0.75, 0.50000001],
                                            solution, categorical_data, 1e-7)

    expected_ranks = [1, 2, 1, 1, 2, 2]
    utils_for_tests.check_onion_ranks(
        model.input_data, dmus, expected_ranks, ranks)
def test_CRS_multi_input_oriented_with_non_discretionary_vars(data):
    model = MultiplierModelInputOrientedWithNonDiscVars(
        MultiplierModelBase(data, 1e-12, MultiplierInputOrientedModel()),
        set(['x1']))

    model_solution = model.run()
    utils_for_tests.check_optimal_solution_status_and_sizes(
        model_solution, data)
    dmus = ['A', 'B', 'C', 'D', 'E']
    utils_for_tests.check_efficiency_scores(dmus,
                                            [0.3, 1, 0.750000012, 0.5, 1],
                                            model_solution, data)

    utils_for_tests.check_lambda_variables('A', 'B', 0.25, model_solution,
                                           data)
    utils_for_tests.check_lambda_variables('A', 'E', 0.25, model_solution,
                                           data)
    utils_for_tests.check_lambda_variables('B', 'B', 1, model_solution, data)
    utils_for_tests.check_lambda_variables('C', 'B', 0.75, model_solution,
                                           data)
    utils_for_tests.check_lambda_variables('C', 'E', 0.75, model_solution,
                                           data)
    utils_for_tests.check_lambda_variables('D', 'E', 0.5, model_solution, data)
    utils_for_tests.check_lambda_variables('E', 'E', 1, model_solution, data)

    utils_for_tests.check_categories_for_dmu('A', ['x1', 'x2', 'q'],
                                             [0.1, 0.2, 0.5], model_solution,
                                             data)
    utils_for_tests.check_categories_for_dmu('B', ['x1', 'x2', 'q'],
                                             [0.125, 0.25, 0.625],
                                             model_solution, data)
    utils_for_tests.check_categories_for_dmu(
        'C', ['x1', 'x2', 'q'], [0.083333333, 0.16666667, 0.41666667],
        model_solution, data)
    utils_for_tests.check_categories_for_dmu('D', ['x1', 'x2', 'q'],
                                             [0, 0.5, 0.5], model_solution,
                                             data)
    utils_for_tests.check_categories_for_dmu('E', ['x1', 'x2', 'q'],
                                             [0, 0.5, 0.5], model_solution,
                                             data)
def test_price_ratio_restrictions_medium_env_model():
    categories, data, dmu_name, sheet_name = read_data(
        'tests/dataFromDEAbook_page181.xls')
    coefficients, has_same_dmus = convert_to_dictionary(data)
    assert has_same_dmus is False
    assert validate_data(categories, coefficients) is True
    data = construct_input_data_instance(categories, coefficients)
    print(data.categories)
    data.add_input_category('Doctors')
    data.add_input_category('Nurses')
    data.add_output_category('Outpatients')
    data.add_output_category('Inpatients')

    model = MultiplierModelBase(data, 0, MultiplierInputOrientedModel())

    ratio_bounds = {
        ('Nurses', 'Doctors'): (0.2, 5),
        ('Inpatients', 'Outpatients'): (0.2, 5)
    }
    model = MultiplierModelWithPriceRatioConstraints(model, ratio_bounds)

    model_solution = model.run()
    utils_for_tests.check_if_category_is_within_price_ratio_constraints(
        model_solution, ratio_bounds)

    utils_for_tests.check_optimal_solution_status_and_sizes(
        model_solution, data)
    dmus = [
        'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'H10', 'H11',
        'H12', 'H13', 'H14'
    ]
    utils_for_tests.check_efficiency_scores(dmus, [
        0.926, 1, 1, 0.634, 0.82, 1, 0.803, 0.872, 0.982, 1, 0.849, 0.93, 0.74,
        0.929
    ], model_solution, data, 1e-3)
    clean_up_pickled_files()
def test_CRS_multi_input_oriented_with_weakly_disposable_vars_small(data):
    model = MultiplierModelWithDisposableCategories(
        MultiplierModelBase(data, 1e-12, MultiplierInputOrientedModel()),
        ['x1', 'q'])
    model_solution = model.run()
    utils_for_tests.check_optimal_solution_status_and_sizes(
        model_solution, data)
    dmus = ['A', 'B', 'C', 'D', 'E']
    utils_for_tests.check_efficiency_scores(
        dmus, [0.5, 1, 0.83333334, 0.71428571, 1], model_solution, data)

    utils_for_tests.check_lambda_variables('A', 'B', 0.5, model_solution, data)
    utils_for_tests.check_lambda_variables('B', 'B', 1, model_solution, data)
    utils_for_tests.check_lambda_variables('C', 'B', 1, model_solution, data)
    utils_for_tests.check_lambda_variables('C', 'E', 0.5, model_solution, data)
    utils_for_tests.check_lambda_variables('D', 'B', 0.21428571,
                                           model_solution, data)
    utils_for_tests.check_lambda_variables('D', 'E', 0.28571429,
                                           model_solution, data)
    utils_for_tests.check_lambda_variables('E', 'E', 1, model_solution, data)

    utils_for_tests.check_categories_for_dmu('A', ['x1', 'x2', 'q'],
                                             [0.5, 0, 0.5], model_solution,
                                             data)
    utils_for_tests.check_categories_for_dmu('B', ['x1', 'x2', 'q'],
                                             [0.5, 0, 0.5], model_solution,
                                             data)
    utils_for_tests.check_categories_for_dmu(
        'C', ['x1', 'x2', 'q'], [0.055555556, 0.11111111, 0.27777778],
        model_solution, data)
    utils_for_tests.check_categories_for_dmu(
        'D', ['x1', 'x2', 'q'], [0.14285714, 0.28571429, 0.71428571],
        model_solution, data)
    utils_for_tests.check_categories_for_dmu('E', ['x1', 'x2', 'q'],
                                             [0.1, 0.2, 0.5], model_solution,
                                             data)
示例#10
0
 def get_input_oriented_model(cls, use_super_efficiency,
                              non_discr_categories):
     ''' See base class.
     '''
     return MultiplierInputOrientedModel()
def model(request, data):
    model = MultiplierModelVRSDecorator(
        MultiplierModelBase(data, 0, MultiplierInputOrientedModel()))
    return model
def model(request, data):
    model = MultiplierModelBase(data, 1e-12, MultiplierInputOrientedModel())
    return model