Exemplo n.º 1
0
def test_add_empty_input_and_output_categories(DEA_example_data):
    allParams = Parameters()
    allParams.update_parameter('INPUT_CATEGORIES', '')
    allParams.update_parameter('OUTPUT_CATEGORIES', 'O1; O2')
    with pytest.raises(ValueError) as excinfo:
        factory.add_input_and_output_categories(allParams, DEA_example_data)
    assert str(
        excinfo.value) == 'Both input and output categories must be specified'
Exemplo n.º 2
0
def test_weakly_disposal_categories_creation(params, DEA_example_data):
    factory.add_input_and_output_categories(params, DEA_example_data)
    params.update_parameter('WEAKLY_DISPOSAL_CATEGORIES', 'I1; O2')
    model = factory.create_model(params, DEA_example_data)
    assert model._constraint_creator.__class__.__name__ == 'DisposableVarsConstraintCreator'
    params.update_parameter('DEA_FORM', 'multi')
    model = factory.create_model(params, DEA_example_data)
    assert model.__class__.__name__ == 'MultiplierModelWithDisposableCategories'
Exemplo n.º 3
0
def test_add_input_and_output_categories(DEA_example_data):
    allParams = Parameters()
    allParams.update_parameter('INPUT_CATEGORIES', 'I1; I2')
    allParams.update_parameter('OUTPUT_CATEGORIES', 'O1; O2')
    factory.add_input_and_output_categories(allParams, DEA_example_data)
    assert 'I1' in DEA_example_data.input_categories
    assert 'I2' in DEA_example_data.input_categories
    assert 'O1' in DEA_example_data.output_categories
    assert 'O2' in DEA_example_data.output_categories
Exemplo n.º 4
0
def test_create_model(params, DEA_example_data):
    factory.add_input_and_output_categories(params, DEA_example_data)
    model = factory.create_model(params, DEA_example_data)
    assert model.__class__.__name__ == 'EnvelopmentModelBase'
    assert model._concrete_model.__class__.__name__ == 'EnvelopmentModelInputOriented'
    assert model._constraint_creator.__class__.__name__ == 'DefaultConstraintCreator'
    params.update_parameter('DEA_FORM', 'multi')
    model = factory.create_model(params, DEA_example_data)
    assert model.__class__.__name__ == 'MultiplierModelBase'
    assert model._concrete_model.__class__.__name__ == 'MultiplierInputOrientedModel'
Exemplo n.º 5
0
def test_orientation_and_non_disc_variables(params, DEA_example_data):
    factory.add_input_and_output_categories(params, DEA_example_data)
    params.update_parameter('ORIENTATION', 'output')
    model = factory.create_model(params, DEA_example_data)
    assert model._concrete_model.__class__.__name__ == 'EnvelopmentModelOutputOriented'
    params.update_parameter('NON_DISCRETIONARY_CATEGORIES', 'O1')
    model = factory.create_model(params, DEA_example_data)
    assert model._concrete_model.__class__.__name__ == 'EnvelopmentModelOutputOrientedWithNonDiscVars'
    params.update_parameter('ORIENTATION', 'input')
    params.update_parameter('NON_DISCRETIONARY_CATEGORIES', 'I2')
    model = factory.create_model(params, DEA_example_data)
    assert model._concrete_model.__class__.__name__ == 'EnvelopmentModelInputOrientedWithNonDiscVars'
    params.update_parameter('ORIENTATION', 'not valid value')
    with pytest.raises(ValueError) as excinfo:
        model = factory.create_model(params, DEA_example_data)
    assert str(excinfo.value) == 'Unexpected value of parameter <ORIENTATION>'
Exemplo n.º 6
0
def build_models(params, model_input):
    ''' Creates several models and parameters in the case when
        RETURN_TO_SCALE or ORIENTATION is set to both. If neither
        RETURN_TO_SCALE
        nor ORIENTATION is set to both, then no new models will be created,
        a copy of the given model and parameters will be returned.

        Args:
            params (Parameters): parameters.
            model_input (InputData): data instance.

        Returns:
            tuple of list of ModelBase, list of Parameters: tuple with two
                lists. The first list contains all created models, the
                second list contains corresponding parameters.
    '''
    model_factory.add_input_and_output_categories(params, model_input)
    rts_type = params.get_parameter_value('RETURN_TO_SCALE')
    list_of_param_objects = []
    original_params = Parameters()
    original_params.copy_all_params(params)
    list_of_param_objects.append(original_params)
    if rts_type == 'both':
        original_params.update_parameter('RETURN_TO_SCALE', 'VRS')
        params_with_crs = Parameters()
        params_with_crs.copy_all_params(original_params)
        params_with_crs.update_parameter('RETURN_TO_SCALE', 'CRS')
        list_of_param_objects.append(params_with_crs)
    orientation_type = original_params.get_parameter_value('ORIENTATION')
    nb_param_objs = len(list_of_param_objects)
    if orientation_type == 'both':
        possible_orientation = ['input', 'output']
        for count in range(nb_param_objs):
            assert(count < 2)
            param_obj = list_of_param_objects[count]
            param_obj.update_parameter('ORIENTATION',
                                       possible_orientation[count])
            new_param_obj = Parameters()
            new_param_obj.copy_all_params(param_obj)
            new_param_obj.update_parameter('ORIENTATION',
                                           possible_orientation[1 - count])
            list_of_param_objects.append(new_param_obj)

    models = []
    for param_object in list_of_param_objects:
        models.append(model_factory.create_model(param_object, model_input))
    return models, list_of_param_objects
Exemplo n.º 7
0
def test_peel_the_onion_unbounded():
    params = parse_parameters_from_file('tests/params_for_linux.txt')

    categories, xls_data, dmu_name, sheet_name = read_data(
        params.get_parameter_value('DATA_FILE'))
    coefficients, has_same_dmus = convert_to_dictionary(xls_data)
    assert has_same_dmus is False
    assert validate_data(categories, coefficients) is True
    model_input = construct_input_data_instance(categories, coefficients)

    model_factory.add_input_and_output_categories(params, model_input)

    model = model_factory.create_model(params, model_input)

    ranks = None
    model_solution, ranks, state = peel_the_onion_method(model)
    assert state is True
    clean_up_pickled_files()
Exemplo n.º 8
0
def test_peel_the_onion_unbounded():
    params = parse_parameters_from_file('tests/params_for_linux.txt')

    categories, xls_data, dmu_name, sheet_name = read_data(
        params.get_parameter_value('DATA_FILE'))
    coefficients, has_same_dmus = convert_to_dictionary(xls_data)
    assert has_same_dmus is False
    assert validate_data(categories, coefficients) is True
    model_input = construct_input_data_instance(categories, coefficients)

    model_factory.add_input_and_output_categories(params, model_input)

    model = model_factory.create_model(params, model_input)

    ranks = None
    model_solution, ranks, state = peel_the_onion_method(model)
    assert state is True
    clean_up_pickled_files()
def test_VRS_from_params_file():
    params = parse_parameters_from_file('tests/params_new_format.txt')

    categories, xls_data, dmu_name, sheet_name = read_data(
        params.get_parameter_value('DATA_FILE'))
    coefficients, has_same_dmus = convert_to_dictionary(xls_data)
    assert has_same_dmus is False
    assert validate_data(categories, coefficients) is True
    model_input = construct_input_data_instance(categories, coefficients)

    model_factory.add_input_and_output_categories(params, model_input)

    model = model_factory.create_model(params, model_input)
    model_solution = model.run()
    utils_for_tests.check_optimal_solution_status_and_sizes(
        model_solution, model_input)
    dmus = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
    utils_for_tests.check_efficiency_scores(dmus, [1, 0.86998617, 1, 0.95561335,
                                                   0.85,
                                                   1, 1, 0.84507042, 1,
                                                   0.524, 0.89058524],
                                            model_solution, model_input)
    clean_up_pickled_files()
Exemplo n.º 10
0
def test_peel_the_onion_creation(params, DEA_example_data):
    params.update_parameter('PEEL_THE_ONION', 'yes')
    factory.add_input_and_output_categories(params, DEA_example_data)
    model = factory.create_model(params, DEA_example_data)
    peel_the_onion_method(model)