Esempio n. 1
0
    def test_objective(self):

        w_estimates = np.array([5.0, 5.0])
        z_estimates = np.array([2.0, 2.0])
        rho = 2.0
        nlp = AdmmNLP(self.pyomo_nlp,
                      self.coupling_vars,
                      rho=rho,
                      w_estimates=w_estimates,
                      z_estimates=z_estimates)

        hessian_base = self.model.hessian_f
        c = self.model.grad_f
        A = np.array([[1, 0, 0], [0, 0, 1]], dtype=np.double)
        x = nlp.create_vector_x()
        x.fill(1.0)
        f = 0.5 * x.transpose().dot(hessian_base.dot(x)) + c.dot(x)
        difference = A.dot(x) - z_estimates
        f += w_estimates.dot(difference)
        f += 0.5 * rho * np.linalg.norm(difference)**2
        self.assertEqual(f, nlp.objective(x))
Esempio n. 2
0
    def test_objective(self):

        w_estimates = np.array([5.0, 5.0])
        z_estimates = np.array([2.0, 2.0])
        rho = 2.0
        nlp = AdmmNLP(self.pyomo_nlp,
                       self.coupling_vars,
                       rho=rho,
                       w_estimates=w_estimates,
                       z_estimates=z_estimates)

        hessian_base = self.model.hessian_f
        c = self.model.grad_f
        A = np.array([[1, 0, 0], [0, 0, 1]], dtype=np.double)
        x = nlp.create_vector_x()
        x.fill(1.0)
        f = 0.5 * x.transpose().dot(hessian_base.dot(x)) + c.dot(x)
        difference = A.dot(x) - z_estimates
        f += w_estimates.dot(difference)
        f += 0.5 * rho * np.linalg.norm(difference)**2
        self.assertEqual(f, nlp.objective(x))

        # second nlp
        w_estimates = np.array([1.0, 2.0, 3.0])
        z_estimates = np.array([3.0, 4.0, 5.0])
        nlp = AdmmNLP(self.pyomo_nlp2,
                      self.coupling_vars2,
                      rho=5.0,
                      w_estimates=w_estimates,
                      z_estimates=z_estimates)

        m = self.model2
        transform = AdmmModel()
        aug_model = transform.create_using(m,
                                           complicating_vars=[m.x[1], m.x[3], m.x[5]],
                                           z_estimates=z_estimates,
                                           w_estimates=w_estimates,
                                           rho=5.0)
        nl = PyomoNLP(aug_model)

        x = nlp.create_vector_x()
        self.assertAlmostEqual(nlp.objective(x), nl.objective((x)))

        # third nlp
        w_estimates = np.array([1.0])
        z_estimates = np.array([3.0])
        nlp = AdmmNLP(self.pyomo_nlp3,
                      self.coupling_vars3,
                      rho=7.0,
                      w_estimates=w_estimates,
                      z_estimates=z_estimates)

        m = self.model3
        transform = AdmmModel()
        aug_model = transform.create_using(m,
                                           complicating_vars=[m.x[1]],
                                           z_estimates=z_estimates,
                                           w_estimates=w_estimates,
                                           rho=7.0)
        nl = PyomoNLP(aug_model)

        x = nlp.create_vector_x()
        self.assertAlmostEqual(nlp.objective(x), nl.objective((x)))
Esempio n. 3
0
    def test_objective(self):

        w_estimates = np.array([5.0, 5.0])
        z_estimates = np.array([2.0, 2.0])
        rho = 2.0
        nlp = AdmmNLP(self.pyomo_nlp,
                      self.coupling_vars,
                      rho=rho,
                      w_estimates=w_estimates,
                      z_estimates=z_estimates)

        hessian_base = self.model.hessian_f
        c = self.model.grad_f
        A = np.array([[1, 0, 0], [0, 0, 1]], dtype=np.double)
        x = nlp.create_vector_x()
        x.fill(1.0)
        f = 0.5 * x.transpose().dot(hessian_base.dot(x)) + c.dot(x)
        difference = A.dot(x) - z_estimates
        f += w_estimates.dot(difference)
        f += 0.5 * rho * np.linalg.norm(difference)**2
        self.assertEqual(f, nlp.objective(x))

        # second nlp
        w_estimates = np.array([1.0, 2.0, 3.0])
        z_estimates = np.array([3.0, 4.0, 5.0])
        nlp = AdmmNLP(self.pyomo_nlp2,
                      self.coupling_vars2,
                      rho=5.0,
                      w_estimates=w_estimates,
                      z_estimates=z_estimates)

        m = self.model2
        transform = AdmmModel()
        aug_model = transform.create_using(
            m,
            complicating_vars=[m.x[1], m.x[3], m.x[5]],
            z_estimates=z_estimates,
            w_estimates=w_estimates,
            rho=5.0)
        nl = PyomoNLP(aug_model)

        x = nlp.create_vector_x()
        self.assertAlmostEqual(nlp.objective(x), nl.objective((x)))

        # third nlp
        w_estimates = np.array([1.0])
        z_estimates = np.array([3.0])
        nlp = AdmmNLP(self.pyomo_nlp3,
                      self.coupling_vars3,
                      rho=7.0,
                      w_estimates=w_estimates,
                      z_estimates=z_estimates)

        m = self.model3
        transform = AdmmModel()
        aug_model = transform.create_using(m,
                                           complicating_vars=[m.x[1]],
                                           z_estimates=z_estimates,
                                           w_estimates=w_estimates,
                                           rho=7.0)
        nl = PyomoNLP(aug_model)

        x = nlp.create_vector_x()
        self.assertAlmostEqual(nlp.objective(x), nl.objective((x)))