コード例 #1
0
ファイル: IpNLPScaling.cpp プロジェクト: ChinaQuants/Ipopt
 SmartPtr<const Vector> NLPScalingObject::apply_vector_scaling_d_LU(
   const Matrix& Pd_LU,
   const SmartPtr<const Vector>& lu,
   const VectorSpace& d_space)
 {
   DBG_START_METH("NLPScalingObject::apply_vector_scaling_d_LU", dbg_verbosity);
   if (have_d_scaling()) {
     return ConstPtr(apply_vector_scaling_d_LU_NonConst(Pd_LU, lu, d_space));
   }
   else {
     return lu;
   }
 }
コード例 #2
0
SmartPtr<const Vector> StandardScalingBase::unapply_vector_scaling_d(
   const SmartPtr<const Vector>& v
   )
{
   DBG_START_METH("NLPScalingObject::unapply_vector_scaling_d", dbg_verbosity);
   if( IsValid(scaled_jac_d_space_) && IsValid(scaled_jac_d_space_->RowScaling()) )
   {
      return ConstPtr(unapply_vector_scaling_d_NonConst(v));
   }
   else
   {
      return v;
   }
}
コード例 #3
0
SmartPtr<const Vector> StandardScalingBase::unapply_vector_scaling_x(
   const SmartPtr<const Vector>& v
   )
{
   DBG_START_METH("NLPScalingObject::unapply_vector_scaling_x", dbg_verbosity);
   if( IsValid(dx_) )
   {
      return ConstPtr(unapply_vector_scaling_x_NonConst(v));
   }
   else
   {
      return v;
   }
}
コード例 #4
0
ファイル: IpNLPScaling.cpp プロジェクト: ChinaQuants/Ipopt
 SmartPtr<const Vector> NLPScalingObject::unapply_grad_obj_scaling(
   const SmartPtr<const Vector>& v)
 {
   DBG_START_METH("NLPScalingObject::unapply_grad_obj_scaling", dbg_verbosity);
   Number df = unapply_obj_scaling(1.);
   if (df != 1.) {
     SmartPtr<Vector> unscaled_v = unapply_grad_obj_scaling_NonConst(v);
     return ConstPtr(unscaled_v);
   }
   else {
     SmartPtr<const Vector> scaled_v = apply_vector_scaling_x(v);
     return scaled_v;
   }
 }
コード例 #5
0
  void AlgorithmBuilder::BuildIpoptObjects(const Journalist& jnlst,
      const OptionsList& options,
      const std::string& prefix,
      const SmartPtr<NLP>& nlp,
      SmartPtr<IpoptNLP>& ip_nlp,
      SmartPtr<IpoptData>& ip_data,
      SmartPtr<IpoptCalculatedQuantities>& ip_cq)
  {
    DBG_ASSERT(prefix == "");

    SmartPtr<NLPScalingObject> nlp_scaling ;
    std::string nlp_scaling_method;
    options.GetStringValue("nlp_scaling_method", nlp_scaling_method, "");
    if (nlp_scaling_method == "user-scaling") {
      nlp_scaling = new UserScaling(ConstPtr(nlp));
    }
    else if (nlp_scaling_method == "gradient-based") {
      nlp_scaling = new GradientScaling(nlp);
    }
    else if (nlp_scaling_method == "equilibration-based") {
      nlp_scaling = new EquilibrationScaling(nlp);
    }
    else {
      nlp_scaling = new NoNLPScalingObject();
    }

    ip_nlp = new OrigIpoptNLP(&jnlst, GetRawPtr(nlp), nlp_scaling);

    // Create the IpoptData.  Check if there is additional data that
    // is needed
    std::string lsmethod;
    SmartPtr<IpoptAdditionalData> add_data;
    options.GetStringValue("line_search_method", lsmethod, prefix);
    if (lsmethod=="cg-penalty") {
      add_data = new CGPenaltyData();
    }
    ip_data = new IpoptData(add_data);

    // Create the IpoptCalculators.  Check if there are additional
    // calcluated quantities that are needed
    ip_cq = new IpoptCalculatedQuantities(ip_nlp, ip_data);
    if (lsmethod=="cg-penalty") {
      SmartPtr<IpoptAdditionalCq> add_cq =
        new CGPenaltyCq(GetRawPtr(ip_nlp), GetRawPtr(ip_data),
                        GetRawPtr(ip_cq));
      ip_cq->SetAddCq(add_cq);
    }
  }
コード例 #6
0
 /** Use this method to create a new const IteratesVector. You must pass in
  *  valid pointers for all of the entries.
  */
 const SmartPtr<const IteratesVector> MakeNewIteratesVector(const Vector& x, const Vector& s,
     const Vector& y_c, const Vector& y_d,
     const Vector& z_L, const Vector& z_U,
     const Vector& v_L, const Vector& v_U)
 {
   SmartPtr<IteratesVector> newvec = MakeNewIteratesVector(false);
   newvec->Set_x(x);
   newvec->Set_s(s);
   newvec->Set_y_c(y_c);
   newvec->Set_y_d(y_d);
   newvec->Set_z_L(z_L);
   newvec->Set_z_U(z_U);
   newvec->Set_v_L(v_L);
   newvec->Set_v_U(v_U);
   return ConstPtr(newvec);
 }
コード例 #7
0
  SmartPtr<const Vector>
  AugRestoSystemSolver::Neg_Omega_c_plus_D_c(
    const SmartPtr<const Vector>& sigma_tilde_n_c_inv,
    const SmartPtr<const Vector>& sigma_tilde_p_c_inv,
    const Vector* D_c,
    const Vector& any_vec_in_c)
  {
    DBG_START_METH("AugRestoSystemSolver::Neg_Omega_c_plus_D_c",dbg_verbosity);
    SmartPtr<Vector> retVec;
    if (IsValid(sigma_tilde_n_c_inv) || IsValid(sigma_tilde_p_c_inv) || D_c) {
      if (!neg_omega_c_plus_D_c_cache_.
          GetCachedResult3Dep(retVec, GetRawPtr(sigma_tilde_n_c_inv), GetRawPtr(sigma_tilde_p_c_inv), D_c)) {
        DBG_PRINT((1,"Not found in cache\n"));
        retVec = any_vec_in_c.MakeNew();

        Number fact1, fact2;
        SmartPtr<const Vector> v1;
        SmartPtr<const Vector> v2;

        if (IsValid(sigma_tilde_n_c_inv)) {
          v1 = sigma_tilde_n_c_inv;
          fact1 = -1.;
        }
        else {
          v1 = &any_vec_in_c;
          fact1 = 0.;
        }
        if (IsValid(sigma_tilde_p_c_inv)) {
          v2 = sigma_tilde_p_c_inv;
          fact2 = -1.;
        }
        else {
          v2 = &any_vec_in_c;
          fact2 = 0.;
        }
        retVec->AddTwoVectors(fact1, *v1, fact2, *v2, 0.);

        if (D_c) {
          retVec->Axpy(1.0, *D_c);
        }

        neg_omega_c_plus_D_c_cache_.
        AddCachedResult3Dep(retVec, GetRawPtr(sigma_tilde_n_c_inv), GetRawPtr(sigma_tilde_p_c_inv), D_c);
      }
    }
    return ConstPtr(retVec);
  }
コード例 #8
0
  bool IndexPCalculator::ComputeP()
  {
    DBG_START_METH("IndexPCalculator::ComputeP", dbg_verbosity);
    bool retval = true;

    // 1. check whether all columns needed by data_A() are in map cols_ - we suppose data_A is IndexSchurData
    const std::vector<Index>* p2col_idx = dynamic_cast<const IndexSchurData*>(GetRawPtr(data_A()))->GetColIndices();
    Index col;
    Number* col_values = NULL;
    Index curr_dim, curr_schur_row=0;
    SmartPtr<const DenseVector> comp_vec;
    const Number* comp_values;
    std::map< Index, SmartPtr<PColumn> >::iterator find_it;
    SmartPtr<IteratesVector> col_vec = IpData().curr()->MakeNewIteratesVector();
    SmartPtr<IteratesVector> sol_vec = col_vec->MakeNewIteratesVector();
    for (std::vector<Index>::const_iterator col_it=p2col_idx->begin(); col_it!=p2col_idx->end(); ++col_it){
      col = *col_it;

      find_it = cols_.find(col);
      if (find_it==cols_.end()) {
	// column is in data_A but not in P-matrix ->create
	data_A()->GetRow(curr_schur_row, *col_vec);
	retval = Solver()->Solve(sol_vec, ConstPtr(col_vec));
	DBG_ASSERT(retval);

	/* This part is for displaying norm2(I_z*K^(-1)*I_1) */
	DBG_PRINT((dbg_verbosity,"\ncurr_schur_row=%d, ",curr_schur_row));
	DBG_PRINT((dbg_verbosity,"norm2(z)=%23.16e\n",sol_vec->x()->Nrm2()));
	/* end displaying norm2 */

	DBG_ASSERT(col_values== NULL);
	col_values = new Number[nrows_];
	curr_dim = 0;
	for (Index j=0; j<sol_vec->NComps(); ++j) {
	  comp_vec = dynamic_cast<const DenseVector*>(GetRawPtr(sol_vec->GetComp(j)));
	  comp_values = comp_vec->Values();
	  IpBlasDcopy(comp_vec->Dim(), comp_values, 1, col_values+curr_dim,1);
	  curr_dim += comp_vec->Dim();
	}
	cols_[col] = new PColumn(nrows_, col_values);
	col_values = NULL;
      }
      curr_schur_row++;
    }

    return retval;
  }
コード例 #9
0
  inline
  void CGPenaltyData::set_delta_cgfast(SmartPtr<IteratesVector>& delta_cgfast)
  {
    delta_cgfast_ = ConstPtr(delta_cgfast);
#if COIN_IPOPT_CHECKLEVEL > 0

    if (IsValid(delta_cgfast)) {
      debug_delta_cgfast_tag_ = delta_cgfast->GetTag();
      debug_delta_cgfast_tag_sum_ = delta_cgfast->GetTagSum();
    }
    else {
      debug_delta_cgfast_tag_ = 0;
      debug_delta_cgfast_tag_sum_ = delta_cgfast->GetTagSum();
    }
#endif

    delta_cgfast = NULL;
  }
コード例 #10
0
ファイル: IpIpoptData.hpp プロジェクト: CodeGuro/Ipopt
  inline
  void IpoptData::set_delta_aff(SmartPtr<IteratesVector>& delta_aff)
  {
    delta_aff_ = ConstPtr(delta_aff);
#if COIN_IPOPT_CHECKLEVEL > 0

    if (IsValid(delta_aff)) {
      debug_delta_aff_tag_ = delta_aff->GetTag();
      debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
    }
    else {
      debug_delta_aff_tag_ = TaggedObject::Tag();
      debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
    }
#endif

    delta_aff = NULL;
  }
コード例 #11
0
  inline
  void CGPenaltyData::set_delta_cgpen(SmartPtr<IteratesVector>& delta_cgpen)
  {
    delta_cgpen_ = ConstPtr(delta_cgpen);
#if COIN_IPOPT_CHECKLEVEL > 0

    if (IsValid(delta_cgpen)) {
      debug_delta_cgpen_tag_ = delta_cgpen->GetTag();
      debug_delta_cgpen_tag_sum_ = delta_cgpen->GetTagSum();
    }
    else {
      debug_delta_cgpen_tag_ = TaggedObject::Tag();
      debug_delta_cgpen_tag_sum_ = delta_cgpen->GetTagSum();
    }
#endif

    delta_cgpen = NULL;
  }
コード例 #12
0
ファイル: IpIpoptData.hpp プロジェクト: alyst/Ipopt
  inline
  void IpoptData::set_delta(SmartPtr<IteratesVector>& delta)
  {
    delta_ = ConstPtr(delta);
#if COIN_IPOPT_CHECKLEVEL > 0

    if (IsValid(delta)) {
      debug_delta_tag_ = delta->GetTag();
      debug_delta_tag_sum_ = delta->GetTagSum();
    }
    else {
      debug_delta_tag_ = 0;
      debug_delta_tag_sum_ = 0;
    }
#endif

    delta = NULL;
  }
コード例 #13
0
ファイル: IpIpoptData.hpp プロジェクト: CodeGuro/Ipopt
  inline
  void IpoptData::set_trial(SmartPtr<IteratesVector>& trial)
  {
    trial_ = ConstPtr(trial);

#if COIN_IPOPT_CHECKLEVEL > 0
    // verify the correct space
    DBG_ASSERT(trial_->OwnerSpace() == (VectorSpace*)GetRawPtr(iterates_space_));
    if (IsValid(trial)) {
      debug_trial_tag_ = trial->GetTag();
      debug_trial_tag_sum_ = trial->GetTagSum();
    }
    else {
      debug_trial_tag_ = TaggedObject::Tag();
      debug_trial_tag_sum_ = TaggedObject::Tag();
    }
#endif

    trial = NULL;
  }
コード例 #14
0
  SmartPtr<const Vector> AugRestoSystemSolver::D_x_plus_wr_d(
    const SmartPtr<const Vector>& CD_x0,
    Number factor,
    const Vector& wr_d)
  {
    DBG_START_METH("AugRestoSystemSolver::D_x_plus_wr_d",dbg_verbosity);
    SmartPtr<Vector> retVec;

    std::vector<const TaggedObject*> deps(2);
    deps[0] = &wr_d;
    if (IsValid(CD_x0)) {
      deps[1] = GetRawPtr(CD_x0);
    }
    else {
      deps[1] = NULL;
    }
    std::vector<Number> scalar_deps(1);
    scalar_deps[0] = factor;

    if (!d_x_plus_wr_d_cache_.GetCachedResult(retVec, deps, scalar_deps)) {
      DBG_PRINT((1,"Not found in cache\n"));
      retVec = wr_d.MakeNew();

      Number fact;
      SmartPtr<const Vector> v;
      if (IsValid(CD_x0)) {
        fact = 1.;
        v = CD_x0;
      }
      else {
        fact = 0.;
        v = &wr_d;
      }
      retVec->AddTwoVectors(factor, wr_d, fact, *v, 0.);

      d_x_plus_wr_d_cache_.AddCachedResult(retVec, deps, scalar_deps);
    }
    DBG_PRINT_VECTOR(2, "retVec", *retVec);
    return ConstPtr(retVec);
  }
コード例 #15
0
SmartPtr<const Vector> RestoIpoptNLP::grad_f(
   const Vector& x,
   Number        mu
   )
{
   SmartPtr<Vector> retPtr = x.MakeNew();
   // Scale the p's and n's by rho (Scale all, take out the x part later)
   retPtr->Set(rho_);

   const CompoundVector* c_vec_in = static_cast<const CompoundVector*>(&x);
   SmartPtr<const Vector> x_only_in = c_vec_in->GetComp(0);

   CompoundVector* c_vec = static_cast<CompoundVector*>(GetRawPtr(retPtr));
   DBG_ASSERT(c_vec);
   SmartPtr<Vector> x_only = c_vec->GetCompNonConst(0);
   x_only->Copy(*x_only_in);
   x_only->Axpy(-1.0, *x_ref_);
   x_only->ElementWiseMultiply(*dr_x_);
   x_only->Scal(Eta(mu));

   return ConstPtr(retPtr);
}
コード例 #16
0
 SmartPtr<const Vector>
 AugRestoSystemSolver::Neg_Omega_d_plus_D_d(
   const Matrix& Pd_L,
   const SmartPtr<const Vector>& sigma_tilde_n_d_inv,
   const Matrix& neg_Pd_U,
   const SmartPtr<const Vector>& sigma_tilde_p_d_inv,
   const Vector* D_d,
   const Vector& any_vec_in_d)
 {
   DBG_START_METH("AugRestoSystemSolver::Neg_Omega_d_plus_D_d",dbg_verbosity);
   SmartPtr<Vector> retVec;
   if (IsValid(sigma_tilde_n_d_inv) || IsValid(sigma_tilde_p_d_inv) || D_d) {
     std::vector<const TaggedObject*> deps(5);
     std::vector<Number> scalar_deps;
     deps[0] = &Pd_L;
     deps[1] = GetRawPtr(sigma_tilde_n_d_inv);
     deps[2] = &neg_Pd_U;
     deps[3] = GetRawPtr(sigma_tilde_p_d_inv);
     deps[4] = D_d;
     if (!neg_omega_d_plus_D_d_cache_.
         GetCachedResult(retVec, deps, scalar_deps)) {
       DBG_PRINT((1,"Not found in cache\n"));
       retVec = any_vec_in_d.MakeNew();
       retVec->Set(0.0);
       if (IsValid(sigma_tilde_n_d_inv)) {
         Pd_L.MultVector(-1.0, *sigma_tilde_n_d_inv, 1.0, *retVec);
       }
       if (IsValid(sigma_tilde_p_d_inv)) {
         neg_Pd_U.MultVector(1.0, *sigma_tilde_p_d_inv, 1.0, *retVec);
       }
       if (D_d) {
         retVec->Copy(*D_d);
       }
       neg_omega_d_plus_D_d_cache_.
       AddCachedResult(retVec, deps, scalar_deps);
     }
   }
   return ConstPtr(retVec);
 }
コード例 #17
0
  SmartPtr<const Vector> AugRestoSystemSolver::Rhs_dR(const Vector& rhs_d,
      const SmartPtr<const Vector>& sigma_tilde_n_d_inv, const Vector& rhs_n_d, const Matrix& pd_L,
      const SmartPtr<const Vector>& sigma_tilde_p_d_inv, const Vector& rhs_p_d, const Matrix& neg_pd_U)
  {
    DBG_START_METH("AugRestoSystemSolver::Rhs_dR",dbg_verbosity);
    SmartPtr<Vector> retVec;
    std::vector<const TaggedObject*> deps(7);
    std::vector<Number> scalar_deps;
    deps[0] = &rhs_d;
    deps[1] = GetRawPtr(sigma_tilde_n_d_inv);
    deps[2] = &rhs_n_d;
    deps[3] = &pd_L;
    deps[4] = GetRawPtr(sigma_tilde_p_d_inv);
    deps[5] = &rhs_p_d;
    deps[6] = &neg_pd_U;
    if (!rhs_dR_cache_.GetCachedResult(retVec, deps, scalar_deps)) {
      DBG_PRINT((1,"Not found in cache\n"));
      retVec = rhs_d.MakeNew();
      retVec->Copy(rhs_d);

      if (IsValid(sigma_tilde_n_d_inv)) {
        SmartPtr<Vector> tmpn = sigma_tilde_n_d_inv->MakeNew();
        tmpn->Copy(*sigma_tilde_n_d_inv);
        tmpn->ElementWiseMultiply(rhs_n_d);
        pd_L.MultVector(-1.0, *tmpn, 1.0, *retVec);
      }

      if (IsValid(sigma_tilde_p_d_inv)) {
        SmartPtr<Vector> tmpp = sigma_tilde_p_d_inv->MakeNew();
        tmpp->Copy(*sigma_tilde_p_d_inv);
        tmpp->ElementWiseMultiply(rhs_p_d);
        neg_pd_U.MultVector(-1.0, *tmpp, 1.0, *retVec);
      }

      rhs_dR_cache_.AddCachedResult(retVec, deps, scalar_deps);
    }
    return ConstPtr(retVec);
  }
コード例 #18
0
  SmartPtr<const Vector> AugRestoSystemSolver::Sigma_tilde_n_c_inv(
    const SmartPtr<const Vector>& sigma_n_c,
    Number delta_x,
    const Vector& any_vec_in_c)
  {
    DBG_START_METH("AugRestoSystemSolver::Sigma_tilde_n_c_inv",dbg_verbosity);
    SmartPtr<Vector> retVec;
    if (IsValid(sigma_n_c) || delta_x != 0.0) {
      std::vector<const TaggedObject*> deps(1);
      std::vector<Number> scalar_deps(1);
      deps[0] = GetRawPtr(sigma_n_c);
      scalar_deps[0] = delta_x;
      if (!sigma_tilde_n_c_inv_cache_.GetCachedResult(retVec, deps, scalar_deps)) {
        DBG_PRINT((1,"Not found in cache\n"));
        retVec = any_vec_in_c.MakeNew();
        if (IsValid(sigma_n_c)) {
          if (delta_x != 0.) {
            retVec->Copy(*sigma_n_c);
            retVec->AddScalar(delta_x);
            retVec->ElementWiseReciprocal();
          }
          else {
            // Given a "homogenous vector" implementation (such as in
            // DenseVector) the following should be more efficient
            retVec->Set(1.);
            retVec->ElementWiseDivide(*sigma_n_c);
          }
        }
        else {
          retVec->Set(1./delta_x);
        }

        sigma_tilde_n_c_inv_cache_.AddCachedResult(retVec, deps, scalar_deps);
      }
    }

    return ConstPtr(retVec);
  }
コード例 #19
0
  SmartPtr<const Vector> AugRestoSystemSolver::Sigma_tilde_p_d_inv(
    const SmartPtr<const Vector>& sigma_p_d,
    Number delta_x,
    const Vector& any_vec_in_p_d)
  {
    DBG_START_METH("AugRestoSystemSolver::Sigma_tilde_p_d_inv",dbg_verbosity);
    SmartPtr<Vector> retVec;
    if (IsValid(sigma_p_d) || delta_x != 0) {
      std::vector<const TaggedObject*> deps(1);
      std::vector<Number> scalar_deps(1);
      deps[0] = GetRawPtr(sigma_p_d);
      scalar_deps[0] = delta_x;
      if (!sigma_tilde_p_d_inv_cache_.GetCachedResult(retVec, deps, scalar_deps)) {
        DBG_PRINT((1,"Not found in cache\n"));
        retVec = any_vec_in_p_d.MakeNew();

        if (IsValid(sigma_p_d)) {
          if (delta_x != 0.) {
            retVec->Copy(*sigma_p_d);
            retVec->AddScalar(delta_x);
            retVec->ElementWiseReciprocal();
          }
          else {
            retVec->Set(1.);
            retVec->ElementWiseDivide(*sigma_p_d);
          }
        }
        else {
          retVec->Set(1./delta_x);
        }

        sigma_tilde_p_d_inv_cache_.AddCachedResult(retVec, deps, scalar_deps);
      }
    }

    return ConstPtr(retVec);
  }
コード例 #20
0
ファイル: IpNLPScaling.cpp プロジェクト: AyMaN-GhOsT/simbody
  SmartPtr<Vector> NLPScalingObject::apply_vector_scaling_x_LU_NonConst(
    const Matrix& Px_LU,
    const SmartPtr<const Vector>& lu,
    const VectorSpace& x_space)
  {
    SmartPtr<Vector> scaled_x_LU = lu->MakeNew();
    if (have_x_scaling()) {
      SmartPtr<Vector> tmp_x = x_space.MakeNew();

      // move to full x space
      Px_LU.MultVector(1.0, *lu, 0.0, *tmp_x);

      // scale in full x space
      tmp_x = apply_vector_scaling_x_NonConst(ConstPtr(tmp_x));

      // move back to x_L space
      Px_LU.TransMultVector(1.0, *tmp_x, 0.0, *scaled_x_LU);
    }
    else {
      scaled_x_LU->Copy(*lu);
    }

    return scaled_x_LU;
  }
コード例 #21
0
ファイル: IpNLPScaling.cpp プロジェクト: AyMaN-GhOsT/simbody
  SmartPtr<Vector> NLPScalingObject::unapply_vector_scaling_d_LU_NonConst(
    const Matrix& Pd_LU,
    const SmartPtr<const Vector>& lu,
    const VectorSpace& d_space)
  {
    SmartPtr<Vector> unscaled_d_LU = lu->MakeNew();
    if (have_d_scaling()) {
      SmartPtr<Vector> tmp_d = d_space.MakeNew();

      // move to full d space
      Pd_LU.MultVector(1.0, *lu, 0.0, *tmp_d);

      // scale in full x space
      tmp_d = unapply_vector_scaling_d_NonConst(ConstPtr(tmp_d));

      // move back to x_L space
      Pd_LU.TransMultVector(1.0, *tmp_d, 0.0, *unscaled_d_LU);
    }
    else {
      unscaled_d_LU->Copy(*lu);
    }

    return unscaled_d_LU;
  }
コード例 #22
0
ファイル: IpScaledMatrix.hpp プロジェクト: Gjacquenot/simbody
 inline
 SmartPtr<const Vector> ScaledMatrix::ColumnScaling() const
 {
   return ConstPtr(owner_space_->ColumnScaling());
 }
コード例 #23
0
ファイル: IpScaledMatrix.hpp プロジェクト: Gjacquenot/simbody
 /** return the vector for the column scaling */
 SmartPtr<const Vector> ColumnScaling() const
 {
   return ConstPtr(column_scaling_);
 }
コード例 #24
0
ファイル: IpScaledMatrix.hpp プロジェクト: Gjacquenot/simbody
 /** return the vector for the row scaling */
 SmartPtr<const Vector> RowScaling() const
 {
   return ConstPtr(row_scaling_);
 }
コード例 #25
0
 /** Method returning the scaling factors for the 2-norm
  *  penalization term.
  */
 SmartPtr<const Vector> DR_x() const
 {
    return ConstPtr(dr_x_);
 }
コード例 #26
0
  SensAlgorithmExitStatus SensApplication::Run()
  {
    DBG_START_METH("SensApplication::Run", dbg_verbosity);

    SensAlgorithmExitStatus retval = SOLVE_SUCCESS;

    bool sens_internal_abort, redhess_internal_abort;
    Options()->GetBoolValue("sens_internal_abort", sens_internal_abort, "");
    Options()->GetBoolValue("redhess_internal_abort", redhess_internal_abort, "");
    if (run_sens_ && sens_internal_abort) {
      jnlst_->Printf(J_WARNING, J_MAIN, "\n\t--------------= Warning =--------------\nInternal abort has been called for the sensitivity calculations.\n");
    }
    if (compute_red_hessian_ && redhess_internal_abort) {
      jnlst_->Printf(J_WARNING, J_MAIN, "\n\t--------------= Warning =--------------\nInternal abort has been called for the sensitivity calculations.\n");
    }

    SolverReturn status = AppReturn2SolverReturn(ipopt_retval_);

    // Check for perturbation of primal dual system
    Number max_pdpert;
    if (ipopt_retval_==0 || ipopt_retval_==1) { // otherwise, the values might not be available
      Options()->GetNumericValue("sens_max_pdpert", max_pdpert, "");
      Number pdpert_x, pdpert_s, pdpert_c, pdpert_d;
      ip_data_->getPDPert(pdpert_x, pdpert_s, pdpert_c, pdpert_d);
      if (Max(pdpert_x, pdpert_s, pdpert_c, pdpert_d)>max_pdpert) {
	jnlst_->Printf(J_WARNING, J_MAIN, "\n\t--------------= Warning =--------------\nInertia correction of primal dual system is too large for meaningful sIPOPT results.\n"
		       "\t... aborting computation.\n"
		       "Set option sens_max_pdpert to a higher value (current: %f) to run sIPOPT algorithm anyway\n", max_pdpert);
	sens_internal_abort = true;
	redhess_internal_abort = true;
      }
    }


    if (compute_red_hessian_ && !redhess_internal_abort) {
      SmartPtr<SensBuilder> schur_builder = new SensBuilder();
      const std::string prefix = ""; // I should be getting this somewhere else...
      SmartPtr<ReducedHessianCalculator> red_hess_calc = schur_builder->BuildRedHessCalc(*jnlst_,
											 *options_,
											 prefix,
											 *ip_nlp_,
											 *ip_data_,
											 *ip_cq_,
											 *pd_solver_);

      red_hess_calc->ComputeReducedHessian();
    }

    if (run_sens_ && n_sens_steps_>0 && !sens_internal_abort) {
      SmartPtr<SensBuilder> schur_builder = new SensBuilder();
      const std::string prefix = ""; // I should be getting this somewhere else...
      SmartPtr<SensAlgorithm> controller = schur_builder->BuildSensAlg(*jnlst_,
								       *options_,
								       prefix,
								       *ip_nlp_,
								       *ip_data_,
								       *ip_cq_,
								       *pd_solver_);

      retval = controller->Run();
    }
    else if (run_sens_) {
      if (n_sens_steps_<=0) {
	jnlst_->Printf(J_WARNING, J_MAIN, "\n"
		       "The run_sens option was set to true, but the specified\n"
		       "number of sensitivity steps was set to zero.\n"
		       "Computation is aborted.\n\n");
      }
    }


    if (IsValid(ip_data_->curr()) && IsValid(ip_data_->curr()->x())) {
      SmartPtr<const Vector> c;
      SmartPtr<const Vector> d;
      SmartPtr<const Vector> zL;
      SmartPtr<const Vector> zU;
      SmartPtr<const Vector> yc;
      SmartPtr<const Vector> yd;
      Number obj = 0.;

      switch (status) {
      case SUCCESS:
	/*c = ip_cq_->curr_c();
	  d = ip_cq_->curr_d();
	  obj = ip_cq_->curr_f();
	  zL = ip_data_->curr()->z_L();
	  zU = ip_data_->curr()->z_U();
	  yc = ip_data_->curr()->y_c();
	  yd = ip_data_->curr()->y_d();*/
      case MAXITER_EXCEEDED:
      case STOP_AT_TINY_STEP:
      case STOP_AT_ACCEPTABLE_POINT:
      case LOCAL_INFEASIBILITY:
      case USER_REQUESTED_STOP:
      case FEASIBLE_POINT_FOUND:
      case DIVERGING_ITERATES:
      case RESTORATION_FAILURE:
      case ERROR_IN_STEP_COMPUTATION:
	c = ip_cq_->curr_c();
	d = ip_cq_->curr_d();
	obj = ip_cq_->curr_f();
	zL = ip_data_->curr()->z_L();
	zU = ip_data_->curr()->z_U();
	yc = ip_data_->curr()->y_c();
	yd = ip_data_->curr()->y_d();
	break;
      default:
	SmartPtr<Vector> tmp = ip_data_->curr()->y_c()->MakeNew();
	tmp->Set(0.);
	c = ConstPtr(tmp);
	yc = ConstPtr(tmp);
	tmp = ip_data_->curr()->y_d()->MakeNew();
	tmp->Set(0.);
	d = ConstPtr(tmp);
	yd = ConstPtr(tmp);
	tmp = ip_data_->curr()->z_L()->MakeNew();
	tmp->Set(0.);
	zL = ConstPtr(tmp);
	tmp = ip_data_->curr()->z_U()->MakeNew();
	tmp->Set(0.);
	zU = ConstPtr(tmp);
      }

      if (compute_red_hessian_ && redhess_internal_abort) {
	jnlst_->Printf(J_WARNING, J_MAIN, "\nReduced hessian was not computed "
		       "because an error occured.\n"
		       "See exception message above for details.\n\n");
      }
      if (run_sens_ && sens_internal_abort) {
	jnlst_->Printf(J_WARNING, J_MAIN, "\nsIPOPT was not called "
		       "because an error occured.\n"
		       "See exception message above for details.\n\n");
      }

      ip_nlp_->FinalizeSolution(status,
				*ip_data_->curr()->x(),
				*zL, *zU, *c, *d, *yc, *yd,
				obj, GetRawPtr(ip_data_), GetRawPtr(ip_cq_));
    }
    return retval;
  }
コード例 #27
0
 /** return the vector for the row and column scaling */
 SmartPtr<const Vector> RowColScaling() const
 {
   return ConstPtr(scaling_);
 }
コード例 #28
0
ファイル: SensAlgorithm.cpp プロジェクト: ChinaQuants/Ipopt
  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);
    
  }
コード例 #29
0
ファイル: SensAlgorithm.cpp プロジェクト: ChinaQuants/Ipopt
  SensAlgorithmExitStatus SensAlgorithm::ComputeSensitivityMatrix(void) {
    
    DBG_START_METH("SensAlgorithm::ComputeSensitivityMatrix", dbg_verbosity);

    SensAlgorithmExitStatus retval = SOLVE_SUCCESS;

    /* Loop through all steps */
    SmartPtr<IteratesVector> sol = IpData().curr()->MakeNewIteratesVector();
    SmartPtr<const Vector> unscaled_x;
    SmartPtr<const Vector> unscaled_yc;
    
    SmartPtr<IteratesVector> trialcopy;

    SmartPtr<DenseVectorSpace> delta_u_space;
    delta_u_space = new DenseVectorSpace(2);

    SmartPtr<DenseVector> delta_u = new DenseVector(GetRawPtr(ConstPtr(delta_u_space)));

    Number* du_val = delta_u->Values();

    std::string state;
    std::string statevalue;

    state      = "sens_init_constr";
    statevalue = "sens_init_constr";

    SmartPtr<const DenseVectorSpace> x_owner_space_ = dynamic_cast<const DenseVectorSpace*>(GetRawPtr(IpData().curr()->y_c()->OwnerSpace())) ;
    //= dynamic_cast<const DenseVectorSpace*>(GetRawPtr(IpData().curr()->x()->OwnerSpace()));

    const std::vector<Index> idx_ipopt = x_owner_space_->GetIntegerMetaData(state.c_str());

    char buffer[250] ;

    Index col = 0 ;
    for (Index Scol =0; Scol < idx_ipopt.size(); ++Scol) {

      if ( idx_ipopt[Scol] > 0 ) {

	// reset rhs vector to zero
	for (Index j = 0; j < idx_ipopt.size(); ++j) {
	  if ( idx_ipopt[j] > 0 ) du_val[ idx_ipopt[j] - 1 ] = 0 ;
	}

	sprintf(buffer,"Column %i",idx_ipopt[Scol]) ;

	sens_step_calc_->SetSchurDriver(driver_vec_[0]);

	// set rhs to 1 (eq. 9-10)
	du_val[idx_ipopt[Scol]-1] = 1;

	delta_u->SetValues(du_val) ;
	//delta_u->Print(Jnlst(),J_VECTOR,J_USER1,"delta_u 1234567");
	sens_step_calc_->Step(*delta_u, *sol);
	SmartPtr<IteratesVector> saved_sol = sol->MakeNewIteratesVectorCopy();
	saved_sol->Print(Jnlst(),J_VECTOR,J_USER1,"sol_vec");

	// unscale solution...
	UnScaleIteratesVector(&saved_sol) ;

	saved_sol->Print(Jnlst(),J_VECTOR,J_USER1,buffer);
	
	// Save column
	GetSensitivityMatrix(col) ;
	++col ; // increase column counter
      }
    }
    return retval ;
  }
コード例 #30
0
 inline SmartPtr<const Vector> SymScaledMatrix::RowColScaling() const
 {
   return ConstPtr(owner_space_->RowColScaling());
 }