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_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_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 = 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_all_constraints_multi_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, MultiplierOutputOrientedModel())
    model_solution = model.run()
    clean_up_pickled_files()
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,
                                MultiplierOutputOrientedModel())
    model_solution = model.run()
    clean_up_pickled_files()
def test_virtual_weight_restrictions_multiplier_model(data):

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

    bounds = {'I1': (None, 0.5)}
    model = MultiplierModelWithVirtualWeightRestrictions(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 = 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_weights_multi_output.xls')
def test_virtual_weight_restrictions_multiplier_model(data):

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

    bounds = {'I1': (None, 0.5)}
    model = MultiplierModelWithVirtualWeightRestrictions(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_weights_multi_output.xls')
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()