Exemple #1
0
    def test_variable_size_generator(self):
        self.args.setdefault('variable_candidate_size', True)

        self.args['candidate_size'] = 10
        for _ in range(10000):
            candidate = set_generator(self.random, self.args)
            self.assertLessEqual(len(candidate), 10)
            candidate = unique_set_generator(self.random, self.args)
            self.assertLessEqual(len(candidate), 10)

        self.args['candidate_size'] = 20
        for _ in range(10000):
            candidate = set_generator(self.random, self.args)
            self.assertLessEqual(len(candidate), 20)
            candidate = unique_set_generator(self.random, self.args)
            self.assertLessEqual(len(candidate), 20)
Exemple #2
0
 def setUp(self):
     self.model = TEST_MODEL
     self.representation = [r.id for r in self.model.reactions]
     random = Random(SEED)
     args = {"representation": self.representation}
     self.solutions = BestSolutionArchiver()
     for _ in range(10000):
         self.solutions.add(set_generator(random, args), random.random(), 100)
     self.decoder = ReactionKnockoutDecoder(self.representation, self.model)
Exemple #3
0
    def test_set_generator(self):
        random = Random(SEED)
        representation = ["a", "b", "c", "d", "e", "f"]
        candidate_size = 5
        variable_candidate_size = False
        expected = [[2, 1, 5, 0, 4],
                    [0, 4, 3, 2, 5],
                    [1, 0, 3, 2, 5],
                    [2, 3, 1, 4, 5],
                    [4, 5, 3, 0, 2]]

        for i in range(len(expected)):
            candidate = set_generator(random, dict(representation=representation,
                                                   candidate_size=candidate_size,
                                                   variable_candidate_size=variable_candidate_size))
            self.assertEqual(candidate, expected[i])