コード例 #1
0
ファイル: test_solvers.py プロジェクト: willigott/framed
    def test_glpk_lazy_loading(self):

        self.solver_one = GlpkSolver()
        self.solver_one.build_problem(self.model)
        sol_one = FBA(self.model, solver=self.solver_one)

        self.solver_two = GlpkSolverLazy()
        self.solver_two.build_problem(self.model)
        sol_two = FBA(self.model, solver=self.solver_two)

        self.assertAlmostEqual(sol_one.fobj, sol_two.fobj, places=5)
コード例 #2
0
ファイル: test_solvers.py プロジェクト: willigott/framed
    def test_glpk_against_gurobi(self):
        
        self.solver_one = GurobiSolver()
        self.solver_one.build_problem(self.model)
        sol_one = FBA(self.model, solver=self.solver_one)

        
        self.solver_two = GlpkSolver()
        self.solver_two.build_problem(self.model)
        sol_two = FBA(self.model, solver=self.solver_two)

        self.assertAlmostEqual(sol_one.fobj, sol_two.fobj, places=5)
コード例 #3
0
ファイル: test_solvers.py プロジェクト: willigott/framed
    def test_remove_constraint(self):
        """ This tests works only for the ecoli core model.
        """
        constr_id = "M_glu_L_c"

        self.solver_one = GlpkSolverLazy()
        self.solver_one.build_problem(self.model)
        self.solver_one.remove_constraint(constr_id)
        sol_one = FBA(self.model, solver=self.solver_one)

        self.solver_two = GlpkSolver()
        self.solver_two.build_problem(self.model)
        nRows_before = glp_get_num_rows(self.solver_two.problem)
        self.solver_two.remove_constraint(constr_id)
        nRows_after = glp_get_num_rows(self.solver_two.problem)
        sol_two = FBA(self.model, solver=self.solver_two)

        self.assertEqual(nRows_before, nRows_after + 1)
        self.assertAlmostEqual(sol_one.fobj, sol_two.fobj, places=5)
コード例 #4
0
ファイル: test_solvers.py プロジェクト: willigott/framed
    def test_remove_variable(self):
        """ This tests works only for the ecoli core model.
        """
        var_id = "R_SUCOAS"

        self.solver_one = GlpkSolverLazy()
        self.solver_one.build_problem(self.model)
        self.solver_one.remove_variable(var_id)
        sol_one = FBA(self.model, solver=self.solver_one)

        self.solver_two = GlpkSolver()
        self.solver_two.build_problem(self.model)

        nCols_before = glp_get_num_cols(self.solver_two.problem)
        self.solver_two.remove_variable(var_id)
        nCols_after = glp_get_num_cols(self.solver_two.problem)
        sol_two = FBA(self.model, solver=self.solver_two)

        self.assertEqual(nCols_before, nCols_after + 1)
        self.assertAlmostEqual(sol_one.fobj, sol_two.fobj, places=5)
コード例 #5
0
ファイル: test_solvers.py プロジェクト: willigott/framed
class SolverGLPKTest(unittest.TestCase):

    def setUp(self):
        self.model = load_sbml_model(SMALL_TEST_MODEL, kind=CONSTRAINT_BASED)
        fix_bigg_model(self.model)

    def test_glpk_alone(self):
        result = solve_lp_prob_glpk()
        self.assertEqual(result[0], 1.25)
        self.assertEqual(result[1], 45)
        self.assertEqual(result[2], 6.25)

    def test_glpk_against_gurobi(self):
        
        self.solver_one = GurobiSolver()
        self.solver_one.build_problem(self.model)
        sol_one = FBA(self.model, solver=self.solver_one)

        
        self.solver_two = GlpkSolver()
        self.solver_two.build_problem(self.model)
        sol_two = FBA(self.model, solver=self.solver_two)

        self.assertAlmostEqual(sol_one.fobj, sol_two.fobj, places=5)

    def test_glpk_milp_alone(self):
        # binary variables only
        result = solve_milp_bin_prob_glpk()
        self.assertEqual(result[0], -14)
        self.assertEqual(result[1], 1)
        self.assertEqual(result[2], 1)
        self.assertEqual(result[3], 0)
        self.assertEqual(result[4], 0)


    def test_glpk_lazy_loading(self):

        self.solver_one = GlpkSolver()
        self.solver_one.build_problem(self.model)
        sol_one = FBA(self.model, solver=self.solver_one)

        self.solver_two = GlpkSolverLazy()
        self.solver_two.build_problem(self.model)
        sol_two = FBA(self.model, solver=self.solver_two)

        self.assertAlmostEqual(sol_one.fobj, sol_two.fobj, places=5)

    def test_remove_constraint(self):
        """ This tests works only for the ecoli core model.
        """
        constr_id = "M_glu_L_c"

        self.solver_one = GlpkSolverLazy()
        self.solver_one.build_problem(self.model)
        self.solver_one.remove_constraint(constr_id)
        sol_one = FBA(self.model, solver=self.solver_one)

        self.solver_two = GlpkSolver()
        self.solver_two.build_problem(self.model)
        nRows_before = glp_get_num_rows(self.solver_two.problem)
        self.solver_two.remove_constraint(constr_id)
        nRows_after = glp_get_num_rows(self.solver_two.problem)
        sol_two = FBA(self.model, solver=self.solver_two)

        self.assertEqual(nRows_before, nRows_after + 1)
        self.assertAlmostEqual(sol_one.fobj, sol_two.fobj, places=5)

    def test_remove_variable(self):
        """ This tests works only for the ecoli core model.
        """
        var_id = "R_SUCOAS"

        self.solver_one = GlpkSolverLazy()
        self.solver_one.build_problem(self.model)
        self.solver_one.remove_variable(var_id)
        sol_one = FBA(self.model, solver=self.solver_one)

        self.solver_two = GlpkSolver()
        self.solver_two.build_problem(self.model)

        nCols_before = glp_get_num_cols(self.solver_two.problem)
        self.solver_two.remove_variable(var_id)
        nCols_after = glp_get_num_cols(self.solver_two.problem)
        sol_two = FBA(self.model, solver=self.solver_two)

        self.assertEqual(nCols_before, nCols_after + 1)
        self.assertAlmostEqual(sol_one.fobj, sol_two.fobj, places=5)