def test_peel_the_onion_and_categorical(categorical_from_book):
    model = EnvelopmentModelBase(categorical_from_book,
                                 EnvelopmentModelInputOriented(
                                     generate_upper_bound_for_efficiency_score),
                                 DefaultConstraintCreator())
    model = ModelWithCategoricalDMUs(model, 'Category')
    model_solution, ranks, state = peel_the_onion_method(model)
    assert state is True
    clean_up_pickled_files()
Beispiel #2
0
def test_peel_the_onion_and_categorical(categorical_from_book):
    model = EnvelopmentModelBase(categorical_from_book,
                                 EnvelopmentModelInputOriented(
                                     generate_upper_bound_for_efficiency_score),
                                 DefaultConstraintCreator())
    model = ModelWithCategoricalDMUs(model, 'Category')
    model_solution, ranks, state = peel_the_onion_method(model)
    assert state is True
    clean_up_pickled_files()
def test_superefficiency_and_peel_the_onion(categorical_data):
    categorical_data.add_input_category('rein')
    categorical_data.add_output_category('aus')
    model = EnvelopmentModelBase(
        categorical_data,
        EnvelopmentModelInputOriented(generate_supper_efficiency_upper_bound),
        DefaultConstraintCreator())
    super_efficiency_model = SupperEfficiencyModel(model)
    model_solution, ranks, state = peel_the_onion_method(
        super_efficiency_model)
Beispiel #4
0
def test_superefficiency_and_peel_the_onion(categorical_data):
    categorical_data.add_input_category('rein')
    categorical_data.add_output_category('aus')
    model = EnvelopmentModelBase(
        categorical_data,
        EnvelopmentModelInputOriented(generate_supper_efficiency_upper_bound),
        DefaultConstraintCreator())
    super_efficiency_model = SupperEfficiencyModel(model)
    model_solution, ranks, state = peel_the_onion_method(
        super_efficiency_model)
def test_peel_the_onion_CRS_env_input_oriented(DEA_example2_data):

    model = _create_large_model(DEA_example2_data)

    solution, ranks, state = peel_the_onion_method(model)

    _check_large_model(solution, model.input_data)

    dmus = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
    expected_ranks = [1, 3, 2, 1, 3, 1, 1, 2, 1, 2, 1]
    utils_for_tests.check_onion_ranks(
        model.input_data, dmus, expected_ranks, ranks)
Beispiel #6
0
def test_peel_the_onion_CRS_env_input_oriented(DEA_example2_data):

    model = _create_large_model(DEA_example2_data)

    solution, ranks, state = peel_the_onion_method(model)

    _check_large_model(solution, model.input_data)

    dmus = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
    expected_ranks = [1, 3, 2, 1, 3, 1, 1, 2, 1, 2, 1]
    utils_for_tests.check_onion_ranks(
        model.input_data, dmus, expected_ranks, ranks)
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_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)
Beispiel #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()
Beispiel #10
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_show_solution(sol_frame, model):
    model_solution, ranks, state = peel_the_onion_method(model)
    sol_frame.show_solution([model_solution], Parameters(), ['params to print'],
                            datetime.datetime.today(), 5, ranks=[ranks])
    assert sol_frame.nb_tabs == 8
    assert len(sol_frame.all_tabs) == 8
    assert sol_frame.nb_filled_tabs == 8
    for count, tab in enumerate(sol_frame.all_tabs):
        assert sol_frame.tab(count, 'text') == tab.name

    model_solution = model.run()
    solutions = [model_solution]
    sol_frame.show_solution(solutions, Parameters(), [
                            'params to print'], datetime.datetime.today(), 5)
    assert sol_frame.nb_tabs == 7
    assert len(sol_frame.all_tabs) == 7
    assert sol_frame.nb_filled_tabs == 7
    for count, tab in enumerate(sol_frame.all_tabs):
        assert sol_frame.tab(count, 'text') == tab.name
def test_peel_the_onion_CRS_multi_output_oriented(DEA_example2_data):
    model = _create_large_model_CRS_multi_output_oriented_with_non_discretionary(
        DEA_example2_data)
    start_time = datetime.datetime.now()
    solution, ranks, state = peel_the_onion_method(model)
    end_time = datetime.datetime.now()
    _check_large_model_CRS_multi_output_oriented_with_non_discretionary(
        solution, model.input_data)
    dmus = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
    expected_ranks = [1, 3, 2, 1, 3, 1, 1, 2, 1, 2, 1]
    utils_for_tests.check_onion_ranks(
        model.input_data, dmus, expected_ranks, ranks)

    work_book = xlwt.Workbook()
    ranks_as_list = []
    ranks_as_list.append(ranks)
    writer = XLSWriter(Parameters(), work_book, datetime.datetime.today(),
                       (end_time - start_time).total_seconds(),
                       ranks=ranks_as_list)
    writer.write_data(solution)
    work_book.save('tests/test_peel_the_onion.xls')
Beispiel #13
0
def test_peel_the_onion_CRS_multi_output_oriented(DEA_example2_data):
    model = _create_large_model_CRS_multi_output_oriented_with_non_discretionary(
        DEA_example2_data)
    start_time = datetime.datetime.now()
    solution, ranks, state = peel_the_onion_method(model)
    end_time = datetime.datetime.now()
    _check_large_model_CRS_multi_output_oriented_with_non_discretionary(
        solution, model.input_data)
    dmus = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
    expected_ranks = [1, 3, 2, 1, 3, 1, 1, 2, 1, 2, 1]
    utils_for_tests.check_onion_ranks(
        model.input_data, dmus, expected_ranks, ranks)

    work_book = Workbook()
    ranks_as_list = []
    ranks_as_list.append(ranks)
    writer = XLSWriter(Parameters(), work_book, datetime.datetime.today(),
                       (end_time - start_time).total_seconds(),
                       ranks=ranks_as_list)
    writer.write_data(solution)
    work_book.save('tests/test_peel_the_onion.xls')
def test_show_solution(sol_frame, model):
    model_solution, ranks, state = peel_the_onion_method(model)
    sol_frame.show_solution([model_solution],
                            Parameters(), ['params to print'],
                            datetime.datetime.today(),
                            5,
                            ranks=[ranks])
    assert sol_frame.nb_tabs == 8
    assert len(sol_frame.all_tabs) == 8
    assert sol_frame.nb_filled_tabs == 8
    for count, tab in enumerate(sol_frame.all_tabs):
        assert sol_frame.tab(count, 'text') == tab.name

    model_solution = model.run()
    solutions = [model_solution]
    sol_frame.show_solution(solutions, Parameters(), ['params to print'],
                            datetime.datetime.today(), 5)
    assert sol_frame.nb_tabs == 7
    assert len(sol_frame.all_tabs) == 7
    assert sol_frame.nb_filled_tabs == 7
    for count, tab in enumerate(sol_frame.all_tabs):
        assert sol_frame.tab(count, 'text') == tab.name
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)
Beispiel #16
0
    def run(self, params):
        ''' Executes solution routine - create data instance,
            solve LPs, post-process solutions.

            Args:
                params (Parameters): parameters of a given problem instance
        '''
        logger = get_logger()
        logger.info('Started solving given DEA model(s).')
        logger.info('Parameters: %s', params.get_all_params_as_string())
        categories = self.get_categories()
        coefficients, has_same_dmus = self.get_coefficients()

        if has_same_dmus:
            self.show_error('Some DMUs have the same name')
        else:
            if validate_data(categories, coefficients):
                try:

                    self.validate_weights_if_needed()  # MUST be called
                    # before model_builder, because it might
                    # update parameters
                    model_input = construct_input_data_instance(
                        categories, coefficients)

                    models, all_params = model_builder.build_models(
                        params, model_input)

                    self.init_before_run(len(models), coefficients)

                    solutions = []

                    state = True
                    param_strs = []
                    all_ranks = []
                    run_date = datetime.datetime.today()
                    start_time = datetime.datetime.now()
                    for count, model_obj in enumerate(models):
                        model = self.decorate_model(model_obj)

                        call_peel_the_onion = params.get_parameter_value(
                            'PEEL_THE_ONION')

                        if call_peel_the_onion:
                            model_solution, ranks, state = (
                                peel_the_onion_method(model))
                            all_ranks.append(ranks)
                        else:
                            model_solution = model.run()

                        str_to_write = create_params_str(all_params[count])
                        param_strs.append(str_to_write)
                        solutions.append(model_solution)
                        try:
                            solutions.append(model.second_solution)
                            param_strs.append(str_to_write + ' second phase')
                        except AttributeError:
                            pass

                    end_time = datetime.datetime.now()
                    diff = end_time - start_time
                    total_seconds = diff.total_seconds()
                    if params.get_parameter_value('RETURN_TO_SCALE') == 'both':
                        derive_returns_to_scale_classification(
                            param_strs, solutions)
                    self.post_process_solutions(solutions, params, param_strs,
                                                all_ranks, run_date,
                                                total_seconds)

                    if state is False:
                        self.show_error('For one of the runs of the '
                                        'peel-the-onion problem is infeasible'
                                        ' or unbounded')
                    self.show_success()
                except Exception as excinfo:
                    self.show_error(excinfo)
                else:
                    logger.info('Given DEA model(s) successfully solved.')
            else:
                self.show_error('Some of the input data is not correct')
Beispiel #17
0
    def run(self, params):
        ''' Executes solution routine - create data instance,
            solve LPs, post-process solutions.

            Args:
                params (Parameters): parameters of a given problem instance
        '''
        logger = get_logger()
        logger.info('Started solving given DEA model(s).')
        logger.info('Parameters: %s', params.get_all_params_as_string())
        categories = self.get_categories()
        coefficients, has_same_dmus = self.get_coefficients()

        if has_same_dmus:
            self.show_error('Some DMUs have the same name')
        else:
            if validate_data(categories, coefficients):
                try:

                    self.validate_weights_if_needed()  # MUST be called
                    # before model_builder, because it might
                    # update parameters
                    model_input = construct_input_data_instance(categories,
                                                                coefficients)

                    models, all_params = model_builder.build_models(params,
                                                                    model_input)

                    self.init_before_run(len(models), coefficients)

                    solutions = []

                    state = True
                    param_strs = []
                    all_ranks = []
                    run_date = datetime.datetime.today()
                    start_time = datetime.datetime.now()
                    for count, model_obj in enumerate(models):
                        model = self.decorate_model(model_obj)

                        call_peel_the_onion = params.get_parameter_value(
                            'PEEL_THE_ONION')

                        if call_peel_the_onion:
                            model_solution, ranks, state = (
                                peel_the_onion_method(model))
                            all_ranks.append(ranks)
                        else:
                            model_solution = model.run()

                        str_to_write = create_params_str(all_params[count])
                        param_strs.append(str_to_write)
                        solutions.append(model_solution)
                        try:
                            solutions.append(model.second_solution)
                            param_strs.append(str_to_write + ' second phase')
                        except AttributeError:
                            pass

                    end_time = datetime.datetime.now()
                    diff = end_time - start_time
                    total_seconds = diff.total_seconds()
                    if params.get_parameter_value('RETURN_TO_SCALE') == 'both':
                        derive_returns_to_scale_classification(param_strs, solutions)
                    self.post_process_solutions(solutions, params, param_strs,
                                                all_ranks, run_date,
                                                total_seconds)

                    if state is False:
                        self.show_error('For one of the runs of the '
                                        'peel-the-onion problem is infeasible'
                                        ' or unbounded')
                    self.show_success()
                except Exception as excinfo:
                    self.show_error(excinfo)
                else:
                    logger.info('Given DEA model(s) successfully solved.')
            else:
                self.show_error('Some of the input data is not correct')