Ejemplo n.º 1
0
    def setUp(self):
        self.m = ConcreteModel()
        self.m.z = Var(range(3), domain=Reals, initialize=2.)
        self.m.x = Var(range(2), initialize=2.)
        self.m.x[1] = 1.0

        def blackbox(a, b):
            return sin(a - b)

        def grad_blackbox(args, fixed):
            a, b = args[:2]
            return [cos(a - b), -cos(a - b)]

        self.m.bb = ExternalFunction(blackbox, grad_blackbox)

        self.m.obj = Objective(expr=(self.m.z[0] - 1.0)**2 +
                               (self.m.z[0] - self.m.z[1])**2 +
                               (self.m.z[2] - 1.0)**2 +
                               (self.m.x[0] - 1.0)**4 + (self.m.x[1] - 1.0)**6)
        self.m.c1 = Constraint(expr=(self.m.x[0] * self.m.z[0]**2 +
                                     self.m.bb(self.m.x[0], self.m.x[1]) == 2 *
                                     sqrt(2.0)))
        self.m.c2 = Constraint(expr=self.m.z[2]**4 * self.m.z[1]**2 +
                               self.m.z[1] == 8 + sqrt(2.0))
        self.config = _trf_config()
        self.ext_fcn_surrogate_map_rule = lambda comp, ef: 0
        self.interface = TRFInterface(self.m,
                                      [self.m.z[0], self.m.z[1], self.m.z[2]],
                                      self.ext_fcn_surrogate_map_rule,
                                      self.config)
Ejemplo n.º 2
0
 def test_config_generator(self):
     CONFIG = _trf_config()
     self.assertEqual(CONFIG.solver, 'ipopt')
     self.assertFalse(CONFIG.keepfiles)
     self.assertFalse(CONFIG.tee)
     self.assertFalse(CONFIG.verbose)
     self.assertEqual(CONFIG.trust_radius, 1.0)
     self.assertEqual(CONFIG.minimum_radius, 1e-6)
     self.assertEqual(CONFIG.maximum_radius, 100.0)
     self.assertEqual(CONFIG.maximum_iterations, 50)
     self.assertEqual(CONFIG.feasibility_termination, 1e-5)
     self.assertEqual(CONFIG.step_size_termination, 1e-5)
     self.assertEqual(CONFIG.minimum_feasibility, 1e-4)
     self.assertEqual(CONFIG.switch_condition_kappa_theta, 0.1)
     self.assertEqual(CONFIG.switch_condition_gamma_s, 2.0)
     self.assertEqual(CONFIG.radius_update_param_gamma_c, 0.5)
     self.assertEqual(CONFIG.radius_update_param_gamma_e, 2.5)
     self.assertEqual(CONFIG.ratio_test_param_eta_1, 0.05)
     self.assertEqual(CONFIG.ratio_test_param_eta_2, 0.2)
     self.assertEqual(CONFIG.maximum_feasibility, 50.0)
     self.assertEqual(CONFIG.param_filter_gamma_theta, 0.01)
     self.assertEqual(CONFIG.param_filter_gamma_f, 0.01)