Esempio n. 1
0
    def test_wrap_problem_lambda(self):
        l = lambda _: 0.0
        ioh.problem.wrap_real_problem(l, "f")
        p = ioh.get_problem("f")
        p([0] * 5)

        ioh.problem.wrap_real_problem(l, "f")
        p2 = ioh.get_problem("f")
        self.assertEqual(p.meta_data.problem_id, p2.meta_data.problem_id)
        self.assertEqual(p.meta_data.name, p2.meta_data.name)
Esempio n. 2
0
 def test_flatfile(self):
     pr = ioh.get_problem("Sphere", 1, 5)
     p = [ioh.logger.property.CURRENT_Y_BEST]
     t = [ioh.logger.trigger.ON_IMPROVEMENT]
     l = ioh.logger.FlatFile(t, p, separator=" ")
     pr.attach_logger(l)
     self.assertEqual(os.path.realpath("./"),
                      os.path.realpath(l.output_directory))
     pr([0] * 5)
     self.assertTrue(os.path.isfile("IOH.dat"))
Esempio n. 3
0
    def test_eaf(self):
        p = ioh.get_problem(1, 1, 5)
        l = ioh.logger.EAH(0, 20, 10, 0, 100, 10)
        self.assertEqual(l.error_range.min, 0)
        self.assertEqual(l.error_range.max, 20)
        self.assertEqual(l.error_range.size, 10)
        self.assertEqual(l.eval_range.min, 0)
        self.assertEqual(l.eval_range.max, 100)
        self.assertEqual(l.eval_range.size, 10)
        p.attach_logger(l)

        for i in range(10):
            p([i] * 5)

        self.assertEqual(list(l.data.keys()), [1])
Esempio n. 4
0
    def test_analyzer(self):
        pr = ioh.get_problem("Sphere", 1, 5)
        c = Container()
        l = ioh.logger.Analyzer([ioh.logger.trigger.ALWAYS])
        l.set_experiment_attributes({"x": "1"})
        l.watch(c, ["xv", "xy"])
        l.add_run_attributes(c, "xv")
        pr.attach_logger(l)

        for c.xv in range(4):
            for i in range(5):
                c.xy = i * 10
                pr([i] * 5)
            pr.reset()

        self.assertTrue(os.path.isdir("ioh_data"))
    def test_file_comparisons(self):
        for test_file in  ("pbofitness16.in", "pbofitness100.in",
                           "bbobfitness5.in", "bbobfitness20.in", ):
            with self.subTest(test_file=test_file):
                suite, dim = test_file.split("fitness")
                dim = int(dim[:-3])
                dtype = float if suite == 'bbob' else int
                tol = .01 if suite == 'bbob' else 0.000099

                with open(os.path.join(DATA_DIR, test_file)) as f:
                    for line in f:
                        fid, iid, x, y = line.split()
                        if "," in x:
                            x = x.split(",")
                        x = list(map(dtype, x))
                        p = ioh.get_problem(int(fid), int(iid), dim, suite.upper())
                        self.assertTrue(math.isclose(p(x), float(y), abs_tol = tol))
Esempio n. 6
0
    def test_triggers(self):
        always = ioh.logger.trigger.Always()
        on_improvement = ioh.logger.trigger.OnImprovement()
        at = ioh.logger.trigger.At({1, 22})
        self.assertSetEqual(at.time_points, {1, 22})

        each = ioh.logger.trigger.Each(10, 2)
        self.assertEqual(each.interval, 10)
        self.assertEqual(each.starting_at, 2)

        during = ioh.logger.trigger.During({(10, 25), (30, 40)})
        self.assertEqual(during.time_ranges, {(10, 25), (30, 40)})

        log_info = ioh.LogInfo(22, 0, 0, 0, ioh.RealSolution([0, 1], 0),
                               ioh.RealSolution([1, 0], 0))
        problem = ioh.get_problem(1, 1, 2)
        for t in (always, on_improvement, at, each, during):
            self.assertTrue(t(log_info, problem.meta_data))
Esempio n. 7
0
 def test_wrap_problem_builtins(self):
     for f in (sum, min, max):
         ioh.problem.wrap_real_problem(f, f.__name__)
         p = ioh.get_problem(f.__name__)
         y = p([0] * 5)
         self.assertEqual(y, 0.0)
Esempio n. 8
0
 def w():
     ioh.problem.wrap_real_problem(lambda _: 0.0, "l")
     return ioh.get_problem("l")
 def test_evaluation_pbo_problems(self):
     for fid in range(1,26):
         f = ioh.get_problem(fid, 1 ,4, "PBO")
         self.assertGreater(f([0,0,0,0]), -1000) 
Esempio n. 10
0
 def test_evaluation_bbob_problems(self):
     for fid in range(1,25):
         f = ioh.get_problem(fid, 1 ,5, "BBOB")
         self.assertGreater(f([0,0,0,0,0]), -1000)
Esempio n. 11
0
 def test_get_problem(self):
     self.assertIsInstance(ioh.get_problem(1, 1, 2, "BBOB"), ioh.problem.Sphere)
     self.assertIsInstance(ioh.get_problem("Sphere", 1, 2, "BBOB"), ioh.problem.Sphere)
     self.assertIsInstance(ioh.get_problem("Sphere", 1, 2), ioh.problem.Sphere)
     self.assertIsInstance(ioh.get_problem(1, 1, 2, "PBO"), ioh.problem.OneMax)
     self.assertIsInstance(ioh.get_problem("OneMax", 1, 2, "PBO"), ioh.problem.OneMax)