示例#1
0
    def test_number_of_knockouts(self):
        of_max = number_of_knockouts(sense='max')
        of_min = number_of_knockouts(sense='min')

        f1 = of_max(None, None, [['a', 'b'], ['a', 'b']])
        f2 = of_max(None, None, [['a', 'b'], ['a', 'b', 'c']])
        self.assertGreater(f2, f1)

        f1 = of_min(None, None, [['a', 'b'], ['a', 'b']])
        f2 = of_min(None, None, [['a', 'b'], ['a', 'b', 'c']])
        self.assertGreater(f1, f2)
示例#2
0
    def test_run_multiobjective(self):
        result_file = os.path.join(CURRENT_PATH, "data", "reaction_knockout_multi_objective.pkl")
        objective1 = biomass_product_coupled_yield(
            "Biomass_Ecoli_core_N_LPAREN_w_FSLASH_GAM_RPAREN__Nmet2",
            "EX_ac_LPAREN_e_RPAREN_",
            "EX_glc_LPAREN_e_RPAREN_")

        objective2 = number_of_knockouts()
        objective = [objective1, objective2]

        rko = ReactionKnockoutOptimization(model=self.model,
                                           simulation_method=fba,
                                           objective_function=objective,
                                           heuristic_method=inspyred.ec.emo.NSGA2,
                                           seed=SEED)

        # self.assertEqual(rko.random.random(), 0.1915194503788923)

        results = rko.run(max_evaluations=3000, pop_size=10, view=SequentialView())

        # print(rko.random.random(), 0.545818634701)

        with open(result_file, 'rb') as in_file:
            if six.PY3:
                expected_results = pickle.load(in_file, encoding="latin1")
            else:
                expected_results = pickle.load(in_file)

        assert_frame_equal(results.solutions, expected_results.solutions)
示例#3
0
    def test_change_objective_function(self):
        single_objective_heuristic = HeuristicOptimization(
            model=self.model,
            objective_function=self.single_objective_function,
        )

        nok = number_of_knockouts()

        single_objective_heuristic.objective_function = nok
        self.assertEqual(nok, single_objective_heuristic.objective_function)
        self.assertFalse(single_objective_heuristic.is_mo())
        self.assertRaises(TypeError,
                          single_objective_heuristic.objective_function,
                          self.multiobjective_function)

        single_objective_heuristic.objective_function = [nok]
        self.assertEqual(nok, single_objective_heuristic.objective_function)
        self.assertFalse(single_objective_heuristic.is_mo())
        self.assertRaises(TypeError, single_objective_heuristic.objective_function, self.multiobjective_function)

        multiobjective_heuristic = HeuristicOptimization(
            model=self.model,
            objective_function=self.multiobjective_function,
            heuristic_method=inspyred.ec.emo.NSGA2
        )

        multiobjective_heuristic.objective_function = nok
        self.assertEqual(len(multiobjective_heuristic.objective_function), 1)
        self.assertEqual(multiobjective_heuristic.objective_function[0], nok)
        self.assertTrue(multiobjective_heuristic.is_mo())
示例#4
0
 def setUp(self):
     self.model = TEST_MODEL
     self.single_objective_function = product_yield('product', 'substrate')
     self.multiobjective_function = [
         product_yield('product', 'substrate'),
         number_of_knockouts()
     ]