bool RestoRestorationPhase::PerformRestoration() { DBG_START_METH("RestoRestorationPhase::PerformRestoration", dbg_verbosity); Jnlst().Printf(J_DETAILED, J_MAIN, "Performing second level restoration phase for current constriant violation %8.2e\n", IpCq().curr_constraint_violation()); DBG_ASSERT(IpCq().curr_constraint_violation()>0.); // Get a grip on the restoration phase NLP and obtain the pointers // to the original NLP data SmartPtr<RestoIpoptNLP> resto_ip_nlp = static_cast<RestoIpoptNLP*> (&IpNLP()); DBG_ASSERT(dynamic_cast<RestoIpoptNLP*> (&IpNLP())); SmartPtr<IpoptNLP> orig_ip_nlp = static_cast<IpoptNLP*> (&resto_ip_nlp->OrigIpNLP()); DBG_ASSERT(dynamic_cast<IpoptNLP*> (&resto_ip_nlp->OrigIpNLP())); // Get the current point and create a new vector for the result SmartPtr<const CompoundVector> Ccurr_x = static_cast<const CompoundVector*> (GetRawPtr(IpData().curr()->x())); SmartPtr<Vector> new_x = IpData().curr()->x()->MakeNew(); SmartPtr<CompoundVector> Cnew_x = static_cast<CompoundVector*> (GetRawPtr(new_x)); // The x values remain unchanged SmartPtr<Vector> x = Cnew_x->GetCompNonConst(0); x->Copy(*Ccurr_x->GetComp(0)); // ToDo in free mu mode - what to do here? Number mu = IpData().curr_mu(); // Compute the initial values for the n and p variables for the // equality constraints Number rho = resto_ip_nlp->Rho(); SmartPtr<Vector> nc = Cnew_x->GetCompNonConst(1); SmartPtr<Vector> pc = Cnew_x->GetCompNonConst(2); SmartPtr<const Vector> cvec = orig_ip_nlp->c(*Ccurr_x->GetComp(0)); SmartPtr<Vector> a = nc->MakeNew(); SmartPtr<Vector> b = nc->MakeNew(); a->Set(mu/(2.*rho)); a->Axpy(-0.5, *cvec); b->Copy(*cvec); b->Scal(mu/(2.*rho)); solve_quadratic(*a, *b, *nc); pc->Copy(*cvec); pc->Axpy(1., *nc); DBG_PRINT_VECTOR(2, "nc", *nc); DBG_PRINT_VECTOR(2, "pc", *pc); // initial values for the n and p variables for the inequality // constraints SmartPtr<Vector> nd = Cnew_x->GetCompNonConst(3); SmartPtr<Vector> pd = Cnew_x->GetCompNonConst(4); SmartPtr<Vector> dvec = pd->MakeNew(); dvec->Copy(*orig_ip_nlp->d(*Ccurr_x->GetComp(0))); dvec->Axpy(-1., *IpData().curr()->s()); a = nd->MakeNew(); b = nd->MakeNew(); a->Set(mu/(2.*rho)); a->Axpy(-0.5, *dvec); b->Copy(*dvec); b->Scal(mu/(2.*rho)); solve_quadratic(*a, *b, *nd); pd->Copy(*dvec); pd->Axpy(1., *nd); DBG_PRINT_VECTOR(2, "nd", *nd); DBG_PRINT_VECTOR(2, "pd", *pd); // Now set the trial point to the solution of the restoration phase // s and all multipliers remain unchanged SmartPtr<IteratesVector> new_trial = IpData().curr()->MakeNewContainer(); new_trial->Set_x(*new_x); IpData().set_trial(new_trial); IpData().Append_info_string("R"); return true; }
bool RestoIterateInitializer::SetInitialIterates() { DBG_START_METH("RestoIterateInitializer::SetInitialIterates", dbg_verbosity); // Get a grip on the restoration phase NLP and obtain the pointers // to the original NLP data SmartPtr<RestoIpoptNLP> resto_ip_nlp = static_cast<RestoIpoptNLP*> (&IpNLP()); SmartPtr<IpoptNLP> orig_ip_nlp = static_cast<IpoptNLP*> (&resto_ip_nlp->OrigIpNLP()); SmartPtr<IpoptData> orig_ip_data = static_cast<IpoptData*> (&resto_ip_nlp->OrigIpData()); SmartPtr<IpoptCalculatedQuantities> orig_ip_cq = static_cast<IpoptCalculatedQuantities*> (&resto_ip_nlp->OrigIpCq()); // Set the value of the barrier parameter Number resto_mu; resto_mu = Max(orig_ip_data->curr_mu(), orig_ip_cq->curr_c()->Amax(), orig_ip_cq->curr_d_minus_s()->Amax()); IpData().Set_mu(resto_mu); Jnlst().Printf(J_DETAILED, J_INITIALIZATION, "Initial barrier parameter resto_mu = %e\n", resto_mu); ///////////////////////////////////////////////////////////////////// // Initialize primal varialbes // ///////////////////////////////////////////////////////////////////// // initialize the data structures in the restoration phase NLP IpData().InitializeDataStructures(IpNLP(), false, false, false, false, false); SmartPtr<Vector> new_x = IpData().curr()->x()->MakeNew(); SmartPtr<CompoundVector> Cnew_x = static_cast<CompoundVector*> (GetRawPtr(new_x)); // Set the trial x variables from the original NLP Cnew_x->GetCompNonConst(0)->Copy(*orig_ip_data->curr()->x()); // Compute the initial values for the n and p variables for the // equality constraints Number rho = resto_ip_nlp->Rho(); DBG_PRINT((1,"rho = %e\n", rho)); SmartPtr<Vector> nc = Cnew_x->GetCompNonConst(1); SmartPtr<Vector> pc = Cnew_x->GetCompNonConst(2); SmartPtr<const Vector> cvec = orig_ip_cq->curr_c(); DBG_PRINT_VECTOR(2, "cvec", *cvec); SmartPtr<Vector> a = nc->MakeNew(); SmartPtr<Vector> b = nc->MakeNew(); a->Set(resto_mu/(2.*rho)); a->Axpy(-0.5, *cvec); b->Copy(*cvec); b->Scal(resto_mu/(2.*rho)); DBG_PRINT_VECTOR(2, "a", *a); DBG_PRINT_VECTOR(2, "b", *b); solve_quadratic(*a, *b, *nc); pc->Copy(*cvec); pc->Axpy(1., *nc); DBG_PRINT_VECTOR(2, "nc", *nc); DBG_PRINT_VECTOR(2, "pc", *pc); // initial values for the n and p variables for the inequality // constraints SmartPtr<Vector> nd = Cnew_x->GetCompNonConst(3); SmartPtr<Vector> pd = Cnew_x->GetCompNonConst(4); cvec = orig_ip_cq->curr_d_minus_s(); a = nd->MakeNew(); b = nd->MakeNew(); a->Set(resto_mu/(2.*rho)); a->Axpy(-0.5, *cvec); b->Copy(*cvec); b->Scal(resto_mu/(2.*rho)); solve_quadratic(*a, *b, *nd); pd->Copy(*cvec); pd->Axpy(1., *nd); DBG_PRINT_VECTOR(2, "nd", *nd); DBG_PRINT_VECTOR(2, "pd", *pd); // Leave the slacks unchanged SmartPtr<const Vector> new_s = orig_ip_data->curr()->s(); // Now set the primal trial variables DBG_PRINT_VECTOR(2,"new_s",*new_s); DBG_PRINT_VECTOR(2,"new_x",*new_x); SmartPtr<IteratesVector> trial = IpData().curr()->MakeNewContainer(); trial->Set_primal(*new_x, *new_s); IpData().set_trial(trial); DBG_PRINT_VECTOR(2, "resto_c", *IpCq().trial_c()); DBG_PRINT_VECTOR(2, "resto_d_minus_s", *IpCq().trial_d_minus_s()); ///////////////////////////////////////////////////////////////////// // Initialize bound multipliers // ///////////////////////////////////////////////////////////////////// SmartPtr<Vector> new_z_L = IpData().curr()->z_L()->MakeNew(); SmartPtr<CompoundVector> Cnew_z_L = static_cast<CompoundVector*> (GetRawPtr(new_z_L)); DBG_ASSERT(IsValid(Cnew_z_L)); SmartPtr<Vector> new_z_U = IpData().curr()->z_U()->MakeNew(); SmartPtr<Vector> new_v_L = IpData().curr()->v_L()->MakeNew(); SmartPtr<Vector> new_v_U = IpData().curr()->v_U()->MakeNew(); // multipliers for the original bounds are SmartPtr<const Vector> orig_z_L = orig_ip_data->curr()->z_L(); SmartPtr<const Vector> orig_z_U = orig_ip_data->curr()->z_U(); SmartPtr<const Vector> orig_v_L = orig_ip_data->curr()->v_L(); SmartPtr<const Vector> orig_v_U = orig_ip_data->curr()->v_U(); // Set the new multipliers to the min of the penalty parameter Rho // and their current value SmartPtr<Vector> Cnew_z_L0 = Cnew_z_L->GetCompNonConst(0); Cnew_z_L0->Set(rho); Cnew_z_L0->ElementWiseMin(*orig_z_L); new_z_U->Set(rho); new_z_U->ElementWiseMin(*orig_z_U); new_v_L->Set(rho); new_v_L->ElementWiseMin(*orig_v_L); new_v_U->Set(rho); new_v_U->ElementWiseMin(*orig_v_U); // Set the multipliers for the p and n bounds to the "primal" multipliers SmartPtr<Vector> Cnew_z_L1 = Cnew_z_L->GetCompNonConst(1); Cnew_z_L1->Set(resto_mu); Cnew_z_L1->ElementWiseDivide(*nc); SmartPtr<Vector> Cnew_z_L2 = Cnew_z_L->GetCompNonConst(2); Cnew_z_L2->Set(resto_mu); Cnew_z_L2->ElementWiseDivide(*pc); SmartPtr<Vector> Cnew_z_L3 = Cnew_z_L->GetCompNonConst(3); Cnew_z_L3->Set(resto_mu); Cnew_z_L3->ElementWiseDivide(*nd); SmartPtr<Vector> Cnew_z_L4 = Cnew_z_L->GetCompNonConst(4); Cnew_z_L4->Set(resto_mu); Cnew_z_L4->ElementWiseDivide(*pd); // Set those initial values to be the trial values in Data trial = IpData().trial()->MakeNewContainer(); trial->Set_bound_mult(*new_z_L, *new_z_U, *new_v_L, *new_v_U); IpData().set_trial(trial); ///////////////////////////////////////////////////////////////////// // Initialize equality constraint multipliers // ///////////////////////////////////////////////////////////////////// DefaultIterateInitializer::least_square_mults( Jnlst(), IpNLP(), IpData(), IpCq(), resto_eq_mult_calculator_, constr_mult_init_max_); // upgrade the trial to the current point IpData().AcceptTrialPoint(); DBG_PRINT_VECTOR(2, "y_c", *IpData().curr()->y_c()); DBG_PRINT_VECTOR(2, "y_d", *IpData().curr()->y_d()); DBG_PRINT_VECTOR(2, "z_L", *IpData().curr()->z_L()); DBG_PRINT_VECTOR(2, "z_U", *IpData().curr()->z_U()); DBG_PRINT_VECTOR(2, "v_L", *IpData().curr()->v_L()); DBG_PRINT_VECTOR(2, "v_U", *IpData().curr()->v_U()); return true; }
void GradientScaling::DetermineScalingParametersImpl( const SmartPtr<const VectorSpace> x_space, const SmartPtr<const VectorSpace> p_space, const SmartPtr<const VectorSpace> c_space, const SmartPtr<const VectorSpace> d_space, const SmartPtr<const MatrixSpace> jac_c_space, const SmartPtr<const MatrixSpace> jac_d_space, const SmartPtr<const SymMatrixSpace> h_space, const Matrix& Px_L, const Vector& x_L, const Matrix& Px_U, const Vector& x_U, Number& df, SmartPtr<Vector>& dx, SmartPtr<Vector>& dc, SmartPtr<Vector>& dd) { DBG_ASSERT(IsValid(nlp_)); SmartPtr<Vector> x = x_space->MakeNew(); SmartPtr<Vector> p = p_space->MakeNew(); if (!nlp_->GetStartingPoint(GetRawPtr(x), true, GetRawPtr(p), true, NULL, false, NULL, false, NULL, false, NULL, false)) { THROW_EXCEPTION(FAILED_INITIALIZATION, "Error getting initial point from NLP in GradientScaling.\n"); } // // Calculate grad_f scaling // SmartPtr<Vector> grad_f = x_space->MakeNew(); if (nlp_->Eval_grad_f(*x, *p, *grad_f)) { double max_grad_f = grad_f->Amax(); df = 1.; if (scaling_obj_target_gradient_ == 0.) { if (max_grad_f > scaling_max_gradient_) { df = scaling_max_gradient_ / max_grad_f; } } else { if (max_grad_f == 0.) { Jnlst().Printf(J_WARNING, J_INITIALIZATION, "Gradient of objective function is zero at starting point. Cannot determine scaling factor based on scaling_obj_target_gradient option.\n"); } else { df = scaling_obj_target_gradient_ / max_grad_f; } } df = Max(df, scaling_min_value_); Jnlst().Printf(J_DETAILED, J_INITIALIZATION, "Scaling parameter for objective function = %e\n", df); } else { Jnlst().Printf(J_WARNING, J_INITIALIZATION, "Error evaluating objective gradient at user provided starting point.\n No scaling factor for objective function computed!\n"); df = 1.; } // // No x scaling // dx = NULL; dc = NULL; if (c_space->Dim()>0) { // // Calculate c scaling // SmartPtr<Matrix> jac_c = jac_c_space->MakeNew(); if (nlp_->Eval_jac_c(*x, *p, *jac_c)) { dc = c_space->MakeNew(); const double dbl_min = std::numeric_limits<double>::min(); dc->Set(dbl_min); jac_c->ComputeRowAMax(*dc, false); Number arow_max = dc->Amax(); if (scaling_constr_target_gradient_<=0.) { if (arow_max > scaling_max_gradient_) { dc->ElementWiseReciprocal(); dc->Scal(scaling_max_gradient_); SmartPtr<Vector> dummy = dc->MakeNew(); dummy->Set(1.); dc->ElementWiseMin(*dummy); } else { dc = NULL; } } else { dc->Set(scaling_constr_target_gradient_/arow_max); } if (IsValid(dc) && scaling_min_value_ > 0.) { SmartPtr<Vector> tmp = dc->MakeNew(); tmp->Set(scaling_min_value_); dc->ElementWiseMax(*tmp); } } else { Jnlst().Printf(J_WARNING, J_INITIALIZATION, "Error evaluating Jacobian of equality constraints at user provided starting point.\n No scaling factors for equality constraints computed!\n"); } } dd = NULL; if (d_space->Dim()>0) { // // Calculate d scaling // SmartPtr<Matrix> jac_d = jac_d_space->MakeNew(); if (nlp_->Eval_jac_d(*x, *p, *jac_d)) { dd = d_space->MakeNew(); const double dbl_min = std::numeric_limits<double>::min(); dd->Set(dbl_min); jac_d->ComputeRowAMax(*dd, false); Number arow_max = dd->Amax(); if (scaling_constr_target_gradient_<=0.) { if (arow_max > scaling_max_gradient_) { dd->ElementWiseReciprocal(); dd->Scal(scaling_max_gradient_); SmartPtr<Vector> dummy = dd->MakeNew(); dummy->Set(1.); dd->ElementWiseMin(*dummy); } else { dd = NULL; } } else { dd->Set(scaling_constr_target_gradient_/arow_max); } if (IsValid(dd) && scaling_min_value_ > 0.) { SmartPtr<Vector> tmp = dd->MakeNew(); tmp->Set(scaling_min_value_); dd->ElementWiseMax(*tmp); } } else { Jnlst().Printf(J_WARNING, J_INITIALIZATION, "Error evaluating Jacobian of inequality constraints at user provided starting point.\n No scaling factors for inequality constraints computed!\n"); } } }
void SensAlgorithm::UnScaleIteratesVector(SmartPtr<IteratesVector> *V) { // unscale the iterates vector // pretty much a copy from IpOrigIpopt::finalize_solution SmartPtr<const Vector> unscaled_x; unscaled_x = IpNLP().NLP_scaling()->unapply_vector_scaling_x((*V)->x()); DBG_ASSERT(IsValid(unscaled_x)); (*V)->Set_x(*unscaled_x); unscaled_x = NULL ; SmartPtr<const Matrix> Px_L = IpNLP().Px_L(); SmartPtr<const Matrix> Px_U = IpNLP().Px_U(); SmartPtr<const VectorSpace> x_space = IpNLP().x_space(); SmartPtr<const Vector> y_c = (*V)->y_c(); SmartPtr<const Vector> y_d = (*V)->y_d(); SmartPtr<const Vector> z_L = (*V)->z_L(); SmartPtr<const Vector> z_U = (*V)->z_U(); // unscale y_c SmartPtr<const Vector> unscaled_yc; SmartPtr<const Vector> unscaled_yd; SmartPtr<const Vector> unscaled_z_L; SmartPtr<const Vector> unscaled_z_U; Number obj_unscale_factor = IpNLP().NLP_scaling()->unapply_obj_scaling(1.); if (obj_unscale_factor!=1.) { SmartPtr<Vector> tmp = IpNLP().NLP_scaling()->apply_vector_scaling_x_LU_NonConst(*Px_L, z_L, *x_space); tmp->Scal(obj_unscale_factor); unscaled_z_L = ConstPtr(tmp); tmp = IpNLP().NLP_scaling()->apply_vector_scaling_x_LU_NonConst(*Px_U, z_U, *x_space); tmp->Scal(obj_unscale_factor); unscaled_z_U = ConstPtr(tmp); tmp = IpNLP().NLP_scaling()->apply_vector_scaling_c_NonConst(y_c); tmp->Scal(obj_unscale_factor); unscaled_yc = ConstPtr(tmp); tmp = IpNLP().NLP_scaling()->apply_vector_scaling_d_NonConst(y_d); tmp->Scal(obj_unscale_factor); unscaled_yd = ConstPtr(tmp); } else { unscaled_z_L = IpNLP().NLP_scaling()->apply_vector_scaling_x_LU(*Px_L, z_L, *x_space); unscaled_z_U = IpNLP().NLP_scaling()->apply_vector_scaling_x_LU(*Px_U, z_U, *x_space); unscaled_yc = IpNLP().NLP_scaling()->apply_vector_scaling_c(y_c); unscaled_yd = IpNLP().NLP_scaling()->apply_vector_scaling_d(y_d); } (*V)->Set_z_U(*unscaled_z_U); (*V)->Set_z_L(*unscaled_z_L); (*V)->Set_y_c(*unscaled_yc); (*V)->Set_y_d(*unscaled_yd); }
bool RestoIpoptNLP::InitializeStructures( SmartPtr<Vector>& x, bool init_x, SmartPtr<Vector>& y_c, bool init_y_c, SmartPtr<Vector>& y_d, bool init_y_d, SmartPtr<Vector>& z_L, bool init_z_L, SmartPtr<Vector>& z_U, bool init_z_U, SmartPtr<Vector>& v_L, SmartPtr<Vector>& v_U) { DBG_START_METH("RestoIpoptNLP::InitializeStructures", 0); DBG_ASSERT(initialized_); /////////////////////////////////////////////////////////// // Get the vector/matrix spaces for the original problem // /////////////////////////////////////////////////////////// SmartPtr<const VectorSpace> orig_x_space; SmartPtr<const VectorSpace> orig_c_space; SmartPtr<const VectorSpace> orig_d_space; SmartPtr<const VectorSpace> orig_x_l_space; SmartPtr<const MatrixSpace> orig_px_l_space; SmartPtr<const VectorSpace> orig_x_u_space; SmartPtr<const MatrixSpace> orig_px_u_space; SmartPtr<const VectorSpace> orig_d_l_space; SmartPtr<const MatrixSpace> orig_pd_l_space; SmartPtr<const VectorSpace> orig_d_u_space; SmartPtr<const MatrixSpace> orig_pd_u_space; SmartPtr<const MatrixSpace> orig_jac_c_space; SmartPtr<const MatrixSpace> orig_jac_d_space; SmartPtr<const SymMatrixSpace> orig_h_space; orig_ip_nlp_->GetSpaces(orig_x_space, orig_c_space, orig_d_space, orig_x_l_space, orig_px_l_space, orig_x_u_space, orig_px_u_space, orig_d_l_space, orig_pd_l_space, orig_d_u_space, orig_pd_u_space, orig_jac_c_space, orig_jac_d_space, orig_h_space); // Create the restoration phase problem vector/matrix spaces, based // on the original spaces (pretty inconvenient with all the // matrix spaces, isn't it?!?) DBG_PRINT((1, "Creating the x_space_\n")); // vector x Index total_dim = orig_x_space->Dim() + 2 * orig_c_space->Dim() + 2 * orig_d_space->Dim(); x_space_ = new CompoundVectorSpace(5, total_dim); x_space_->SetCompSpace(0, *orig_x_space); x_space_->SetCompSpace(1, *orig_c_space); // n_c x_space_->SetCompSpace(2, *orig_c_space); // p_c x_space_->SetCompSpace(3, *orig_d_space); // n_d x_space_->SetCompSpace(4, *orig_d_space); // p_d DBG_PRINT((1, "Setting the c_space_\n")); // vector c //c_space_ = orig_c_space; c_space_ = new CompoundVectorSpace(1, orig_c_space->Dim()); c_space_->SetCompSpace(0, *orig_c_space); DBG_PRINT((1, "Setting the d_space_\n")); // vector d //d_space_ = orig_d_space; d_space_ = new CompoundVectorSpace(1, orig_d_space->Dim()); d_space_->SetCompSpace(0, *orig_d_space); DBG_PRINT((1, "Creating the x_l_space_\n")); // vector x_L total_dim = orig_x_l_space->Dim() + 2 * orig_c_space->Dim() + 2 * orig_d_space->Dim(); x_l_space_ = new CompoundVectorSpace(5, total_dim); x_l_space_->SetCompSpace(0, *orig_x_l_space); x_l_space_->SetCompSpace(1, *orig_c_space); // n_c >=0 x_l_space_->SetCompSpace(2, *orig_c_space); // p_c >=0 x_l_space_->SetCompSpace(3, *orig_d_space); // n_d >=0 x_l_space_->SetCompSpace(4, *orig_d_space); // p_d >=0 DBG_PRINT((1, "Setting the x_u_space_\n")); // vector x_U x_u_space_ = new CompoundVectorSpace(1, orig_x_u_space->Dim()); x_u_space_->SetCompSpace(0, *orig_x_u_space); DBG_PRINT((1, "Creating the px_l_space_\n")); // matrix px_l Index total_rows = orig_x_space->Dim() + 2 * orig_c_space->Dim() + 2 * orig_d_space->Dim(); Index total_cols = orig_x_l_space->Dim() + 2 * orig_c_space->Dim() + 2 * orig_d_space->Dim(); px_l_space_ = new CompoundMatrixSpace(5, 5, total_rows, total_cols); px_l_space_->SetBlockRows(0, orig_x_space->Dim()); px_l_space_->SetBlockRows(1, orig_c_space->Dim()); px_l_space_->SetBlockRows(2, orig_c_space->Dim()); px_l_space_->SetBlockRows(3, orig_d_space->Dim()); px_l_space_->SetBlockRows(4, orig_d_space->Dim()); px_l_space_->SetBlockCols(0, orig_x_l_space->Dim()); px_l_space_->SetBlockCols(1, orig_c_space->Dim()); px_l_space_->SetBlockCols(2, orig_c_space->Dim()); px_l_space_->SetBlockCols(3, orig_d_space->Dim()); px_l_space_->SetBlockCols(4, orig_d_space->Dim()); px_l_space_->SetCompSpace(0, 0, *orig_px_l_space); // now setup the identity matrix // This could be changed to be something like... // px_l_space_->SetBlockToIdentity(1,1,1.0); // px_l_space_->SetBlockToIdentity(2,2,other_factor); // ... etc with some simple changes to the CompoundMatrixSpace // to allow this (space should auto create the matrices) // // for now, we use the new feature and set the true flag for this block // to say that the matrices should be auto_allocated SmartPtr<const MatrixSpace> identity_mat_space_nc = new IdentityMatrixSpace(orig_c_space->Dim()); px_l_space_->SetCompSpace(1, 1, *identity_mat_space_nc, true); px_l_space_->SetCompSpace(2, 2, *identity_mat_space_nc, true); SmartPtr<const MatrixSpace> identity_mat_space_nd = new IdentityMatrixSpace(orig_d_space->Dim()); px_l_space_->SetCompSpace(3, 3, *identity_mat_space_nd, true); px_l_space_->SetCompSpace(4, 4, *identity_mat_space_nd, true); DBG_PRINT((1, "Creating the px_u_space_\n")); // matrix px_u total_rows = orig_x_space->Dim() + 2 * orig_c_space->Dim() + 2 * orig_d_space->Dim(); total_cols = orig_x_u_space->Dim(); DBG_PRINT((1, "total_rows = %d, total_cols = %d\n", total_rows, total_cols)); px_u_space_ = new CompoundMatrixSpace(5, 1, total_rows, total_cols); px_u_space_->SetBlockRows(0, orig_x_space->Dim()); px_u_space_->SetBlockRows(1, orig_c_space->Dim()); px_u_space_->SetBlockRows(2, orig_c_space->Dim()); px_u_space_->SetBlockRows(3, orig_d_space->Dim()); px_u_space_->SetBlockRows(4, orig_d_space->Dim()); px_u_space_->SetBlockCols(0, orig_x_u_space->Dim()); px_u_space_->SetCompSpace(0, 0, *orig_px_u_space); // other matrices are zero'ed out // vector d_L //d_l_space_ = orig_d_l_space; d_l_space_ = new CompoundVectorSpace(1, orig_d_l_space->Dim()); d_l_space_->SetCompSpace(0, *orig_d_l_space); // vector d_U //d_u_space_ = orig_d_u_space; d_u_space_ = new CompoundVectorSpace(1, orig_d_u_space->Dim()); d_u_space_->SetCompSpace(0, *orig_d_u_space); // matrix pd_L //pd_l_space_ = orig_pd_l_space; pd_l_space_ = new CompoundMatrixSpace(1, 1, orig_pd_l_space->NRows(), orig_pd_l_space->NCols()); pd_l_space_->SetBlockRows(0, orig_pd_l_space->NRows()); pd_l_space_->SetBlockCols(0, orig_pd_l_space->NCols()); pd_l_space_->SetCompSpace(0, 0, *orig_pd_l_space); // matrix pd_U //pd_u_space_ = orig_pd_u_space; pd_u_space_ = new CompoundMatrixSpace(1, 1, orig_pd_u_space->NRows(), orig_pd_u_space->NCols()); pd_u_space_->SetBlockRows(0, orig_pd_u_space->NRows()); pd_u_space_->SetBlockCols(0, orig_pd_u_space->NCols()); pd_u_space_->SetCompSpace(0, 0, *orig_pd_u_space); DBG_PRINT((1, "Creating the jac_c_space_\n")); // matrix jac_c total_rows = orig_c_space->Dim(); total_cols = orig_x_space->Dim() + 2 * orig_c_space->Dim() + 2 * orig_d_space->Dim(); jac_c_space_ = new CompoundMatrixSpace(1, 5, total_rows, total_cols); jac_c_space_->SetBlockRows(0, orig_c_space->Dim()); jac_c_space_->SetBlockCols(0, orig_x_space->Dim()); jac_c_space_->SetBlockCols(1, orig_c_space->Dim()); jac_c_space_->SetBlockCols(2, orig_c_space->Dim()); jac_c_space_->SetBlockCols(3, orig_d_space->Dim()); jac_c_space_->SetBlockCols(4, orig_d_space->Dim()); jac_c_space_->SetCompSpace(0, 0, *orig_jac_c_space); // **NOTE: By placing "flat" identity matrices here, we are creating // potential issues for linalg operations that arise when the original // NLP has a "compound" c_space. To avoid problems like this, // we place all unmodified component spaces in trivial (size 1) // "compound" spaces. jac_c_space_->SetCompSpace(0, 1, *identity_mat_space_nc, true); jac_c_space_->SetCompSpace(0, 2, *identity_mat_space_nc, true); // remaining blocks are zero'ed DBG_PRINT((1, "Creating the jac_d_space_\n")); // matrix jac_d total_rows = orig_d_space->Dim(); total_cols = orig_x_space->Dim() + 2 * orig_c_space->Dim() + 2 * orig_d_space->Dim(); jac_d_space_ = new CompoundMatrixSpace(1, 5, total_rows, total_cols); jac_d_space_->SetBlockRows(0, orig_d_space->Dim()); jac_d_space_->SetBlockCols(0, orig_x_space->Dim()); jac_d_space_->SetBlockCols(1, orig_c_space->Dim()); jac_d_space_->SetBlockCols(2, orig_c_space->Dim()); jac_d_space_->SetBlockCols(3, orig_d_space->Dim()); jac_d_space_->SetBlockCols(4, orig_d_space->Dim()); jac_d_space_->SetCompSpace(0, 0, *orig_jac_d_space); DBG_PRINT((1, "orig_jac_d_space = %x\n", GetRawPtr(orig_jac_d_space))) // Blocks (0,1) and (0,2) are zero'ed out // **NOTE: By placing "flat" identity matrices here, we are creating // potential issues for linalg operations that arise when the original // NLP has a "compound" d_space. To avoid problems like this, // we place all unmodified component spaces in trivial (size 1) // "compound" spaces. jac_d_space_->SetCompSpace(0, 3, *identity_mat_space_nd, true); jac_d_space_->SetCompSpace(0, 4, *identity_mat_space_nd, true); DBG_PRINT((1, "Creating the h_space_\n")); // matrix h total_dim = orig_x_space->Dim() + 2 * orig_c_space->Dim() + 2 * orig_d_space->Dim(); h_space_ = new CompoundSymMatrixSpace(5, total_dim); h_space_->SetBlockDim(0, orig_x_space->Dim()); h_space_->SetBlockDim(1, orig_c_space->Dim()); h_space_->SetBlockDim(2, orig_c_space->Dim()); h_space_->SetBlockDim(3, orig_d_space->Dim()); h_space_->SetBlockDim(4, orig_d_space->Dim()); SmartPtr<DiagMatrixSpace> DR_x_space = new DiagMatrixSpace(orig_x_space->Dim()); if( hessian_approximation_ == LIMITED_MEMORY ) { const LowRankUpdateSymMatrixSpace* LR_h_space = static_cast<const LowRankUpdateSymMatrixSpace*>(GetRawPtr( orig_h_space)); DBG_ASSERT(LR_h_space); SmartPtr<LowRankUpdateSymMatrixSpace> new_orig_h_space = new LowRankUpdateSymMatrixSpace(LR_h_space->Dim(), NULL, orig_x_space, false); h_space_->SetCompSpace(0, 0, *new_orig_h_space, true); } else { SmartPtr<SumSymMatrixSpace> sumsym_mat_space = new SumSymMatrixSpace(orig_x_space->Dim(), 2); sumsym_mat_space->SetTermSpace(0, *orig_h_space); sumsym_mat_space->SetTermSpace(1, *DR_x_space); h_space_->SetCompSpace(0, 0, *sumsym_mat_space, true); // All remaining blocks are zero'ed out } /////////////////////////// // Create the bound data // /////////////////////////// // x_L x_L_ = x_l_space_->MakeNewCompoundVector(); x_L_->SetComp(0, *orig_ip_nlp_->x_L()); // x >= x_L x_L_->GetCompNonConst(1)->Set(0.0); // n_c >= 0 x_L_->GetCompNonConst(2)->Set(0.0); // p_c >= 0 x_L_->GetCompNonConst(3)->Set(0.0); // n_d >= 0 x_L_->GetCompNonConst(4)->Set(0.0); // p_d >= 0 DBG_PRINT_VECTOR(2, "resto_x_L", *x_L_); // x_U x_U_ = x_u_space_->MakeNewCompoundVector(); x_U_->SetComp(0, *orig_ip_nlp_->x_U()); // d_L d_L_ = d_l_space_->MakeNewCompoundVector(); d_L_->SetComp(0, *orig_ip_nlp_->d_L()); // d_U d_U_ = d_u_space_->MakeNewCompoundVector(); d_U_->SetComp(0, *orig_ip_nlp_->d_U()); // Px_L Px_L_ = px_l_space_->MakeNewCompoundMatrix(); Px_L_->SetComp(0, 0, *orig_ip_nlp_->Px_L()); // Identities are auto-created (true flag passed into SetCompSpace) // Px_U Px_U_ = px_u_space_->MakeNewCompoundMatrix(); Px_U_->SetComp(0, 0, *orig_ip_nlp_->Px_U()); // Remaining matrices will be zero'ed out // Pd_L //Pd_L_ = orig_ip_nlp_->Pd_L(); Pd_L_ = pd_l_space_->MakeNewCompoundMatrix(); Pd_L_->SetComp(0, 0, *orig_ip_nlp_->Pd_L()); // Pd_U //Pd_U_ = orig_ip_nlp_->Pd_U(); Pd_U_ = pd_u_space_->MakeNewCompoundMatrix(); Pd_U_->SetComp(0, 0, *orig_ip_nlp_->Pd_U()); // Getting the NLP scaling SmartPtr<const MatrixSpace> scaled_jac_c_space; SmartPtr<const MatrixSpace> scaled_jac_d_space; SmartPtr<const SymMatrixSpace> scaled_h_space; NLP_scaling()->DetermineScaling(GetRawPtr(x_space_), c_space_, d_space_, GetRawPtr(jac_c_space_), GetRawPtr(jac_d_space_), GetRawPtr(h_space_), scaled_jac_c_space, scaled_jac_d_space, scaled_h_space, *Px_L_, *x_L_, *Px_U_, *x_U_); // For now we assume that no scaling is done inside the NLP_Scaling DBG_ASSERT(scaled_jac_c_space == jac_c_space_); DBG_ASSERT(scaled_jac_d_space == jac_d_space_); DBG_ASSERT(scaled_h_space == h_space_); ///////////////////////////////////////////////////////////////////////// // Create and initialize the vectors for the restoration phase problem // ///////////////////////////////////////////////////////////////////////// // Vector x SmartPtr<CompoundVector> comp_x = x_space_->MakeNewCompoundVector(); if( init_x ) { comp_x->GetCompNonConst(0)->Copy(*orig_ip_data_->curr()->x()); comp_x->GetCompNonConst(1)->Set(1.0); comp_x->GetCompNonConst(2)->Set(1.0); comp_x->GetCompNonConst(3)->Set(1.0); comp_x->GetCompNonConst(4)->Set(1.0); } x = GetRawPtr(comp_x); // Vector y_c y_c = c_space_->MakeNew(); if( init_y_c ) { y_c->Set(0.0); // ToDo } // Vector y_d y_d = d_space_->MakeNew(); if( init_y_d ) { y_d->Set(0.0); } // Vector z_L z_L = x_l_space_->MakeNew(); if( init_z_L ) { z_L->Set(1.0); } // Vector z_U z_U = x_u_space_->MakeNew(); if( init_z_U ) { z_U->Set(1.0); } // Vector v_L v_L = d_l_space_->MakeNew(); // Vector v_U v_U = d_u_space_->MakeNew(); // Initialize other data needed by the restoration nlp. x_ref is // the point to reference to which we based the regularization // term x_ref_ = orig_x_space->MakeNew(); x_ref_->Copy(*orig_ip_data_->curr()->x()); dr_x_ = orig_x_space->MakeNew(); dr_x_->Set(1.0); SmartPtr<Vector> tmp = dr_x_->MakeNew(); tmp->Copy(*x_ref_); dr_x_->ElementWiseMax(*tmp); tmp->Scal(-1.); dr_x_->ElementWiseMax(*tmp); dr_x_->ElementWiseReciprocal(); DBG_PRINT_VECTOR(2, "dr_x_", *dr_x_); DR_x_ = DR_x_space->MakeNewDiagMatrix(); DR_x_->SetDiag(*dr_x_); return true; }