def test_build_models_two_models(): params, model_input = _construct_params_and_input() params.update_parameter('RETURN_TO_SCALE', 'both') models, all_params = build_models(params, model_input) assert len(models) == 2 and len(all_params) == 2 assert (all_params[0].get_parameter_value('RETURN_TO_SCALE') == 'VRS' or all_params[1].get_parameter_value('RETURN_TO_SCALE') == 'VRS') assert (all_params[0].get_parameter_value('RETURN_TO_SCALE') == 'CRS' or all_params[1].get_parameter_value('RETURN_TO_SCALE') == 'CRS') _check_params_are_the_same(all_params[0], params, ['RETURN_TO_SCALE']) _check_params_are_the_same(all_params[1], params, ['RETURN_TO_SCALE'])
def test_build_models_two_models(): params, model_input = _construct_params_and_input() params.update_parameter('RETURN_TO_SCALE', 'both') models, all_params = build_models(params, model_input) assert len(models) == 2 and len(all_params) == 2 assert (all_params[0].get_parameter_value('RETURN_TO_SCALE') == 'VRS' or all_params[1].get_parameter_value('RETURN_TO_SCALE') == 'VRS') assert (all_params[0].get_parameter_value('RETURN_TO_SCALE') == 'CRS' or all_params[1].get_parameter_value('RETURN_TO_SCALE') == 'CRS') _check_params_are_the_same(all_params[0], params, ['RETURN_TO_SCALE']) _check_params_are_the_same(all_params[1], params, ['RETURN_TO_SCALE'])
def test_build_models_four_models(): params, model_input = _construct_params_and_input() params.update_parameter('RETURN_TO_SCALE', 'both') params.update_parameter('ORIENTATION', 'both') models, all_params = build_models(params, model_input) assert len(models) == 4 and len(all_params) == 4 assert (all_params[0].get_parameter_value('RETURN_TO_SCALE') == 'VRS' or all_params[1].get_parameter_value('RETURN_TO_SCALE') == 'VRS') assert (all_params[0].get_parameter_value('RETURN_TO_SCALE') == 'CRS' or all_params[1].get_parameter_value('RETURN_TO_SCALE') == 'CRS') assert (all_params[0].get_parameter_value('ORIENTATION') == 'input' or all_params[1].get_parameter_value('ORIENTATION') == 'input') assert (all_params[0].get_parameter_value('ORIENTATION') == 'output' or all_params[1].get_parameter_value('ORIENTATION') == 'output') for params_to_check in all_params: _check_params_are_the_same(params_to_check, params, [ 'RETURN_TO_SCALE', 'ORIENTATION'])
def test_build_models_four_models(): params, model_input = _construct_params_and_input() params.update_parameter('RETURN_TO_SCALE', 'both') params.update_parameter('ORIENTATION', 'both') models, all_params = build_models(params, model_input) assert len(models) == 4 and len(all_params) == 4 assert (all_params[0].get_parameter_value('RETURN_TO_SCALE') == 'VRS' or all_params[1].get_parameter_value('RETURN_TO_SCALE') == 'VRS') assert (all_params[0].get_parameter_value('RETURN_TO_SCALE') == 'CRS' or all_params[1].get_parameter_value('RETURN_TO_SCALE') == 'CRS') assert (all_params[0].get_parameter_value('ORIENTATION') == 'input' or all_params[1].get_parameter_value('ORIENTATION') == 'input') assert (all_params[0].get_parameter_value('ORIENTATION') == 'output' or all_params[1].get_parameter_value('ORIENTATION') == 'output') for params_to_check in all_params: _check_params_are_the_same(params_to_check, params, ['RETURN_TO_SCALE', 'ORIENTATION'])
def test_abs_restrictions_env_model_output(data): filename = 'tests/DEA_Harish_parameters.txt' params = parse_parameters_from_file(filename) categories, data, dmu_name, sheet_name = read_data( params.get_parameter_value('DATA_FILE')) coefficients, has_same_dmus = convert_to_dictionary(data) model_input = construct_input_data_instance(categories, coefficients) models, all_params = build_models(params, model_input) assert len(models) == 1 and len(all_params) == 1 model = models[0] start_time = datetime.datetime.now() model_solution = model.run() end_time = datetime.datetime.now() bounds = {'Urban Roads (%)': (None, 0.003)} utils_for_tests.check_if_category_is_within_abs_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_abs_constraints_env_outoriented_output.xls')
def test_abs_restrictions_env_model_output(data): filename = 'tests/DEA_Harish_parameters.txt' params = parse_parameters_from_file(filename) categories, data, dmu_name, sheet_name = read_data( params.get_parameter_value('DATA_FILE')) coefficients, has_same_dmus = convert_to_dictionary(data) model_input = construct_input_data_instance(categories, coefficients) models, all_params = build_models(params, model_input) assert len(models) == 1 and len(all_params) == 1 model = models[0] start_time = datetime.datetime.now() model_solution = model.run() end_time = datetime.datetime.now() bounds = {'Urban Roads (%)': (None, 0.003)} utils_for_tests.check_if_category_is_within_abs_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_abs_constraints_env_outoriented_output.xls')
def test_build_models_one_model(): params, model_input = _construct_params_and_input() models, all_params = build_models(params, model_input) assert len(models) == 1 and len(all_params) == 1 _check_params_are_the_same(all_params[0], params, [])
def test_build_models_one_model(): params, model_input = _construct_params_and_input() models, all_params = build_models(params, model_input) assert len(models) == 1 and len(all_params) == 1 _check_params_are_the_same(all_params[0], params, [])
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')
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')