Exemplo n.º 1
0
SmartPtr<const SymMatrix> RestoIpoptNLP::uninitialized_h()
{
   SmartPtr<CompoundSymMatrix> retPtr;
   if( hessian_approximation_ == LIMITED_MEMORY )
   {
      retPtr = h_space_->MakeNewCompoundSymMatrix();
   }
   else
   {
      SmartPtr<const SymMatrix> h_con_orig = orig_ip_nlp_->uninitialized_h();
      retPtr = h_space_->MakeNewCompoundSymMatrix();
      SmartPtr<Matrix> h_sum_mat = retPtr->GetCompNonConst(0, 0);
      SmartPtr<SumSymMatrix> h_sum = static_cast<SumSymMatrix*>(GetRawPtr(h_sum_mat));
      h_sum->SetTerm(0, 1.0, *h_con_orig);
      h_sum->SetTerm(1, 1.0, *DR_x_);
   }

   return GetRawPtr(retPtr);
}
Exemplo n.º 2
0
SmartPtr<const SymMatrix> RestoIpoptNLP::h(
   const Vector& x,
   Number        obj_factor,
   const Vector& yc,
   const Vector& yd,
   Number        mu
   )
{
   // Here, we use a SumSymMatrix for the (0,0) block of the
   // Hessian. We need to set this to the hessian of the restoration
   // problem, which is the hessian of the objective from the restoration
   // problem + the constraint only part of the hessian from the original
   // problem
   // All other blocks are zero'ed (NULL)

   // get the x_only part
   const CompoundVector* c_vec = static_cast<const CompoundVector*>(&x);
   DBG_ASSERT(dynamic_cast<const CompoundVector*>(&x));
   SmartPtr<const Vector> x_only = c_vec->GetComp(0);

   // yc and yd should be trivial compound vectors
   const CompoundVector* Cyc = static_cast<const CompoundVector*>(&yc);
   DBG_ASSERT(dynamic_cast<const CompoundVector*>(&yc)); DBG_ASSERT(Cyc->NComps() == 1);
   SmartPtr<const Vector> Cyc0 = Cyc->GetComp(0);
   const CompoundVector* Cyd = static_cast<const CompoundVector*>(&yd);
   DBG_ASSERT(dynamic_cast<const CompoundVector*>(&yd)); DBG_ASSERT(Cyd->NComps() == 1);
   SmartPtr<const Vector> Cyd0 = Cyd->GetComp(0);

   // calculate the original hessian
   SmartPtr<const SymMatrix> h_con_orig = orig_ip_nlp_->h(*x_only, 0.0, *Cyc0, *Cyd0);

   // Create the new compound matrix
   // The SumSymMatrix is auto_allocated
   SmartPtr<CompoundSymMatrix> retPtr = h_space_->MakeNewCompoundSymMatrix();

   // Set the entries in the SumSymMatrix
   SmartPtr<Matrix> h_sum_mat = retPtr->GetCompNonConst(0, 0);
   SmartPtr<SumSymMatrix> h_sum = static_cast<SumSymMatrix*>(GetRawPtr(h_sum_mat));
   h_sum->SetTerm(0, 1.0, *h_con_orig);
   h_sum->SetTerm(1, obj_factor * Eta(mu), *DR_x_);

   return GetRawPtr(retPtr);
}
Exemplo n.º 3
0
SmartPtr<const Vector> RestoIpoptNLP::d(
   const Vector& x
   )
{
   const CompoundVector* c_vec = static_cast<const CompoundVector*>(&x);
   SmartPtr<const Vector> x_only = c_vec->GetComp(0);
   SmartPtr<const Vector> nd_only = c_vec->GetComp(3);
   SmartPtr<const Vector> pd_only = c_vec->GetComp(4);

   SmartPtr<const Vector> orig_d = orig_ip_nlp_->d(*x_only);
   SmartPtr<Vector> retPtr = d_space_->MakeNew();
   SmartPtr<CompoundVector> CretPtr = static_cast<CompoundVector*>(GetRawPtr(retPtr));
   DBG_ASSERT(dynamic_cast<CompoundVector*> (GetRawPtr(retPtr)));
   SmartPtr<Vector> CretPtr0 = CretPtr->GetCompNonConst(0);
   CretPtr0->Copy(*orig_d);
   CretPtr0->Axpy(1., *nd_only);
   CretPtr0->Axpy(-1., *pd_only);

   return GetRawPtr(retPtr);
}
Exemplo n.º 4
0
SmartPtr<const Vector> RestoIpoptNLP::c(
   const Vector& x
   )
{
   const CompoundVector* c_vec = static_cast<const CompoundVector*>(&x);
   SmartPtr<const Vector> x_only = c_vec->GetComp(0);
   SmartPtr<const Vector> nc_only = c_vec->GetComp(1);
   SmartPtr<const Vector> pc_only = c_vec->GetComp(2);

   SmartPtr<const Vector> orig_c = orig_ip_nlp_->c(*x_only);
   SmartPtr<Vector> retPtr = c_space_->MakeNew();
   SmartPtr<CompoundVector> CretPtr = static_cast<CompoundVector*>(GetRawPtr(retPtr));
   DBG_ASSERT(dynamic_cast<CompoundVector*> (GetRawPtr(retPtr)));
   SmartPtr<Vector> CretPtr0 = CretPtr->GetCompNonConst(0);
   CretPtr0->Copy(*orig_c);
   CretPtr0->Axpy(1.0, *nc_only);
   CretPtr0->Axpy(-1.0, *pc_only);

   return GetRawPtr(retPtr);
}
Exemplo n.º 5
0
SmartPtr<const Matrix> RestoIpoptNLP::jac_d(
   const Vector& x
   )
{
   DBG_START_METH("RestoIpoptNLP::jac_d", dbg_verbosity);

   // Here, we set the (0,0) block with the values from the
   // original jac_d and set the factor for the -I (jac w.r.t. p_d)

   // get out the x_only part
   const CompoundVector* c_vec = static_cast<const CompoundVector*>(&x);
   DBG_ASSERT(c_vec);
   SmartPtr<const Vector> x_only = c_vec->GetComp(0);

   // calculate the jacobian for the original problem
   SmartPtr<const Matrix> jac_d_only = orig_ip_nlp_->jac_d(*x_only);

   // Create the new compound matrix
   // The zero parts remain NULL, the identities are created from the matrix
   // space (since auto_allocate was set to true in SetCompSpace)
   SmartPtr<CompoundMatrix> retPtr = jac_d_space_->MakeNewCompoundMatrix();
   DBG_PRINT((1, "jac_d_space_ = %x\n", GetRawPtr(jac_d_space_)))

   // Set the block for the original Jacobian
   retPtr->SetComp(0, 0, *jac_d_only);

   // (0,1) and (0,2) blocks are zero (NULL)

   // set the factor for the identity matrix for the pd variables
   // (likr in jac_c)
   SmartPtr<Matrix> jac_d_pd_mat = retPtr->GetCompNonConst(0, 4);
   IdentityMatrix* jac_d_pd = static_cast<IdentityMatrix*>(GetRawPtr(jac_d_pd_mat));
   DBG_ASSERT(jac_d_pd);
   jac_d_pd->SetFactor(-1.0);

   return GetRawPtr(retPtr);
}
Exemplo n.º 6
0
SmartPtr<const Matrix> RestoIpoptNLP::jac_c(
   const Vector& x
   )
{

   // Here, we set the (0,0) block with the values from the
   // original jac_c and set the factor for the -I (jac w.r.t. p_c)

   // get out the x_only part
   const CompoundVector* c_vec = static_cast<const CompoundVector*>(&x);
   DBG_ASSERT(c_vec);
   SmartPtr<const Vector> x_only = c_vec->GetComp(0);

   // calculate the jacobian for the original problem
   SmartPtr<const Matrix> jac_c_only = orig_ip_nlp_->jac_c(*x_only);

   // Create the new compound matrix
   // The zero parts remain NULL, the identities are created from the matrix
   // space (since auto_allocate was set to true in SetCompSpace)
   SmartPtr<CompoundMatrix> retPtr = jac_c_space_->MakeNewCompoundMatrix();

   // set the (0,0) block to the original jacobian
   retPtr->SetComp(0, 0, *jac_c_only);

   // we currently do not have a default factor in the matrix spaces
   // so we need to set the factor on the identity (jacobian of the
   // restoration c w.r.t. p_c is -I)
   // This could easily be changed to include special processing
   // for identities in the CompoundMatrixSpace (and a factor)
   SmartPtr<Matrix> jac_c_pc_mat = retPtr->GetCompNonConst(0, 2);
   IdentityMatrix* jac_c_pc = static_cast<IdentityMatrix*>(GetRawPtr(jac_c_pc_mat));
   DBG_ASSERT(jac_c_pc);
   jac_c_pc->SetFactor(-1.0);

   return GetRawPtr(retPtr);
}