예제 #1
0
def test_create_model_VRS(params, DEA_example_data):
    params.update_parameter('RETURN_TO_SCALE', 'VRS')
    model = factory.create_model(params, DEA_example_data)
    assert model.__class__.__name__ == 'EnvelopmentModelVRSDecorator'
    params.update_parameter('DEA_FORM', 'multi')
    model = factory.create_model(params, DEA_example_data)
    assert model.__class__.__name__ == 'MultiplierModelVRSDecorator'
예제 #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'
예제 #3
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'
예제 #4
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>'
예제 #5
0
 def run(self):
     model = factory.create_model(self.__dea_params, self.__dea_data)
     solution = model.run()
     r = {}
     s = solution.efficiency_scores
     for dmu_key in sorted(s.keys()):
         r[self.__dea_data.get_dmu_user_name(dmu_key)] = s[dmu_key]
     return r
예제 #6
0
def test_create_model_weigth_restrictions(params, DEA_example_data):
    params.update_parameter('ABS_WEIGHT_RESTRICTIONS',
                            'I1 >= 1; I2 <= 10; I1 <= 7')
    model = factory.create_model(params, DEA_example_data)
    assert model.__class__.__name__ == 'EnvelopmentModelWithAbsoluteWeightRestrictions'
    params.update_parameter('VIRTUAL_WEIGHT_RESTRICTIONS',
                            'I1 >= 1; I2 <= 10; I1 <= 7')
    model = factory.create_model(params, DEA_example_data)
    assert model.__class__.__name__ == 'EnvelopmentModelWithVirtualWeightRestrictions'
    assert model.model.__class__.__name__ == 'EnvelopmentModelWithAbsoluteWeightRestrictions'
    params.update_parameter('PRICE_RATIO_RESTRICTIONS',
                            'I1/I2 >= 1; I2/I1 <= 10; I1/I2 <= 7')
    model = factory.create_model(params, DEA_example_data)
    assert model.__class__.__name__ == 'EnvelopmentModelWithPriceRatioConstraints'
    assert model.model.__class__.__name__ == 'EnvelopmentModelWithVirtualWeightRestrictions'
    params.update_parameter('DEA_FORM', 'multi')
    params.update_parameter('VIRTUAL_WEIGHT_RESTRICTIONS', '')
    params.update_parameter('PRICE_RATIO_RESTRICTIONS', '')
    model = factory.create_model(params, DEA_example_data)
    assert model.__class__.__name__ == 'MultiplierModelWithAbsoluteWeightRestrictions'
    params.update_parameter('VIRTUAL_WEIGHT_RESTRICTIONS',
                            'I1 >= 1; I2 <= 10; I1 <= 7')
    model = factory.create_model(params, DEA_example_data)
    assert model.__class__.__name__ == 'MultiplierModelWithVirtualWeightRestrictions'
    assert model._model_to_decorate.__class__.__name__ == 'MultiplierModelWithAbsoluteWeightRestrictions'
    params.update_parameter('PRICE_RATIO_RESTRICTIONS',
                            'I1/I2 >= 1; I2/I1 <= 10; I1/I2 <= 7')
    model = factory.create_model(params, DEA_example_data)
    assert model.__class__.__name__ == 'MultiplierModelWithPriceRatioConstraints'
    assert model._model_to_decorate.__class__.__name__ == 'MultiplierModelWithVirtualWeightRestrictions'
예제 #7
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
예제 #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()
예제 #9
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()
예제 #11
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)
예제 #12
0
def test_categorical_model_creation(params, DEA_example_data):
    params.update_parameter('CATEGORICAL_CATEGORY', 'I1')
    model = factory.create_model(params, DEA_example_data)
    assert model.__class__.__name__ == 'ModelWithCategoricalDMUs'
예제 #13
0
def test_invalid_dea_form(params, DEA_example_data):
    params.update_parameter('DEA_FORM', 'invalid')
    with pytest.raises(ValueError) as excinfo:
        model = factory.create_model(params, DEA_example_data)
    assert str(excinfo.value) == 'Invalid value of parameter <DEA_FORM>'
예제 #14
0
def test_super_efficiency_creation(params, DEA_example_data):
    params.update_parameter('USE_SUPER_EFFICIENCY', 'yes')
    model = factory.create_model(params, DEA_example_data)
    assert model.__class__.__name__ == 'SupperEfficiencyModel'
예제 #15
0
def test_max_slacks_creation(params, DEA_example_data):
    params.update_parameter('MAXIMIZE_SLACKS', 'yes')
    model = factory.create_model(params, DEA_example_data)
    assert model.__class__.__name__ == 'MaximizeSlacksModel'