def test_gutmann_ex8_1_4_log(self): """Check solution of ex8_1_4 with Gutmann, log scaling, infstep. Sampling-based global search. """ bb = ti.TestBlackBox('ex8_1_4') optimum = bb._function.optimum_value for seed in self.rand_seeds: print() print('Solving branin with random seed ' + '{:d}'.format(seed)) settings = RbfSettings(algorithm='Gutmann', rbf='multiquadric', global_search_method='sampling', target_objval=optimum, eps_opt=self.eps_opt, max_iterations=200, max_evaluations=300, function_scaling='log', do_infstep=True, rand_seed=seed) alg = ra.OptAlgorithm(settings, bb) res = alg.optimize() msg = 'Could not solve branin with Gutmann\'s algorithm' target = optimum + (abs(optimum) * self.eps_opt if abs(optimum) > settings.eps_zero else self.eps_opt) self.assertLessEqual(res[0], target, msg=msg)
def test_gutmann_branin_noisy_with_init(self): """Check solution of noisy braning with Gutmann, solver.""" bb = ti.TestNoisyBlackBox('branin', 0.1, 0.01) optimum = bb._function.optimum_value for seed in self.rand_seeds: print() print('Solving branin with random seed ' + '{:d}'.format(seed)) settings = RbfSettings(algorithm='Gutmann', global_search_method='solver', target_objval=optimum, eps_opt=self.eps_opt, max_iterations=200, max_evaluations=300, fast_objfun_rel_error=0.1, fast_objfun_abs_error=0.01, rand_seed=seed) init_node_pos = [[0, 0], [-2, 2], [5, 10]] init_node_val = [bb._function.evaluate(x) for x in init_node_pos] alg = ra.OptAlgorithm(settings, bb, init_node_pos, init_node_val) res = alg.optimize() msg = ('Could not solve noisy branin with init and ' + 'Gutmann\'s algorithm') target = optimum + (abs(optimum) * self.eps_opt if abs(optimum) > settings.eps_zero else self.eps_opt) self.assertLessEqual(res[0], target, msg=msg)
def test_state_reload(self): """Check solution of ex8_1_4 after state save/reload.""" bb = ti.TestBlackBox('ex8_1_4') optimum = bb._function.optimum_value handle, filename = tempfile.mkstemp() for seed in self.rand_seeds: print() print('Solving ex8_1_4 with random seed ' + '{:d}'.format(seed)) settings = RbfSettings(algorithm='MSRSM', rbf='linear', target_objval=optimum, eps_opt=self.eps_opt, max_iterations=200, max_evaluations=300, rand_seed=seed) alg = ra.OptAlgorithm(settings, bb) res = alg.optimize(5) alg.save_to_file(filename) alg_reload = ra.OptAlgorithm.load_from_file(filename) res = alg_reload.optimize() msg = 'Could not solve ex8_1_4 after reload' target = optimum + (abs(optimum) * self.eps_opt if abs(optimum) > settings.eps_zero else self.eps_opt) self.assertLessEqual(res[0], target, msg=msg) os.close(handle) os.remove(filename)
def test_msrsm_parallel_st_miqp3_no_local_search(self): """Check solution of st_miqp3 with MSRSM and no local search. Solver solution of global search problems.""" bb = ti.TestBlackBox('st_miqp3') optimum = bb._function.optimum_value for seed in self.rand_seeds: print() print('Solving st_miqp3 with random seed ' + '{:d}'.format(seed)) settings = RbfSettings(rbf='cubic', global_search_method='genetic', algorithm='MSRSM', target_objval=optimum, eps_opt=self.eps_opt, max_iterations=200, max_evaluations=300, num_cpus=4, local_search_box_scaling=10000, rand_seed=seed) alg = ra.OptAlgorithm(settings, bb) res = alg.optimize() msg = 'Could not solve st_miqp3 with MSRSM algorithm' target = optimum + (abs(optimum) * self.eps_opt if abs(optimum) > settings.eps_zero else self.eps_opt) self.assertLessEqual(res[0], target, msg=msg)
def test_time_limit(self): """Verify that time limits are satisfied.""" bb = ti.TestBlackBox('hartman6') optimum = bb._function.optimum_value for seed in self.rand_seeds: print() print('Solving hartman6 with random seed ' + '{:d}'.format(seed)) settings = RbfSettings(algorithm='MSRSM', global_search_method='solver', target_objval=optimum, eps_opt=0.0, max_clock_time=2.0, rand_seed=seed) start_time = time.time() alg = ra.OptAlgorithm(settings, bb) res = alg.optimize() tot_time = time.time() - start_time msg = 'Time limit exceeded with MSRSM algorithm' self.assertLessEqual(tot_time, 5.0, msg=msg)
def test_msrsm_prob03(self): """Check solution of prob03 with the MSRSM algorithm, genetic.""" bb = ti.TestBlackBox('prob03') optimum = bb._function.optimum_value for seed in self.rand_seeds: print() print('Solving prob03 with random seed ' + '{:d}'.format(seed)) settings = RbfSettings(algorithm='MSRSM', global_search_method='genetic', target_objval=optimum, eps_opt=self.eps_opt, max_iterations=200, max_evaluations=300, rand_seed=seed) alg = ra.OptAlgorithm(settings, bb) res = alg.optimize() msg = 'Could not solve prob03 with MSRSM algorithm' target = optimum + (abs(optimum) * self.eps_opt if abs(optimum) > settings.eps_zero else self.eps_opt) self.assertLessEqual(res[0], target, msg=msg)
def test_msrsm_parallel_ex8_1_4(self): """Check solution of ex8_1_4 with the MSRSM algorithm, sampling.""" bb = ti.TestBlackBox('ex8_1_4') optimum = bb._function.optimum_value for seed in self.rand_seeds: print() print('Solving ex8_1_4 with random seed ' + '{:d}'.format(seed)) settings = RbfSettings(algorithm='MSRSM', global_search_method='sampling', rbf='linear', target_objval=optimum, eps_opt=self.eps_opt, max_iterations=200, max_evaluations=300, num_cpus=2, rand_seed=seed) alg = ra.OptAlgorithm(settings, bb) res = alg.optimize() msg = 'Could not solve ex8_1_4 with MSRSM algorithm' target = optimum + (abs(optimum) * self.eps_opt if abs(optimum) > settings.eps_zero else self.eps_opt) self.assertLessEqual(res[0], target, msg=msg)
def test_gutmann_parallel_prob03(self): """Check solution of prob03 with Gutmann's method, sampling.""" bb = ti.TestBlackBox('prob03') optimum = bb._function.optimum_value for seed in self.rand_seeds: print() print('Solving prob03 with random seed ' + '{:d}'.format(seed)) settings = RbfSettings(algorithm='Gutmann', global_search_method='sampling', rbf='cubic', target_objval=optimum, eps_opt=self.eps_opt, max_iterations=200, max_evaluations=300, num_cpus=2, rand_seed=seed) alg = ra.OptAlgorithm(settings, bb) res = alg.optimize() msg = 'Could not solve prob03 with Gutmann\'s algorithm' target = optimum + (abs(optimum) * self.eps_opt if abs(optimum) > settings.eps_zero else self.eps_opt) self.assertLessEqual(res[0], target, msg=msg)
def test_gutmann_st_miqp3_noisy(self): """Check solution of noisy st_miqp3 with Gutmann, genetic.""" bb = ti.TestNoisyBlackBox('st_miqp3', 0.1, 0.01) optimum = bb._function.optimum_value for seed in self.rand_seeds: print() print('Solving st_miqp3 with random seed ' + '{:d}'.format(seed)) settings = RbfSettings(algorithm='Gutmann', global_search_method='genetic', target_objval=optimum, eps_opt=self.eps_opt, max_iterations=200, max_evaluations=300, fast_objfun_rel_error=0.1, fast_objfun_abs_error=0.01, rand_seed=seed) alg = ra.OptAlgorithm(settings, bb) res = alg.optimize() msg = 'Could not solve st_miqp3 with Gutmann\'s algorithm' target = optimum + (abs(optimum) * self.eps_opt if abs(optimum) > settings.eps_zero else self.eps_opt) self.assertLessEqual(res[0], target, msg=msg)
def test_msrsm_parallel_prob03_noisy(self): """Check solution of noisy prob03 with MSRSM, sampling.""" bb = ti.TestNoisyBlackBox('prob03', 0.1, 0.01) optimum = bb._function.optimum_value for seed in self.rand_seeds: print() print('Solving prob03 with random seed ' + '{:d}'.format(seed)) settings = RbfSettings(algorithm='MSRSM', global_search_method='sampling', target_objval=optimum, eps_opt=self.eps_opt, max_iterations=200, max_evaluations=300, num_cpus=4, fast_objfun_rel_error=0.1, fast_objfun_abs_error=0.01, rand_seed=seed) alg = ra.OptAlgorithm(settings, bb) res = alg.optimize() msg = 'Could not solve prob03 with MSRSM algorithm' target = optimum + (abs(optimum) * self.eps_opt if abs(optimum) > settings.eps_zero else self.eps_opt) self.assertLessEqual(res[0], target, msg=msg)