Пример #1
0
    def test_grad_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)

        df = hessian_base.dot(x) + c
        df += A.transpose().dot(w_estimates)
        df += rho * (A.transpose().dot(A).dot(x) -
                     A.transpose().dot(z_estimates))

        self.assertTrue(np.allclose(df, nlp.grad_objective(x)))
Пример #2
0
    def test_grad_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)

        df = hessian_base.dot(x) + c
        df += A.transpose().dot(w_estimates)
        df += rho * (A.transpose().dot(A).dot(x) - A.transpose().dot(z_estimates))

        self.assertTrue(np.allclose(df, nlp.grad_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=3.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=3.0)
        nl = PyomoNLP(aug_model)

        x = nlp.create_vector_x()
        self.assertTrue(np.allclose(nlp.grad_objective(x), nl.grad_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=8.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=8.0)
        nl = PyomoNLP(aug_model)

        x = nlp.create_vector_x()
        x.fill(1.0)
        self.assertTrue(np.allclose(nlp.grad_objective(x), nl.grad_objective(x)))
Пример #3
0
    def test_grad_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)

        df = hessian_base.dot(x) + c
        df += A.transpose().dot(w_estimates)
        df += rho * (A.transpose().dot(A).dot(x) -
                     A.transpose().dot(z_estimates))

        self.assertTrue(np.allclose(df, nlp.grad_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=3.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=3.0)
        nl = PyomoNLP(aug_model)

        x = nlp.create_vector_x()
        self.assertTrue(
            np.allclose(nlp.grad_objective(x), nl.grad_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=8.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=8.0)
        nl = PyomoNLP(aug_model)

        x = nlp.create_vector_x()
        x.fill(1.0)
        self.assertTrue(
            np.allclose(nlp.grad_objective(x), nl.grad_objective(x)))