def test_netlib(netlib_tar_path=os.path.join(os.path.dirname(__file__), 'data/netlib_lp_problems.tar.gz')): """ Test netlib with glpk interface """ tar = tarfile.open(netlib_tar_path) model_paths_in_tar = glob.fnmatch.filter(tar.getnames(), '*.SIF') for model_path_in_tar in model_paths_in_tar: print(model_path_in_tar) netlib_id = os.path.basename(model_path_in_tar).replace('.SIF', '') # TODO: get the following problems to work # E226 seems to be a MPS related problem, see http://lists.gnu.org/archive/html/bug-glpk/2003-01/msg00003.html if netlib_id in ('AGG', 'E226', 'SCSD6', 'BLEND', 'DFL001', 'FORPLAN', 'GFRD-PNC', 'SIERRA'): # def test_skip(netlib_id): # raise SkipTest('Skipping netlib problem %s ...' % netlib_id) # test_skip(netlib_id) # class TestWeirdNetlibProblems(unittest.TestCase): # @unittest.skip('Skipping netlib problem') # def test_fail(): # pass continue # TODO: For now, test only models that are covered by the final netlib results else: if netlib_id not in THE_FINAL_NETLIB_RESULTS.keys(): continue fhandle = tar.extractfile(model_path_in_tar) problem = read_netlib_sif_cplex(fhandle) model = Model(problem=problem) model.configuration.presolve = True model.configuration.verbosity = 3 func = partial(check_dimensions, problem, model) func.description = "test_netlib_check_dimensions_%s (%s)" % ( netlib_id, os.path.basename(str(__file__))) yield func model.optimize() if model.status == 'optimal': model_objval = model.objective.value else: raise Exception('No optimal solution found for netlib model %s' % netlib_id) func = partial(check_objval, problem, model_objval) func.description = "test_netlib_check_objective_value_%s (%s)" % ( netlib_id, os.path.basename(str(__file__))) yield func func = partial(check_objval_against_the_final_netlib_results, netlib_id, model_objval) func.description = "test_netlib_check_objective_value__against_the_final_netlib_results_%s (%s)" % ( netlib_id, os.path.basename(str(__file__))) yield func if os.getenv('CI', 'false') != 'true': # check that a cloned model also gives the correct result model = Model.clone(model, use_json=False, use_lp=False) model.optimize() if model.status == 'optimal': model_objval = model.objective.value else: raise Exception('No optimal solution found for netlib model %s' % netlib_id) func = partial(check_objval_against_the_final_netlib_results, netlib_id, model_objval) func.description = "test_netlib_check_objective_value__against_the_final_netlib_results_after_cloning_%s (%s)" % ( netlib_id, os.path.basename(str(__file__))) yield func
def test_netlib(netlib_tar_path=os.path.join(os.path.dirname(__file__), 'data/netlib_lp_problems.tar.gz')): """ Test netlib with glpk interface """ tar = tarfile.open(netlib_tar_path) model_paths_in_tar = glob.fnmatch.filter(tar.getnames(), '*.SIF') for model_path_in_tar in model_paths_in_tar: print(model_path_in_tar) netlib_id = os.path.basename(model_path_in_tar).replace('.SIF', '') # TODO: get the following problems to work # E226 seems to be a MPS related problem, see http://lists.gnu.org/archive/html/bug-glpk/2003-01/msg00003.html if netlib_id in ('AGG', 'E226', 'SCSD6', 'BLEND', 'DFL001', 'FORPLAN', 'GFRD-PNC', 'SIERRA'): # def test_skip(netlib_id): # raise SkipTest('Skipping netlib problem %s ...' % netlib_id) # test_skip(netlib_id) # class TestWeirdNetlibProblems(unittest.TestCase): # @unittest.skip('Skipping netlib problem') # def test_fail(): # pass continue # TODO: For now, test only models that are covered by the final netlib results else: if netlib_id not in THE_FINAL_NETLIB_RESULTS.keys(): continue fhandle = tar.extractfile(model_path_in_tar) problem = read_netlib_sif_cplex(fhandle) model = Model(problem=problem) model.configuration.presolve = True model.configuration.verbosity = 3 func = partial(check_dimensions, problem, model) func.description = "test_netlib_check_dimensions_%s (%s)" % ( netlib_id, os.path.basename(str(__file__))) yield func model.optimize() if model.status == 'optimal': model_objval = model.objective.value else: raise Exception('No optimal solution found for netlib model %s' % netlib_id) func = partial(check_objval, problem, model_objval) func.description = "test_netlib_check_objective_value_%s (%s)" % ( netlib_id, os.path.basename(str(__file__))) yield func func = partial(check_objval_against_the_final_netlib_results, netlib_id, model_objval) func.description = "test_netlib_check_objective_value__against_the_final_netlib_results_%s (%s)" % ( netlib_id, os.path.basename(str(__file__))) yield func if not os.getenv('TRAVIS', False): # check that a cloned model also gives the correct result model = Model.clone(model, use_json=False, use_lp=False) model.optimize() if model.status == 'optimal': model_objval = model.objective.value else: raise Exception('No optimal solution found for netlib model %s' % netlib_id) func = partial(check_objval_against_the_final_netlib_results, netlib_id, model_objval) func.description = "test_netlib_check_objective_value__against_the_final_netlib_results_after_cloning_%s (%s)" % ( netlib_id, os.path.basename(str(__file__))) yield func