Esempio n. 1
0
def test_CRS_env_output_oriented_non_disc_vars():
    categories, xls_data, dmu_name, sheet_name = read_data(
        'tests/DEA_example_data.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('I1')
    data.add_input_category('I2')
    data.add_output_category('ND1')
    data.add_output_category('O1')
    data.add_output_category('O2')
    model = EnvelopmentModelBase(
        data,
        EnvelopmentModelOutputOrientedWithNonDiscVars(
            set(['ND1']), generate_lower_bound_for_efficiency_score),
        DefaultConstraintCreator())

    model_solution = model.run()
    utils_for_tests.check_optimal_solution_status_and_sizes(
        model_solution, data)
    dmus = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
    utils_for_tests.check_efficiency_scores(dmus, [
        1, 1, 1 / 1.1698685, 1, 1 / 2.3749162, 1, 1, 1 / 1.3198374,
        1 / 1.2115385, 0.5, 1
    ], model_solution, data)
    clean_up_pickled_files()
def test_CRS_env_output_oriented_non_disc_vars():
    categories, xls_data, dmu_name, sheet_name = read_data(
        'tests/DEA_example_data.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('I1')
    data.add_input_category('I2')
    data.add_output_category('ND1')
    data.add_output_category('O1')
    data.add_output_category('O2')
    model = EnvelopmentModelBase(
        data,
        EnvelopmentModelOutputOrientedWithNonDiscVars(
            set(['ND1']),
            generate_lower_bound_for_efficiency_score),
        DefaultConstraintCreator())

    model_solution = model.run()
    utils_for_tests.check_optimal_solution_status_and_sizes(model_solution,
                                                            data)
    dmus = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
    utils_for_tests.check_efficiency_scores(dmus, [1, 1, 1 / 1.1698685, 1,
                                                   1 / 2.3749162, 1,
                                                   1, 1 / 1.3198374,
                                                   1 / 1.2115385,
                                                   0.5, 1], model_solution,
                                            data)
    clean_up_pickled_files()
def test_price_ratio_restrictions_env_model(data):
    model = EnvelopmentModelBase(data,
                                 EnvelopmentModelInputOriented(
                                     generate_upper_bound_for_efficiency_score),
                                 DefaultConstraintCreator())

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

    work_book = xlwt.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_price_ratio_env_output.xls')
def test_virual_restrictions_env_model(data):
    model = EnvelopmentModelBase(data,
                                 EnvelopmentModelInputOriented(
                                     generate_upper_bound_for_efficiency_score),
                                 DefaultConstraintCreator())

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

    work_book = xlwt.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_virtual_constraints_env_output.xls')
Esempio n. 5
0
def test_CRS_env_input_oriented_non_disc_vars(DEA_example_data):
    data = DEA_example_data
    data.add_input_category('I1')
    data.add_input_category('I2')
    data.add_input_category('ND1')
    data.add_output_category('O1')
    data.add_output_category('O2')
    model = EnvelopmentModelBase(
        data,
        EnvelopmentModelInputOrientedWithNonDiscVars(
            set(['ND1']), generate_upper_bound_for_efficiency_score),
        DefaultConstraintCreator())

    model_solution = model.run()

    utils_for_tests.check_optimal_solution_status_and_sizes(
        model_solution, data)
    dmus = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
    utils_for_tests.check_efficiency_scores(dmus, [
        1, 0.62939304, 0.95095971, 1, 0.42525889, 1, 1, 0.82672274, 1,
        0.53385106, 1
    ], model_solution, data)
def test_CRS_env_input_oriented_non_disc_vars(DEA_example_data):
    data = DEA_example_data
    data.add_input_category('I1')
    data.add_input_category('I2')
    data.add_input_category('ND1')
    data.add_output_category('O1')
    data.add_output_category('O2')
    model = EnvelopmentModelBase(
        data,
        EnvelopmentModelInputOrientedWithNonDiscVars(
            set(['ND1']),
            generate_upper_bound_for_efficiency_score),
        DefaultConstraintCreator())

    model_solution = model.run()

    utils_for_tests.check_optimal_solution_status_and_sizes(
        model_solution, data)
    dmus = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
    utils_for_tests.check_efficiency_scores(dmus, [1, 0.62939304, 0.95095971,
                                                   1, 0.42525889,
                                                   1, 1, 0.82672274, 1,
                                                   0.53385106, 1],
                                            model_solution, data)
def test_maximize_slacks_usual():
    categories, xls_data, dmu_name, sheet_name = read_data(
        'tests/DEA_example_data.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('I1')
    data.add_input_category('I2')
    data.add_output_category('O1')
    data.add_output_category('O2')
    model = EnvelopmentModelBase(data,
                                 EnvelopmentModelInputOriented(
                                     generate_upper_bound_for_efficiency_score),
                                 DefaultConstraintCreator())
    model = MaximizeSlacksModel(model)

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

    utils_for_tests.check_optimal_solution_status_and_sizes(
        model_solution, data)
    dmus = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
    utils_for_tests.check_efficiency_scores(dmus, [1, 0.62939304, 0.85479694,
                                                   1, 0.42106749,
                                                   1, 1, 0.75766909,
                                                   0.82539683, 0.5, 1],
                                            model_solution, data)

    work_book = xlwt.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_max_slacks_output.xls')
    clean_up_pickled_files()