Changeset 414


Ignore:
Timestamp:
Jul 28, 2005 11:53:28 AM (14 years ago)
Author:
andreasw
Message:
  • several changes handling the NLP scaling
  • compute unscaled quantities in CalculatedQuantities? (such as errors)
  • print unscaled errors in output file and on console after solution
Location:
branches/dev
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • branches/dev/Algorithm/IpAdaptiveMuUpdate.cpp

    r409 r414  
    346346      // Choose the fraction-to-the-boundary parameter for the current
    347347      // iteration
    348       // ToDo
     348      // ToDo: Is curr_nlp_error really what we should use here?
    349349      Number tau = Max(tau_min_, 1.-IpCq().curr_nlp_error());
    350350      IpData().Set_tau(tau);
     
    413413                                           IpCq().curr_constraint_violation());
    414414        */
     415        // ToDo: Is curr_nlp_error really what we should use here?
    415416        Number curr_error = IpCq().curr_nlp_error();
    416417        Number margin = filter_margin_fact_*Min(filter_max_margin_, curr_error);
  • branches/dev/Algorithm/IpDefaultIterateInitializer.cpp

    r413 r414  
    8989
    9090    IpData().InitializeDataStructures(IpNLP(), true, false, false,
    91                                       false, false, false, false);
     91                                      false, false);
    9292
    9393    // get a container of the current point. We will modify parts of this
  • branches/dev/Algorithm/IpGradientScaling.cpp

    r410 r414  
    1818  {
    1919    roptions->AddLowerBoundedNumberOption(
    20       "scaling_max_gradient", "maximum gradient after scaling",
     20      "nlp_scaling_max_gradient", "maximum gradient after scaling",
    2121      0, true, 100.0,
    2222      "This is the gradient scaling cut-off. If the maximum"
     
    3030                                       const std::string& prefix)
    3131  {
    32     options.GetNumericValue("scaling_max_gradient", scaling_max_gradient_, prefix);
     32    options.GetNumericValue("nlp_scaling_max_gradient", scaling_max_gradient_, prefix);
    3333    return StandardScalingBase::InitializeImpl(options, prefix);
    3434  }
     
    5454                                NULL, false,
    5555                                NULL, false,
    56                                 NULL, false,
    57                                 NULL, false,
    5856                                NULL, false)) {
    5957      THROW_EXCEPTION(FAILED_INITIALIZATION,
  • branches/dev/Algorithm/IpIpoptCalculatedQuantities.cpp

    r407 r414  
    7373      curr_constraint_violation_cache_(2),
    7474      trial_constraint_violation_cache_(5),
     75      curr_nlp_constraint_violation_cache_(3),
     76      unscaled_curr_nlp_constraint_violation_cache_(3),
    7577
    7678      curr_grad_lag_x_cache_(1),
     
    9698      curr_dual_infeasibility_cache_(3),
    9799      trial_dual_infeasibility_cache_(3),
     100      unscaled_curr_dual_infeasibility_cache_(3),
    98101      curr_complementarity_cache_(6),
    99102      trial_complementarity_cache_(6),
    100103      curr_centrality_measure_cache_(1),
    101104      curr_nlp_error_cache_(1),
     105      unscaled_curr_nlp_error_cache_(1),
    102106      curr_barrier_error_cache_(1),
    103107      curr_primal_dual_system_error_cache_(1),
     
    527531  IpoptCalculatedQuantities::unscaled_curr_f()
    528532  {
    529     // this value is cached in IpOrigIpoptNLP (not in the resto...)
    530     return ip_nlp_->unscaled_f(*ip_data_->curr()->x());
     533    return ip_nlp_->NLP_scaling()->unapply_obj_scaling(curr_f());
    531534  }
    532535
     
    566569    DBG_PRINT((1,"result (trial_f) = %e\n", result));
    567570    return result;
     571  }
     572
     573  Number
     574  IpoptCalculatedQuantities::unscaled_trial_f()
     575  {
     576    return ip_nlp_->NLP_scaling()->unapply_obj_scaling(trial_f());
    568577  }
    569578
     
    10141023  IpoptCalculatedQuantities::unscaled_curr_c()
    10151024  {
    1016     // this value is cached in IpOrigIpoptNLP (not resto)
    1017     return ip_nlp_->unscaled_c(*ip_data_->curr()->x());
     1025    return ip_nlp_->NLP_scaling()->unapply_vector_scaling_c(curr_c());
    10181026  }
    10191027
     
    10551063  IpoptCalculatedQuantities::unscaled_curr_d()
    10561064  {
    1057     // this value is cached in IpOrigIpoptNLP (not the resto)
    1058     return ip_nlp_->unscaled_d(*ip_data_->curr()->x());
     1065    return ip_nlp_->NLP_scaling()->unapply_vector_scaling_d(curr_d());
    10591066  }
    10601067
     
    13501357                   dbg_verbosity);
    13511358    return trial_primal_infeasibility(constr_viol_normtype_);
     1359  }
     1360
     1361  Number
     1362  IpoptCalculatedQuantities::curr_nlp_constraint_violation
     1363  (ENormType NormType)
     1364  {
     1365    DBG_START_METH("IpoptCalculatedQuantities::curr_nlp_constraint_violation()",
     1366                   dbg_verbosity);
     1367    Number result;
     1368
     1369    SmartPtr<const Vector> x = ip_data_->curr()->x();
     1370
     1371    std::vector<const TaggedObject*> deps(1);
     1372    deps[0] = GetRawPtr(x);
     1373    std::vector<Number> sdeps(1);
     1374    sdeps[0] = (Number)NormType;
     1375
     1376    if (!curr_nlp_constraint_violation_cache_.GetCachedResult(result, deps, sdeps)) {
     1377      SmartPtr<const Vector> c = curr_c();
     1378      SmartPtr<const Vector> d = curr_d();
     1379
     1380      SmartPtr<Vector> d_viol_L = ip_nlp_->d_L()->MakeNewCopy();
     1381      ip_nlp_->Pd_L()->TransMultVector(-1., *d, 1., *d_viol_L);
     1382      SmartPtr<Vector> tmp = d_viol_L->MakeNew();
     1383      tmp->Set(0.);
     1384      d_viol_L->ElementWiseMax(*tmp);
     1385      DBG_PRINT_VECTOR(2, "d_viol_L", *d_viol_L);
     1386
     1387      SmartPtr<Vector> d_viol_U = ip_nlp_->d_U()->MakeNewCopy();
     1388      ip_nlp_->Pd_U()->TransMultVector(-1., *d, 1., *d_viol_U);
     1389      tmp = d_viol_U->MakeNew();
     1390      tmp->Set(0.);
     1391      d_viol_U->ElementWiseMin(*tmp);
     1392      DBG_PRINT_VECTOR(2, "d_viol_U", *d_viol_U);
     1393
     1394      std::vector<SmartPtr<const Vector> > vecs(3);
     1395      vecs[0] = c;
     1396      vecs[1] = GetRawPtr(d_viol_L);
     1397      vecs[2] = GetRawPtr(d_viol_U);
     1398      result = CalcNormOfType(NormType, vecs);
     1399      curr_nlp_constraint_violation_cache_.AddCachedResult(result, deps, sdeps);
     1400    }
     1401
     1402    return result;
     1403  }
     1404
     1405  Number
     1406  IpoptCalculatedQuantities::unscaled_curr_nlp_constraint_violation
     1407  (ENormType NormType)
     1408  {
     1409    DBG_START_METH("IpoptCalculatedQuantities::unscaled_curr_nlp_constraint_violation()",
     1410                   dbg_verbosity);
     1411    Number result;
     1412
     1413    SmartPtr<const Vector> x = ip_data_->curr()->x();
     1414
     1415    std::vector<const TaggedObject*> deps(1);
     1416    deps[0] = GetRawPtr(x);
     1417    std::vector<Number> sdeps(1);
     1418    sdeps[0] = (Number)NormType;
     1419
     1420    if (!unscaled_curr_nlp_constraint_violation_cache_.GetCachedResult(result, deps, sdeps)) {
     1421      SmartPtr<const Vector> c = unscaled_curr_c();
     1422
     1423      SmartPtr<const Vector> d = curr_d();
     1424
     1425      SmartPtr<Vector> d_viol_L = ip_nlp_->d_L()->MakeNewCopy();
     1426      ip_nlp_->Pd_L()->TransMultVector(-1., *d, 1., *d_viol_L);
     1427      SmartPtr<Vector> tmp = d_viol_L->MakeNew();
     1428      tmp->Set(0.);
     1429      d_viol_L->ElementWiseMax(*tmp);
     1430      DBG_PRINT_VECTOR(2, "d_viol_L", *d_viol_L);
     1431
     1432      SmartPtr<Vector> d_viol_U = ip_nlp_->d_U()->MakeNewCopy();
     1433      ip_nlp_->Pd_U()->TransMultVector(-1., *d, 1., *d_viol_U);
     1434      tmp = d_viol_U->MakeNew();
     1435      tmp->Set(0.);
     1436      d_viol_U->ElementWiseMin(*tmp);
     1437      DBG_PRINT_VECTOR(2, "d_viol_U", *d_viol_U);
     1438
     1439      std::vector<SmartPtr<const Vector> > vecs(3);
     1440      vecs[0] = c;
     1441      vecs[1] = GetRawPtr(d_viol_L);
     1442      vecs[2] = GetRawPtr(d_viol_U);
     1443      result = CalcNormOfType(NormType, vecs);
     1444      unscaled_curr_nlp_constraint_violation_cache_.AddCachedResult(result, deps, sdeps);
     1445    }
     1446
     1447    return result;
    13521448  }
    13531449
     
    21462242      }
    21472243      trial_dual_infeasibility_cache_.AddCachedResult(result, deps, sdeps);
     2244    }
     2245
     2246    return result;
     2247  }
     2248
     2249  Number
     2250  IpoptCalculatedQuantities::unscaled_curr_dual_infeasibility
     2251  (ENormType NormType)
     2252  {
     2253    DBG_START_METH("IpoptCalculatedQuantities::unscaled_curr_dual_infeasibility()",
     2254                   dbg_verbosity);
     2255    Number result;
     2256
     2257    SmartPtr<const Vector> x = ip_data_->curr()->x();
     2258    SmartPtr<const Vector> s = ip_data_->curr()->s();
     2259    SmartPtr<const Vector> y_c = ip_data_->curr()->y_c();
     2260    SmartPtr<const Vector> y_d = ip_data_->curr()->y_d();
     2261    SmartPtr<const Vector> z_L = ip_data_->curr()->z_L();
     2262    SmartPtr<const Vector> z_U = ip_data_->curr()->z_U();
     2263    SmartPtr<const Vector> v_L = ip_data_->curr()->v_L();
     2264    SmartPtr<const Vector> v_U = ip_data_->curr()->v_U();
     2265
     2266    std::vector<const TaggedObject*> deps(8);
     2267    deps[0] = GetRawPtr(x);
     2268    deps[1] = GetRawPtr(s);
     2269    deps[2] = GetRawPtr(y_c);
     2270    deps[3] = GetRawPtr(y_d);
     2271    deps[4] = GetRawPtr(z_L);
     2272    deps[5] = GetRawPtr(z_U);
     2273    deps[6] = GetRawPtr(v_L);
     2274    deps[7] = GetRawPtr(v_U);
     2275    std::vector<Number> sdeps(1);
     2276    sdeps[0] = (Number)NormType;
     2277
     2278    if (!unscaled_curr_dual_infeasibility_cache_.GetCachedResult(result, deps, sdeps)) {
     2279      SmartPtr<const Vector> grad_lag_x =
     2280        ip_nlp_->NLP_scaling()->unapply_grad_obj_scaling(curr_grad_lag_x());
     2281
     2282      Number obj_unscal = ip_nlp_->NLP_scaling()->unapply_obj_scaling(1.);
     2283      SmartPtr<const Vector> grad_lag_s;
     2284      if (obj_unscal != 1.) {
     2285        SmartPtr<Vector> tmp =
     2286          ip_nlp_->NLP_scaling()->apply_vector_scaling_d_NonConst(ConstPtr(curr_grad_lag_s()));
     2287        tmp->Scal(obj_unscal);
     2288        grad_lag_s = ConstPtr(tmp);
     2289      }
     2290      else {
     2291        grad_lag_s = ip_nlp_->NLP_scaling()->apply_vector_scaling_d(curr_grad_lag_s());
     2292      }
     2293
     2294      result = CalcNormOfType(NormType, *grad_lag_x, *grad_lag_s);
     2295      unscaled_curr_dual_infeasibility_cache_.AddCachedResult(result, deps, sdeps);
    21482296    }
    21492297
     
    22902438
    22912439  Number
     2440  IpoptCalculatedQuantities::unscaled_curr_complementarity
     2441  (Number mu, ENormType NormType)
     2442  {
     2443    return ip_nlp_->NLP_scaling()->unapply_obj_scaling(curr_complementarity(mu, NormType));
     2444  }
     2445
     2446  Number
    22922447  IpoptCalculatedQuantities::CalcCentralityMeasure(const Vector& compl_x_L,
    22932448      const Vector& compl_x_U,
     
    24422597      DBG_PRINT((1, "s_d = %lf, s_c = %lf\n", s_d, s_c));
    24432598
    2444       // Primal infeasibility
     2599      // Dual infeasibility
    24452600      DBG_PRINT((1, "curr_dual_infeasibility(NORM_MAX) = %8.2e\n",
    24462601                 curr_dual_infeasibility(NORM_MAX)));
    24472602      result = curr_dual_infeasibility(NORM_MAX)/s_d;
    2448       // Dual infeasibility
     2603      /*
     2604      // Primal infeasibility
    24492605      DBG_PRINT((1, "curr_primal_infeasibility(NORM_MAX) = %8.2e\n",
    24502606                 curr_primal_infeasibility(NORM_MAX)));
    24512607      result = Max(result, curr_primal_infeasibility(NORM_MAX));
     2608      */
     2609      result = Max(result, curr_nlp_constraint_violation(NORM_MAX));
    24522610      // Complementarity
    24532611      DBG_PRINT((1, "curr_complementarity(0., NORM_MAX) = %8.2e\n",
     
    24562614
    24572615      curr_nlp_error_cache_.AddCachedResult(result, tdeps);
     2616    }
     2617
     2618    return result;
     2619  }
     2620
     2621  Number
     2622  IpoptCalculatedQuantities::unscaled_curr_nlp_error()
     2623  {
     2624    DBG_START_METH("IpoptCalculatedQuantities::unscaled_curr_nlp_error()",
     2625                   dbg_verbosity);
     2626    DBG_ASSERT(initialize_called_);
     2627    Number result;
     2628
     2629    SmartPtr<const Vector> x = ip_data_->curr()->x();
     2630    SmartPtr<const Vector> s = ip_data_->curr()->s();
     2631    SmartPtr<const Vector> y_c = ip_data_->curr()->y_c();
     2632    SmartPtr<const Vector> y_d = ip_data_->curr()->y_d();
     2633    SmartPtr<const Vector> z_L = ip_data_->curr()->z_L();
     2634    SmartPtr<const Vector> z_U = ip_data_->curr()->z_U();
     2635    SmartPtr<const Vector> v_L = ip_data_->curr()->v_L();
     2636    SmartPtr<const Vector> v_U = ip_data_->curr()->v_U();
     2637
     2638    std::vector<const TaggedObject*> tdeps(8);
     2639    tdeps[0] = GetRawPtr(x);
     2640    tdeps[1] = GetRawPtr(s);
     2641    tdeps[2] = GetRawPtr(y_c);
     2642    tdeps[3] = GetRawPtr(y_d);
     2643    tdeps[4] = GetRawPtr(z_L);
     2644    tdeps[5] = GetRawPtr(z_U);
     2645    tdeps[6] = GetRawPtr(v_L);
     2646    tdeps[7] = GetRawPtr(v_U);
     2647
     2648    if (!unscaled_curr_nlp_error_cache_.GetCachedResult(result, tdeps)) {
     2649
     2650      // Dual infeasibility
     2651      result = unscaled_curr_dual_infeasibility(NORM_MAX);
     2652      // Constraint violation
     2653      result = Max(result, unscaled_curr_nlp_constraint_violation(NORM_MAX));
     2654      // Complementarity (ToDo use unscaled?)
     2655      DBG_PRINT((1, "curr_complementarity(0., NORM_MAX) = %8.2e\n",
     2656                 curr_complementarity(0., NORM_MAX)));
     2657      result = Max(result, unscaled_curr_complementarity(0., NORM_MAX));
     2658
     2659      unscaled_curr_nlp_error_cache_.AddCachedResult(result, tdeps);
    24582660    }
    24592661
  • branches/dev/Algorithm/IpIpoptCalculatedQuantities.hpp

    r407 r414  
    8181    /** Value of objective function (at trial point) */
    8282    Number trial_f();
     83    /** Unscaled value of the objective function (at the trial point) */
     84    Number unscaled_trial_f();
    8385    /** Gradient of objective function (at current point) */
    8486    SmartPtr<const Vector> curr_grad_f();
     
    177179     *  What type of norm is used depends on constr_viol_normtype */
    178180    Number trial_constraint_violation();
     181    /** Real constraint violation in a given norm (at current
     182     *  iterate).  This considers the inequality constraints without
     183     *  slacks. */
     184    Number curr_nlp_constraint_violation(ENormType NormType);
     185    /** Unscaled real constraint violation in a given norm (at current
     186     *  iterate).  This considers the inequality constraints without
     187     *  slacks. */
     188    Number unscaled_curr_nlp_constraint_violation(ENormType NormType);
    179189    //@}
    180190
     
    238248    /** Dual infeasibility in a given norm (at trial iterate) */
    239249    Number trial_dual_infeasibility(ENormType NormType);
     250    /** Unscaled dual infeasibility in a given norm (at current iterate) */
     251    Number unscaled_curr_dual_infeasibility(ENormType NormType);
    240252
    241253    /** Complementarity (for all complementarity conditions together)
     
    245257     *  in a given norm (at trial iterate) */
    246258    Number trial_complementarity(Number mu, ENormType NormType);
     259    /** Complementarity (for all complementarity conditions together)
     260     *  in a given norm (at current iterate) without NLP scaling. */
     261    Number unscaled_curr_complementarity(Number mu, ENormType NormType);
    247262
    248263    /** Centrality measure (in spirit of the -infinity-neighborhood. */
     
    254269    Number curr_centrality_measure();
    255270
    256     /** Scaled total optimality error for the original NLP at the
    257      *  current iterate. */
     271    /** Total optimality error for the original NLP at the current
     272     *  iterate, using scaling factors based on multipliers.  Note
     273     *  that here the constraint violation is measured without slacks
     274     *  (nlp_constraint_violation) */
    258275    Number curr_nlp_error();
    259 
    260     /** Scaled total optimality error for the barrier problem at the
    261      *  current iterate. */
     276    /** Total optimality error for the original NLP at the current
     277     *  iterate, but using no scaling based on multipliers, and no
     278     *  scaling for the NLP.  Note that here the constraint violation
     279     *  is measured without slacks (nlp_constraint_violation) */
     280    Number unscaled_curr_nlp_error();
     281
     282    /** Total optimality error for the barrier problem at the
     283     *  current iterate, using scaling factors based on multipliers. */
    262284    Number curr_barrier_error();
    263285
     
    448470    CachedResults<Number> curr_constraint_violation_cache_;
    449471    CachedResults<Number> trial_constraint_violation_cache_;
     472    CachedResults<Number> curr_nlp_constraint_violation_cache_;
     473    CachedResults<Number> unscaled_curr_nlp_constraint_violation_cache_;
    450474    //@}
    451475
     
    477501    CachedResults<Number> curr_dual_infeasibility_cache_;
    478502    CachedResults<Number> trial_dual_infeasibility_cache_;
     503    CachedResults<Number> unscaled_curr_dual_infeasibility_cache_;
    479504    CachedResults<Number> curr_complementarity_cache_;
    480505    CachedResults<Number> trial_complementarity_cache_;
    481506    CachedResults<Number> curr_centrality_measure_cache_;
    482507    CachedResults<Number> curr_nlp_error_cache_;
     508    CachedResults<Number> unscaled_curr_nlp_error_cache_;
    483509    CachedResults<Number> curr_barrier_error_cache_;
    484510    CachedResults<Number> curr_primal_dual_system_error_cache_;
  • branches/dev/Algorithm/IpIpoptData.cpp

    r365 r414  
    100100      bool want_y_d,
    101101      bool want_z_L,
    102       bool want_z_U,
    103       bool want_v_L,
    104       bool want_v_U)
     102      bool want_z_U)
    105103  {
    106104    DBG_ASSERT(initialize_called_);
     
    126124                                  new_z_L, want_z_L,
    127125                                  new_z_U, want_z_U,
    128                                   new_v_L, want_v_L,
    129                                   new_v_U, want_v_U);
     126                                  new_v_L, new_v_U);
    130127    if (!retValue) {
    131128      return false;
     
    133130
    134131    new_s = new_y_d->MakeNew(); // same dimension as d
    135     /*
    136     new_s ->Set(0.0); // we set it here so that in
    137         // WarmStartIterateInitializer we can use
    138         // MakeNewIteratesVector
    139         */
    140132
    141133    iterates_space_ = new IteratesVectorSpace(*(new_x->OwnerSpace()), *(new_s->OwnerSpace()),
  • branches/dev/Algorithm/IpIpoptData.hpp

    r321 r414  
    5454                                  bool want_y_d,
    5555                                  bool want_z_L,
    56                                   bool want_z_U,
    57                                   bool want_v_L,
    58                                   bool want_v_U);
     56                                  bool want_z_U);
    5957
    6058    /** This method must be called to initialize the global
  • branches/dev/Algorithm/IpIpoptNLP.hpp

    r387 r414  
    7373                                      bool init_z_U,
    7474                                      SmartPtr<Vector>& v_L,
    75                                       bool init_v_L,
    76                                       SmartPtr<Vector>& v_U,
    77                                       bool init_v_U
     75                                      SmartPtr<Vector>& v_U
    7876                                     ) = 0;
    7977
     
    8381    virtual Number f(const Vector& x) = 0;
    8482
    85     /** Unscaled objective value */
    86     virtual Number unscaled_f(const Vector& x) = 0;
    87 
    8883    /** Gradient of the objective */
    8984    virtual SmartPtr<const Vector> grad_f(const Vector& x) = 0;
     
    9186    /** Equality constraint residual */
    9287    virtual SmartPtr<const Vector> c(const Vector& x) = 0;
    93 
    94     /** Unscaled Equality constraint residual */
    95     virtual SmartPtr<const Vector> unscaled_c(const Vector& x) = 0;
    9688
    9789    /** Jacobian Matrix for equality constraints */
     
    10193     *  as equalities with slacks */
    10294    virtual SmartPtr<const Vector> d(const Vector& x) = 0;
    103 
    104     /** Unscaled Inequality constraint residual (reformulated
    105      *  as equalities with slacks */
    106     virtual SmartPtr<const Vector> unscaled_d(const Vector& x) = 0;
    10795
    10896    /** Jacobian Matrix for inequality constraints */
     
    224212    //@}
    225213
    226   protected:
    227     /** Returns the scaling strategy object - may be NULL */
     214    /** Returns the scaling strategy object */
    228215    SmartPtr<NLPScalingObject> NLP_scaling() const
    229216    {
  • branches/dev/Algorithm/IpNLPScaling.cpp

    r396 r414  
    1414  DBG_SET_VERBOSITY(0);
    1515
    16   SmartPtr<Vector> NLPScalingObject::apply_vector_scaling_x_L_NonConst(
    17     SmartPtr<Matrix> Px_L,
    18     const SmartPtr<const Vector>& l,
    19     const SmartPtr<const VectorSpace> x_space)
    20   {
    21     SmartPtr<Vector> tmp_x = x_space->MakeNew();
    22 
    23     // move to full x space
    24     Px_L->MultVector(1.0, *l, 0.0, *tmp_x);
    25 
    26     // scale in full x space
    27     tmp_x = apply_vector_scaling_x_NonConst(ConstPtr(tmp_x));
    28 
    29     // move back to x_L space
    30     SmartPtr<Vector> scaled_x_L = l->MakeNew();
    31     Px_L->TransMultVector(1.0, *tmp_x, 0.0, *scaled_x_L);
    32 
    33     return scaled_x_L;
    34   }
    35 
    36   SmartPtr<Vector> NLPScalingObject::apply_vector_scaling_x_U_NonConst(
    37     SmartPtr<Matrix> Px_U,
    38     const SmartPtr<const Vector>& u,
    39     const SmartPtr<const VectorSpace> x_space)
    40   {
    41     SmartPtr<Vector> tmp_x = x_space->MakeNew();
    42 
    43     // move to full x space
    44     Px_U->MultVector(1.0, *u, 0.0, *tmp_x);
    45 
    46     // scale in full x space
    47     tmp_x = apply_vector_scaling_x_NonConst(ConstPtr(tmp_x));
    48 
    49     // move back to x_L space
    50     SmartPtr<Vector> scaled_x_U = u->MakeNew();
    51     Px_U->TransMultVector(1.0, *tmp_x, 0.0, *scaled_x_U);
    52 
    53     return scaled_x_U;
    54   }
    55 
    56   SmartPtr<Vector> NLPScalingObject::apply_vector_scaling_d_L_NonConst(
    57     SmartPtr<Matrix> Pd_L,
    58     const SmartPtr<const Vector>& l,
    59     const SmartPtr<const VectorSpace> d_space)
    60   {
    61     SmartPtr<Vector> tmp_d = d_space->MakeNew();
    62 
    63     // move to full d space
    64     Pd_L->MultVector(1.0, *l, 0.0, *tmp_d);
    65 
    66     // scale in full d space
    67     tmp_d = apply_vector_scaling_d_NonConst(ConstPtr(tmp_d));
    68 
    69     // move back to d_L space
    70     SmartPtr<Vector> scaled_d_L = l->MakeNew();
    71     Pd_L->TransMultVector(1.0, *tmp_d, 0.0, *scaled_d_L);
    72 
    73     return scaled_d_L;
    74   }
    75 
    76   SmartPtr<Vector> NLPScalingObject::apply_vector_scaling_d_U_NonConst(
    77     SmartPtr<Matrix> Pd_U,
    78     const SmartPtr<const Vector>& u,
    79     const SmartPtr<const VectorSpace> d_space)
    80   {
    81     SmartPtr<Vector> tmp_d = d_space->MakeNew();
    82 
    83     // move to full d space
    84     Pd_U->MultVector(1.0, *u, 0.0, *tmp_d);
    85 
    86     // scale in full d space
    87     tmp_d = apply_vector_scaling_d_NonConst(ConstPtr(tmp_d));
    88 
    89     // move back to d_L space
    90     SmartPtr<Vector> scaled_d_U = u->MakeNew();
    91     Pd_U->TransMultVector(1.0, *tmp_d, 0.0, *scaled_d_U);
    92 
    93     return scaled_d_U;
     16  SmartPtr<Vector> NLPScalingObject::apply_vector_scaling_x_LU_NonConst(
     17    const Matrix& Px_LU,
     18    const SmartPtr<const Vector>& lu,
     19    const VectorSpace& x_space)
     20  {
     21    SmartPtr<Vector> scaled_x_LU = lu->MakeNew();
     22    if (have_x_scaling()) {
     23      SmartPtr<Vector> tmp_x = x_space.MakeNew();
     24
     25      // move to full x space
     26      Px_LU.MultVector(1.0, *lu, 0.0, *tmp_x);
     27
     28      // scale in full x space
     29      tmp_x = apply_vector_scaling_x_NonConst(ConstPtr(tmp_x));
     30
     31      // move back to x_L space
     32      Px_LU.TransMultVector(1.0, *tmp_x, 0.0, *scaled_x_LU);
     33    }
     34    else {
     35      scaled_x_LU->Copy(*lu);
     36    }
     37
     38    return scaled_x_LU;
     39  }
     40
     41  SmartPtr<const Vector> NLPScalingObject::apply_vector_scaling_x_LU(
     42    const Matrix& Px_LU,
     43    const SmartPtr<const Vector>& lu,
     44    const VectorSpace& x_space)
     45  {
     46    if (have_x_scaling()) {
     47      return ConstPtr(apply_vector_scaling_x_LU_NonConst(Px_LU, lu, x_space));
     48    }
     49    else {
     50      return lu;
     51    }
     52  }
     53
     54  SmartPtr<Vector> NLPScalingObject::apply_vector_scaling_d_LU_NonConst(
     55    const Matrix& Pd_LU,
     56    const SmartPtr<const Vector>& lu,
     57    const VectorSpace& d_space)
     58  {
     59    SmartPtr<Vector> scaled_d_LU = lu->MakeNew();
     60    if (have_d_scaling()) {
     61      SmartPtr<Vector> tmp_d = d_space.MakeNew();
     62
     63      // move to full d space
     64      Pd_LU.MultVector(1.0, *lu, 0.0, *tmp_d);
     65
     66      // scale in full x space
     67      tmp_d = apply_vector_scaling_d_NonConst(ConstPtr(tmp_d));
     68
     69      // move back to x_L space
     70      Pd_LU.TransMultVector(1.0, *tmp_d, 0.0, *scaled_d_LU);
     71    }
     72    else {
     73      scaled_d_LU->Copy(*lu);
     74    }
     75
     76    return scaled_d_LU;
     77  }
     78
     79  SmartPtr<const Vector> NLPScalingObject::apply_vector_scaling_d_LU(
     80    const Matrix& Pd_LU,
     81    const SmartPtr<const Vector>& lu,
     82    const VectorSpace& d_space)
     83  {
     84    if (have_d_scaling()) {
     85      return ConstPtr(apply_vector_scaling_d_LU_NonConst(Pd_LU, lu, d_space));
     86    }
     87    else {
     88      return lu;
     89    }
     90  }
     91
     92  SmartPtr<Vector> NLPScalingObject::unapply_vector_scaling_d_LU_NonConst(
     93    const Matrix& Pd_LU,
     94    const SmartPtr<const Vector>& lu,
     95    const VectorSpace& d_space)
     96  {
     97    SmartPtr<Vector> unscaled_d_LU = lu->MakeNew();
     98    if (have_d_scaling()) {
     99      SmartPtr<Vector> tmp_d = d_space.MakeNew();
     100
     101      // move to full d space
     102      Pd_LU.MultVector(1.0, *lu, 0.0, *tmp_d);
     103
     104      // scale in full x space
     105      tmp_d = unapply_vector_scaling_d_NonConst(ConstPtr(tmp_d));
     106
     107      // move back to x_L space
     108      Pd_LU.TransMultVector(1.0, *tmp_d, 0.0, *unscaled_d_LU);
     109    }
     110    else {
     111      unscaled_d_LU->Copy(*lu);
     112    }
     113
     114    return unscaled_d_LU;
     115  }
     116
     117  SmartPtr<const Vector> NLPScalingObject::unapply_vector_scaling_d_LU(
     118    const Matrix& Pd_LU,
     119    const SmartPtr<const Vector>& lu,
     120    const VectorSpace& d_space)
     121  {
     122    if (have_d_scaling()) {
     123      return ConstPtr(unapply_vector_scaling_d_LU_NonConst(Pd_LU, lu, d_space));
     124    }
     125    else {
     126      return lu;
     127    }
    94128  }
    95129
     
    123157  {
    124158    SmartPtr<Vector> unscaled_v = apply_vector_scaling_x_NonConst(v);
    125     Number df = unapply_obj_scaling(1.0);
     159    Number df = unapply_obj_scaling(1.);
    126160    if (df != 1.) {
    127161      unscaled_v->Scal(df);
     
    133167    const SmartPtr<const Vector>& v)
    134168  {
    135     Number df = unapply_obj_scaling(1.0);
     169    Number df = unapply_obj_scaling(1.);
    136170    if (df != 1.) {
    137171      SmartPtr<Vector> unscaled_v = unapply_grad_obj_scaling_NonConst(v);
     
    416450  }
    417451
     452  // ToDo: matrix not passed by reference, so setting to NULL doesn't make difference
    418453  SmartPtr<const Matrix> StandardScalingBase::apply_jac_c_scaling(
    419454    SmartPtr<const Matrix> matrix)
     
    459494      return ret;
    460495    }
     496  }
     497
     498  bool StandardScalingBase::have_x_scaling()
     499  {
     500    return IsValid(dx_);
     501  }
     502
     503  bool StandardScalingBase::have_c_scaling()
     504  {
     505    return (IsValid(scaled_jac_c_space_) &&
     506            IsValid(scaled_jac_c_space_->RowScaling()));
     507  }
     508
     509  bool StandardScalingBase::have_d_scaling()
     510  {
     511    return (IsValid(scaled_jac_d_space_) &&
     512            IsValid(scaled_jac_d_space_->RowScaling()));
    461513  }
    462514
  • branches/dev/Algorithm/IpNLPScaling.hpp

    r396 r414  
    112112    /** Methods for scaling bounds - these wrap those above */
    113113    //@{
    114     /** Returns an x-scaled vector in the x_L space */
    115     SmartPtr<Vector> apply_vector_scaling_x_L_NonConst(
    116       SmartPtr<Matrix> Px_L,
    117       const SmartPtr<const Vector>& l,
    118       const SmartPtr<const VectorSpace> x_space);
    119     /** Returns an x-scaled vector in the x_U space */
    120     SmartPtr<Vector> apply_vector_scaling_x_U_NonConst(
    121       SmartPtr<Matrix> Px_U,
    122       const SmartPtr<const Vector>& u,
    123       const SmartPtr<const VectorSpace> x_space);
    124     /** Returns an d-scaled vector in the d_L space */
    125     SmartPtr<Vector> apply_vector_scaling_d_L_NonConst(
    126       SmartPtr<Matrix> Pd_L,
    127       const SmartPtr<const Vector>& l,
    128       const SmartPtr<const VectorSpace> d_space);
    129     /** Returns an d-scaled vector in the d_U space */
    130     SmartPtr<Vector> apply_vector_scaling_d_U_NonConst(
    131       SmartPtr<Matrix> Pd_U,
    132       const SmartPtr<const Vector>& u,
    133       const SmartPtr<const VectorSpace> d_space);
     114    /** Returns an x-scaled vector in the x_L or x_U space */
     115    SmartPtr<Vector> apply_vector_scaling_x_LU_NonConst(
     116      const Matrix& Px_LU,
     117      const SmartPtr<const Vector>& lu,
     118      const VectorSpace& x_space);
     119    /** Returns an x-scaled vector in the x_L or x_U space */
     120    SmartPtr<const Vector> apply_vector_scaling_x_LU(
     121      const Matrix& Px_LU,
     122      const SmartPtr<const Vector>& lu,
     123      const VectorSpace& x_space);
     124    /** Returns an d-scaled vector in the d_L or d_U space */
     125    SmartPtr<Vector> apply_vector_scaling_d_LU_NonConst(
     126      const Matrix& Pd_LU,
     127      const SmartPtr<const Vector>& lu,
     128      const VectorSpace& d_space);
     129    /** Returns an d-scaled vector in the d_L or d_U space */
     130    SmartPtr<const Vector> apply_vector_scaling_d_LU(
     131      const Matrix& Pd_LU,
     132      const SmartPtr<const Vector>& lu,
     133      const VectorSpace& d_space);
     134    /** Returns an d-unscaled vector in the d_L or d_U space */
     135    SmartPtr<Vector> unapply_vector_scaling_d_LU_NonConst(
     136      const Matrix& Pd_LU,
     137      const SmartPtr<const Vector>& lu,
     138      const VectorSpace& d_space);
     139    /** Returns an d-unscaled vector in the d_L or d_U space */
     140    SmartPtr<const Vector> unapply_vector_scaling_d_LU(
     141      const Matrix& Pd_LU,
     142      const SmartPtr<const Vector>& lu,
     143      const VectorSpace& d_space);
    134144    //@}
    135145
     
    152162    virtual SmartPtr<const Vector>
    153163    unapply_grad_obj_scaling(const SmartPtr<const Vector>& v);
     164    //@}
     165
     166    /** @name Methods for determining whether scaling for entities is
     167     *  done */
     168    //@{
     169    /** Returns true if the primal x variables are scaled. */
     170    virtual bool have_x_scaling()=0;
     171    /** Returns true if the equality constraints are scaled. */
     172    virtual bool have_c_scaling()=0;
     173    /** Returns true if the inequality constraints are scaled. */
     174    virtual bool have_d_scaling()=0;
    154175    //@}
    155176
     
    277298    virtual SmartPtr<const SymMatrix>
    278299    apply_hessian_scaling(SmartPtr<const SymMatrix> matrix);
     300    //@}
     301
     302    /** @name Methods for determining whether scaling for entities is
     303     *  done */
     304    //@{
     305    virtual bool have_x_scaling();
     306    virtual bool have_c_scaling();
     307    virtual bool have_d_scaling();
    279308    //@}
    280309
  • branches/dev/Algorithm/IpOrigIpoptNLP.cpp

    r410 r414  
    8585                                          bool init_z_U,
    8686                                          SmartPtr<Vector>& v_L,
    87                                           bool init_v_L,
    88                                           SmartPtr<Vector>& v_U,
    89                                           bool init_v_U
     87                                          SmartPtr<Vector>& v_U
    9088                                         )
    9189  {
     
    130128
    131129    // Create the bounds structures
    132     x_L_ = x_l_space_->MakeNew();
    133     Px_L_ = px_l_space_->MakeNew();
    134     x_U_ = x_u_space_->MakeNew();
    135     Px_U_ = px_u_space_->MakeNew();
    136     d_L_ = d_l_space_->MakeNew();
    137     Pd_L_ = pd_l_space_->MakeNew();
    138     d_U_ = d_u_space_->MakeNew();
    139     Pd_U_ = pd_u_space_->MakeNew();
    140 
    141     retValue = nlp_->GetBoundsInformation(*Px_L_, *x_L_, *Px_U_, *x_U_,
    142                                           *Pd_L_, *d_L_, *Pd_U_, *d_U_);
     130    SmartPtr<Vector> x_L = x_l_space_->MakeNew();
     131    SmartPtr<Matrix> Px_L = px_l_space_->MakeNew();
     132    SmartPtr<Vector> x_U = x_u_space_->MakeNew();
     133    SmartPtr<Matrix> Px_U = px_u_space_->MakeNew();
     134    SmartPtr<Vector> d_L = d_l_space_->MakeNew();
     135    SmartPtr<Matrix> Pd_L = pd_l_space_->MakeNew();
     136    SmartPtr<Vector> d_U = d_u_space_->MakeNew();
     137    SmartPtr<Matrix> Pd_U = pd_u_space_->MakeNew();
     138
     139    retValue = nlp_->GetBoundsInformation(*Px_L, *x_L, *Px_U, *x_U,
     140                                          *Pd_L, *d_L, *Pd_U, *d_U);
    143141
    144142    if (!retValue) {
     
    146144    }
    147145
    148     relax_bounds(-bound_relax_factor_, *x_L_);
    149     relax_bounds( bound_relax_factor_, *x_U_);
    150     relax_bounds(-bound_relax_factor_, *d_L_);
    151     relax_bounds( bound_relax_factor_, *d_U_);
     146    relax_bounds(-bound_relax_factor_, *x_L);
     147    relax_bounds( bound_relax_factor_, *x_U);
     148    relax_bounds(-bound_relax_factor_, *d_L);
     149    relax_bounds( bound_relax_factor_, *d_U);
     150
     151    x_L_ = ConstPtr(x_L);
     152    Px_L_ = ConstPtr(Px_L);
     153    x_U_ = ConstPtr(x_U);
     154    Px_U_ = ConstPtr(Px_U);
     155    d_L_ = ConstPtr(d_L);
     156    Pd_L_ = ConstPtr(Pd_L);
     157    d_U_ = ConstPtr(d_U);
     158    Pd_U_ = ConstPtr(Pd_U);
    152159
    153160    // now create and store the scaled bounds
    154     x_L_ = NLP_scaling()->apply_vector_scaling_x_L_NonConst(Px_L_, ConstPtr(x_L_), x_space_);
    155     x_U_ = NLP_scaling()->apply_vector_scaling_x_U_NonConst(Px_U_, ConstPtr(x_U_), x_space_);
    156     d_L_ = NLP_scaling()->apply_vector_scaling_d_L_NonConst(Pd_L_, ConstPtr(d_L_), d_space_);
    157     d_U_ = NLP_scaling()->apply_vector_scaling_d_U_NonConst(Pd_U_, ConstPtr(d_U_), d_space_);
     161    x_L_ = NLP_scaling()->apply_vector_scaling_x_LU(*Px_L_, x_L_, *x_space_);
     162    x_U_ = NLP_scaling()->apply_vector_scaling_x_LU(*Px_U_, x_U_, *x_space_);
     163    d_L_ = NLP_scaling()->apply_vector_scaling_d_LU(*Pd_L_, d_L_, *d_space_);
     164    d_U_ = NLP_scaling()->apply_vector_scaling_d_LU(*Pd_U_, d_U_, *d_space_);
    158165
    159166    // Create the iterates structures
     
    170177                                      GetRawPtr(y_d), init_y_d,
    171178                                      GetRawPtr(z_L), init_z_L,
    172                                       GetRawPtr(z_U), init_z_U,
    173                                       GetRawPtr(v_L), init_v_L,
    174                                       GetRawPtr(v_U), init_v_U);
     179                                      GetRawPtr(z_U), init_z_U);
    175180
    176181    if (!retValue) {
     
    178183    }
    179184
     185    Number obj_scal = NLP_scaling()->apply_obj_scaling(1.);
    180186    if (init_x) {
    181       x = NLP_scaling()->apply_vector_scaling_x_NonConst(ConstPtr(x));
     187      if (NLP_scaling()->have_x_scaling()) {
     188        x = NLP_scaling()->apply_vector_scaling_x_NonConst(ConstPtr(x));
     189      }
    182190    }
    183191    if (init_y_c) {
    184       y_c = NLP_scaling()->apply_vector_scaling_c_NonConst(ConstPtr(y_c));
     192      if (NLP_scaling()->have_c_scaling()) {
     193        y_c = NLP_scaling()->unapply_vector_scaling_c_NonConst(ConstPtr(y_c));
     194      }
     195      if (obj_scal!=1.) {
     196        y_c->Scal(obj_scal);
     197      }
    185198    }
    186199    if (init_y_d) {
    187       y_d = NLP_scaling()->apply_vector_scaling_d_NonConst(ConstPtr(y_d));
     200      if (NLP_scaling()->have_d_scaling()) {
     201        y_d = NLP_scaling()->unapply_vector_scaling_d_NonConst(ConstPtr(y_d));
     202      }
     203      if (obj_scal!=1.) {
     204        y_d->Scal(obj_scal);
     205      }
    188206    }
    189207    if (init_z_L) {
    190       z_L = NLP_scaling()->apply_vector_scaling_x_L_NonConst(Px_L_, ConstPtr(z_L), x_space_);
     208      if (NLP_scaling()->have_x_scaling()) {
     209        z_L = NLP_scaling()->apply_vector_scaling_x_LU_NonConst(*Px_L_, ConstPtr(z_L), *x_space_);
     210      }
     211      if (obj_scal!=1.) {
     212        z_L->Scal(obj_scal);
     213      }
    191214    }
    192215    if (init_z_U) {
    193       z_U = NLP_scaling()->apply_vector_scaling_x_U_NonConst(Px_U_, ConstPtr(z_U), x_space_);
    194     }
    195     if (init_v_L) {
    196       v_L = NLP_scaling()->apply_vector_scaling_d_L_NonConst(Pd_L_, ConstPtr(v_L), d_space_);
    197     }
    198     if (init_v_U) {
    199       v_U = NLP_scaling()->apply_vector_scaling_d_U_NonConst(Pd_U_, ConstPtr(v_U), d_space_);
     216      if (NLP_scaling()->have_x_scaling()) {
     217        z_U = NLP_scaling()->apply_vector_scaling_x_LU_NonConst(*Px_U_, ConstPtr(z_U), *x_space_);
     218      }
     219      if (obj_scal!=1.) {
     220        z_U->Scal(obj_scal);
     221      }
    200222    }
    201223
     
    240262  }
    241263
    242   Number OrigIpoptNLP::unscaled_f(const Vector& x)
    243   {
    244     DBG_START_METH("OrigIpoptNLP::unscaled_f", dbg_verbosity);
    245     Number ret = 0.0;
    246     Number scaled_f = 0.0;
    247     DBG_PRINT((1, "x.Tag = %d\n", x.GetTag()));
    248     if (f_cache_.GetCachedResult1Dep(scaled_f, &x)) {
    249       // unscale the cached objective
    250       ret = NLP_scaling()->unapply_obj_scaling(scaled_f);
    251     }
    252     else {
    253       f_evals_++;
    254       SmartPtr<const Vector> unscaled_x = NLP_scaling()->unapply_vector_scaling_x(&x);
    255       bool success = nlp_->Eval_f(*unscaled_x, ret);
    256       ASSERT_EXCEPTION(success && FiniteNumber(ret), Eval_Error,
    257                        "Error evaluating the objective function");
    258       scaled_f = NLP_scaling()->apply_obj_scaling(ret);
    259       f_cache_.AddCachedResult1Dep(scaled_f, &x);
    260     }
    261 
    262     return ret;
    263   }
    264 
    265264  SmartPtr<const Vector> OrigIpoptNLP::grad_f(const Vector& x)
    266265  {
     
    282281  }
    283282
    284 
    285283  /** Equality constraint residual */
    286284  SmartPtr<const Vector> OrigIpoptNLP::c(const Vector& x)
     
    297295      retValue = NLP_scaling()->apply_vector_scaling_c(ConstPtr(unscaled_c));
    298296      c_cache_.AddCachedResult1Dep(retValue, &x);
    299     }
    300 
    301     return retValue;
    302   }
    303 
    304   SmartPtr<const Vector> OrigIpoptNLP::unscaled_c(const Vector& x)
    305   {
    306     SmartPtr<Vector> unscaled_c;
    307     SmartPtr<const Vector> scaled_c;
    308     SmartPtr<const Vector> retValue;
    309     if (c_cache_.GetCachedResult1Dep(scaled_c, &x)) {
    310       // return the unscaled version
    311       retValue = NLP_scaling()->unapply_vector_scaling_c(scaled_c);
    312     }
    313     else {
    314       c_evals_++;
    315       unscaled_c = c_space_->MakeNew();
    316       SmartPtr<const Vector> unscaled_x = NLP_scaling()->unapply_vector_scaling_x(&x);
    317       bool success = nlp_->Eval_c(*unscaled_x, *unscaled_c);
    318       ASSERT_EXCEPTION(success && FiniteNumber(unscaled_c->Nrm2()),
    319                        Eval_Error, "Error evaluating the equality constraints");
    320       scaled_c = NLP_scaling()->apply_vector_scaling_c(ConstPtr(unscaled_c));
    321       c_cache_.AddCachedResult1Dep(scaled_c, &x);
    322       retValue = ConstPtr(unscaled_c);
    323297    }
    324298
     
    343317      retValue = NLP_scaling()->apply_vector_scaling_d(ConstPtr(unscaled_d));
    344318      d_cache_.AddCachedResult1Dep(retValue, &x);
    345     }
    346 
    347     return retValue;
    348   }
    349 
    350   SmartPtr<const Vector> OrigIpoptNLP::unscaled_d(const Vector& x)
    351   {
    352     DBG_START_METH("OrigIpoptNLP::d", dbg_verbosity);
    353     SmartPtr<Vector> unscaled_d;
    354     SmartPtr<const Vector> scaled_d;
    355     SmartPtr<const Vector> retValue;
    356     if (d_cache_.GetCachedResult1Dep(scaled_d, &x)) {
    357       // unscale the result
    358       retValue = NLP_scaling()->unapply_vector_scaling_d(scaled_d);
    359     }
    360     else {
    361       d_evals_++;
    362       unscaled_d = d_space_->MakeNew();
    363 
    364       DBG_PRINT_VECTOR(2, "scaled_x", x);
    365       SmartPtr<const Vector> unscaled_x = NLP_scaling()->unapply_vector_scaling_x(&x);
    366       bool success = nlp_->Eval_d(*unscaled_x, *unscaled_d);
    367       DBG_PRINT_VECTOR(2, "unscaled_d", *unscaled_d);
    368       ASSERT_EXCEPTION(success && FiniteNumber(unscaled_d->Nrm2()),
    369                        Eval_Error, "Error evaluating the inequality constraints");
    370       scaled_d = NLP_scaling()->apply_vector_scaling_d(ConstPtr(unscaled_d));
    371       d_cache_.AddCachedResult1Dep(scaled_d, &x);
    372       retValue = ConstPtr(unscaled_d);
    373319    }
    374320
     
    499445  {
    500446    // need to submit the unscaled solution back to the nlp
    501     SmartPtr<const Vector> unscaled_x = NLP_scaling()->unapply_vector_scaling_x(&x);
    502     SmartPtr<Vector> unscaled_z_L = NLP_scaling()->apply_vector_scaling_x_L_NonConst(Px_L_, &z_L, x_space_);
    503     SmartPtr<Vector> unscaled_z_U = NLP_scaling()->apply_vector_scaling_x_U_NonConst(Px_U_, &z_U, x_space_);
    504     SmartPtr<const Vector> unscaled_c = NLP_scaling()->unapply_vector_scaling_c(&c);
    505     SmartPtr<const Vector> unscaled_d = NLP_scaling()->unapply_vector_scaling_d(&d);
    506     SmartPtr<const Vector> unscaled_y_c = NLP_scaling()->apply_vector_scaling_c(&y_c);
    507     SmartPtr<const Vector> unscaled_y_d = NLP_scaling()->apply_vector_scaling_d(&y_d);
     447    SmartPtr<const Vector> unscaled_x =
     448      NLP_scaling()->unapply_vector_scaling_x(&x);
     449    SmartPtr<const Vector> unscaled_c =
     450      NLP_scaling()->unapply_vector_scaling_c(&c);
     451    SmartPtr<const Vector> unscaled_d =
     452      NLP_scaling()->unapply_vector_scaling_d(&d);
    508453    const Number unscaled_obj = NLP_scaling()->unapply_obj_scaling(obj_value);
     454
     455    SmartPtr<const Vector> unscaled_z_L;
     456    SmartPtr<const Vector> unscaled_z_U;
     457    SmartPtr<const Vector> unscaled_y_c;
     458    SmartPtr<const Vector> unscaled_y_d;
     459
     460    // The objective function scaling factor also appears in the constraints
     461    Number obj_unscale_factor = NLP_scaling()->unapply_obj_scaling(1.);
     462    if (obj_unscale_factor!=1.) {
     463      SmartPtr<Vector> tmp = NLP_scaling()->apply_vector_scaling_x_LU_NonConst(*Px_L_, &z_L, *x_space_);
     464      tmp->Scal(obj_unscale_factor);
     465      unscaled_z_L = ConstPtr(tmp);
     466
     467      tmp = NLP_scaling()->apply_vector_scaling_x_LU_NonConst(*Px_U_, &z_U, *x_space_);
     468      tmp->Scal(obj_unscale_factor);
     469      unscaled_z_U = ConstPtr(tmp);
     470
     471      tmp = NLP_scaling()->apply_vector_scaling_c_NonConst(&y_c);
     472      tmp->Scal(obj_unscale_factor);
     473      unscaled_y_c = ConstPtr(tmp);
     474
     475      tmp = NLP_scaling()->apply_vector_scaling_d_NonConst(&y_d);
     476      tmp->Scal(obj_unscale_factor);
     477      unscaled_y_d = ConstPtr(tmp);
     478    }
     479    else {
     480      unscaled_z_L = NLP_scaling()->apply_vector_scaling_x_LU(*Px_L_, &z_L, *x_space_);
     481      unscaled_z_U = NLP_scaling()->apply_vector_scaling_x_LU(*Px_U_, &z_U, *x_space_);
     482      unscaled_y_c = NLP_scaling()->apply_vector_scaling_c(&y_c);
     483      unscaled_y_d = NLP_scaling()->apply_vector_scaling_d(&y_d);
     484    }
    509485
    510486    nlp_->FinalizeSolution(status, *unscaled_x,
     
    518494                                          const Vector& new_d_L, const Vector& new_d_U)
    519495  {
    520     x_L_->Copy(new_x_L);
    521     x_U_->Copy(new_x_U);
    522     d_L_->Copy(new_d_L);
    523     d_U_->Copy(new_d_U);
     496    x_L_ = new_x_L.MakeNewCopy();
     497    x_U_ = new_x_U.MakeNewCopy();
     498    d_L_ = new_d_L.MakeNewCopy();
     499    d_U_ = new_d_U.MakeNewCopy();
    524500  }
    525501
  • branches/dev/Algorithm/IpOrigIpoptNLP.hpp

    r387 r414  
    1212#include "IpIpoptNLP.hpp"
    1313#include "IpException.hpp"
    14 #include"IpIpoptType.hpp"
     14#include "IpIpoptType.hpp"
    1515
    1616namespace Ipopt
     
    5656                                      bool init_z_U,
    5757                                      SmartPtr<Vector>& v_L,
    58                                       bool init_v_L,
    59                                       SmartPtr<Vector>& v_U,
    60                                       bool init_v_U
     58                                      SmartPtr<Vector>& v_U
    6159                                     );
    6260
     
    6664    virtual Number f(const Vector& x);
    6765
    68     /** Unscaled objective value */
    69     virtual Number unscaled_f(const Vector& x);
    70 
    7166    /** Gradient of the objective */
    7267    virtual SmartPtr<const Vector> grad_f(const Vector& x);
     
    7469    /** Equality constraint residual */
    7570    virtual SmartPtr<const Vector> c(const Vector& x);
    76 
    77     /** Unscaled Equality constraint residual */
    78     virtual SmartPtr<const Vector> unscaled_c(const Vector& x);
    7971
    8072    /** Jacobian Matrix for equality constraints */
     
    8476     *  as equalities with slacks */
    8577    virtual SmartPtr<const Vector> d(const Vector& x);
    86 
    87     /** Unscaled Inequality constraint residual (reformulated
    88      *  as equalities with slacks */
    89     virtual SmartPtr<const Vector> unscaled_d(const Vector& x);
    9078
    9179    /** Jacobian Matrix for inequality constraints*/
     
    10290    virtual SmartPtr<const Vector> x_L()
    10391    {
    104       return ConstPtr(x_L_);
     92      return x_L_;
    10593    }
    10694
     
    10896    virtual SmartPtr<const Matrix> Px_L()
    10997    {
    110       return ConstPtr(Px_L_);
     98      return Px_L_;
    11199    }
    112100
     
    114102    virtual SmartPtr<const Vector> x_U()
    115103    {
    116       return ConstPtr(x_U_);
     104      return x_U_;
    117105    }
    118106
     
    120108    virtual SmartPtr<const Matrix> Px_U()
    121109    {
    122       return ConstPtr(Px_U_);
     110      return Px_U_;
    123111    }
    124112
     
    126114    virtual SmartPtr<const Vector> d_L()
    127115    {
    128       return ConstPtr(d_L_);
     116      return d_L_;
    129117    }
    130118
     
    132120    virtual SmartPtr<const Matrix> Pd_L()
    133121    {
    134       return ConstPtr(Pd_L_);
     122      return Pd_L_;
    135123    }
    136124
     
    138126    virtual SmartPtr<const Vector> d_U()
    139127    {
    140       return ConstPtr(d_U_);
     128      return d_U_;
    141129    }
    142130
     
    144132    virtual SmartPtr<const Matrix> Pd_U()
    145133    {
    146       return ConstPtr(Pd_U_);
     134      return Pd_U_;
    147135    }
    148136    //@}
     
    274262
    275263    /** Lower bounds on x */
    276     SmartPtr<Vector> x_L_;
     264    SmartPtr<const Vector> x_L_;
    277265
    278266    /** Permutation matrix (x_L_ -> x) */
    279     SmartPtr<Matrix> Px_L_;
     267    SmartPtr<const Matrix> Px_L_;
    280268
    281269    /** Upper bounds on x */
    282     SmartPtr<Vector> x_U_;
     270    SmartPtr<const Vector> x_U_;
    283271
    284272    /** Permutation matrix (x_U_ -> x */
    285     SmartPtr<Matrix> Px_U_;
     273    SmartPtr<const Matrix> Px_U_;
    286274
    287275    /** Lower bounds on d */
    288     SmartPtr<Vector> d_L_;
     276    SmartPtr<const Vector> d_L_;
    289277
    290278    /** Permutation matrix (d_L_ -> d) */
    291     SmartPtr<Matrix> Pd_L_;
     279    SmartPtr<const Matrix> Pd_L_;
    292280
    293281    /** Upper bounds on d */
    294     SmartPtr<Vector> d_U_;
     282    SmartPtr<const Vector> d_U_;
    295283
    296284    /** Permutation matrix (d_U_ -> d */
    297     SmartPtr<Matrix> Pd_U_;
     285    SmartPtr<const Matrix> Pd_U_;
    298286    //@}
    299287
  • branches/dev/Algorithm/IpOrigIterationOutput.cpp

    r377 r414  
    199199                     "\n\n***Current NLP Values for Iteration %d:\n",
    200200                     IpData().iter_count());
    201       Jnlst().Printf(J_DETAILED, J_MAIN, "Objective = %.16e\n", IpCq().curr_f());
     201      Jnlst().Printf(J_DETAILED, J_MAIN, "\n                                   (scaled)                 (unscaled)\n");
     202      Jnlst().Printf(J_DETAILED, J_MAIN, "Objective...............: %24.16e  %24.16e\n", IpCq().curr_f(), IpCq().unscaled_curr_f());
     203      Jnlst().Printf(J_DETAILED, J_MAIN, "Dual infeasibility......: %24.16e  %24.16e\n", IpCq().curr_dual_infeasibility(NORM_MAX), IpCq().unscaled_curr_dual_infeasibility(NORM_MAX));
     204      Jnlst().Printf(J_DETAILED, J_MAIN, "Constraint violation....: %24.16e  %24.16e\n", IpCq().curr_nlp_constraint_violation(NORM_MAX), IpCq().unscaled_curr_nlp_constraint_violation(NORM_MAX));
     205      Jnlst().Printf(J_DETAILED, J_MAIN, "Complementarity.........: %24.16e  %24.16e\n", IpCq().curr_complementarity(0., NORM_MAX), IpCq().unscaled_curr_complementarity(0., NORM_MAX));
     206      Jnlst().Printf(J_DETAILED, J_MAIN, "Overall NLP error.......: %24.16e  %24.16e\n\n", IpCq().curr_nlp_error(), IpCq().unscaled_curr_nlp_error());
    202207    }
    203208    if (Jnlst().ProduceOutput(J_VECTOR, J_MAIN)) {
  • branches/dev/Algorithm/IpRestoIpoptNLP.cpp

    r343 r414  
    5858      bool init_z_U,
    5959      SmartPtr<Vector>& v_L,
    60       bool init_v_L,
    61       SmartPtr<Vector>& v_U,
    62       bool init_v_U
     60      SmartPtr<Vector>& v_U
    6361                                          )
    6462  {
  • branches/dev/Algorithm/IpRestoIpoptNLP.hpp

    r387 r414  
    6060                                      bool init_z_U,
    6161                                      SmartPtr<Vector>& v_L,
    62                                       bool init_v_L,
    63                                       SmartPtr<Vector>& v_U,
    64                                       bool init_v_U
     62                                      SmartPtr<Vector>& v_U
    6563                                     );
    6664
     
    9290    }
    9391
    94     /** Unscaled Objective value */
    95     virtual Number unscaled_f(const Vector& x)
    96     {
    97       return f(x);
    98     }
    99 
    10092    /** Objective value */
    10193    virtual Number f(const Vector& x, Number mu);
     
    113105    /** Equality constraint residual */
    114106    virtual SmartPtr<const Vector> c(const Vector& x);
    115 
    116     /** Unscaled equality constraint residual */
    117     virtual SmartPtr<const Vector> unscaled_c(const Vector& x)
    118     {
    119       return c(x);
    120     }
    121107
    122108    /** Jacobian Matrix for equality constraints */
     
    126112     *  as equalities with slacks */
    127113    virtual SmartPtr<const Vector> d(const Vector& x);
    128 
    129     /** Unscaled inequality constraint residual (reformulated
    130      *  as equalities with slacks */
    131     virtual SmartPtr<const Vector> unscaled_d(const Vector& x)
    132     {
    133       return d(x);
    134     }
    135114
    136115    /** Jacobian Matrix for inequality constraints */
  • branches/dev/Algorithm/IpRestoIterateInitializer.cpp

    r413 r414  
    7575    // initialize the data structures in the restoration phase NLP
    7676    IpData().InitializeDataStructures(IpNLP(), false, false, false,
    77                                       false, false, false, false);
     77                                      false, false);
    7878
    7979    SmartPtr<Vector> new_x = IpData().curr()->x()->MakeNew();
  • branches/dev/Algorithm/IpRestoIterationOutput.cpp

    r377 r414  
    107107    // Compute primal infeasibility
    108108    Number inf_pr = orig_ip_cq->trial_primal_infeasibility(NORM_MAX);
    109     Number f = orig_ip_cq->trial_f();
     109    Number f = orig_ip_cq->unscaled_trial_f();
    110110
    111111    // Retrieve some information set in the different parts of the algorithm
     
    243243                     "\n\n***Current NLP Values for Iteration (Restoration phase problem) %d:\n",
    244244                     IpData().iter_count());
    245       Jnlst().Printf(J_DETAILED, J_MAIN, "Objective = %.16e\n", IpCq().curr_f());
     245      Jnlst().Printf(J_DETAILED, J_MAIN, "\n                                   (scaled)                 (unscaled)\n");
     246      Jnlst().Printf(J_DETAILED, J_MAIN, "Objective...............: %24.16e  %24.16e\n", IpCq().curr_f(), IpCq().unscaled_curr_f());
     247      Jnlst().Printf(J_DETAILED, J_MAIN, "Dual infeasibility......: %24.16e  %24.16e\n", IpCq().curr_dual_infeasibility(NORM_MAX), IpCq().unscaled_curr_dual_infeasibility(NORM_MAX));
     248      Jnlst().Printf(J_DETAILED, J_MAIN, "Constraint violation....: %24.16e  %24.16e\n", IpCq().curr_nlp_constraint_violation(NORM_MAX), IpCq().unscaled_curr_nlp_constraint_violation(NORM_MAX));
     249      Jnlst().Printf(J_DETAILED, J_MAIN, "Complementarity.........: %24.16e  %24.16e\n", IpCq().curr_complementarity(0., NORM_MAX), IpCq().unscaled_curr_complementarity(0., NORM_MAX));
     250      Jnlst().Printf(J_DETAILED, J_MAIN, "Overall NLP error.......: %24.16e  %24.16e\n\n", IpCq().curr_nlp_error(), IpCq().unscaled_curr_nlp_error());
    246251    }
    247252    if (Jnlst().ProduceOutput(J_VECTOR, J_MAIN)) {
  • branches/dev/Algorithm/IpWarmStartIterateInitializer.cpp

    r390 r414  
    6868
    6969    // Get the intial values for x, y_c, y_d, z_L, z_U,
    70     IpData().InitializeDataStructures(IpNLP(), true, true, true,
    71                                       true, true, false, false);
     70    IpData().InitializeDataStructures(IpNLP(), true, true, true, true, true);
    7271
    7372    Jnlst().PrintVector(J_VECTOR, J_INITIALIZATION, "user-provided x",
  • branches/dev/Apps/StdInterface/IpIpoptApplication.cpp

    r388 r414  
    267267        }
    268268        jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    269                        "\nNumber of Iterations    = %d\n",
     269                       "\nNumber of Iterations....: %d\n",
    270270                       ip_data->iter_count());
    271         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    272                        "Objective Value         = %23.16e\n",
    273                        ip_cq->unscaled_curr_f());
    274         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    275                        "Primal Infeasibility    = %23.16e\n",
    276                        ip_cq->curr_primal_infeasibility(NORM_MAX));
    277         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    278                        "Dual Infeasibility      = %23.16e\n",
    279                        ip_cq->curr_dual_infeasibility(NORM_MAX));
    280         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    281                        "Complementarity         = %23.16e\n",
    282                        ip_cq->curr_complementarity(0., NORM_MAX));
     271
     272        jnlst_->Printf(J_SUMMARY, J_SOLUTION,
     273                       "\n                                   (scaled)                 (unscaled)\n");
     274        jnlst_->Printf(J_SUMMARY, J_SOLUTION,
     275                       "Objective...............: %24.16e  %24.16e\n", ip_cq->curr_f(), ip_cq->unscaled_curr_f());
     276        jnlst_->Printf(J_SUMMARY, J_SOLUTION,
     277                       "Dual infeasibility......: %24.16e  %24.16e\n", ip_cq->curr_dual_infeasibility(NORM_MAX), ip_cq->unscaled_curr_dual_infeasibility(NORM_MAX));
     278        jnlst_->Printf(J_SUMMARY, J_SOLUTION,
     279                       "Constraint violation....: %24.16e  %24.16e\n", ip_cq->curr_nlp_constraint_violation(NORM_MAX), ip_cq->unscaled_curr_nlp_constraint_violation(NORM_MAX));
     280        jnlst_->Printf(J_SUMMARY, J_SOLUTION,
     281                       "Complementarity.........: %24.16e  %24.16e\n", ip_cq->curr_complementarity(0., NORM_MAX), ip_cq->unscaled_curr_complementarity(0., NORM_MAX));
     282        jnlst_->Printf(J_SUMMARY, J_SOLUTION,
     283                       "Overall NLP error.......: %24.16e  %24.16e\n\n", ip_cq->curr_nlp_error(), ip_cq->unscaled_curr_nlp_error());
     284
    283285
    284286        jnlst_->PrintVector(vector_report_level, J_SOLUTION, "x", *ip_data->curr()->x());
  • branches/dev/Interfaces/IpNLP.hpp

    r388 r414  
    9494      bool need_z_L,
    9595      SmartPtr<Vector> z_U,
    96       bool need_z_U,
    97       SmartPtr<Vector> v_L,
    98       bool need_v_L,
    99       SmartPtr<Vector> v_U,
    100       bool need_v_U
     96      bool need_z_U
    10197    )=0;
    10298    //@}
     
    143139      const SmartPtr<const VectorSpace> d_space,
    144140      Number& obj_scaling,
    145       SmartPtr<Vector> x_scaling,
    146       SmartPtr<Vector> c_scaling,
    147       SmartPtr<Vector> d_scaling) const
     141      SmartPtr<Vector>& x_scaling,
     142      SmartPtr<Vector>& c_scaling,
     143      SmartPtr<Vector>& d_scaling) const
    148144    {
    149145      THROW_EXCEPTION(USER_SCALING_NOT_IMPLEMENTED,
  • branches/dev/LinAlgImpl/Serial/IpTNLPAdapter.cpp

    r388 r414  
    534534                                     bool need_z_L,
    535535                                     SmartPtr<Vector> z_U,
    536                                      bool need_z_U,
    537                                      SmartPtr<Vector> v_L,
    538                                      bool need_v_L,
    539                                      SmartPtr<Vector> v_U,
    540                                      bool need_v_U
     536                                     bool need_z_U
    541537                                    )
    542538  {
     
    612608    }
    613609
    614     DBG_ASSERT(!need_v_L && !need_v_U
    615                && "Need to think about initialization of these.");
    616 
    617610    delete [] full_x;
    618611    full_x = NULL;
     
    798791    const SmartPtr<const VectorSpace> d_space,
    799792    Number& obj_scaling,
    800     SmartPtr<Vector> x_scaling,
    801     SmartPtr<Vector> c_scaling,
    802     SmartPtr<Vector> d_scaling) const
     793    SmartPtr<Vector>& x_scaling,
     794    SmartPtr<Vector>& c_scaling,
     795    SmartPtr<Vector>& d_scaling) const
    803796  {
    804797    x_scaling = x_space->MakeNew();
  • branches/dev/LinAlgImpl/Serial/IpTNLPAdapter.hpp

    r388 r414  
    8787      bool need_z_L,
    8888      SmartPtr<Vector> z_U,
    89       bool need_z_U,
    90       SmartPtr<Vector> v_L,
    91       bool need_v_L,
    92       SmartPtr<Vector> v_U,
    93       bool need_v_U
     89      bool need_z_U
    9490    );
    9591    //@}
     
    120116      const SmartPtr<const VectorSpace> d_space,
    121117      Number& obj_scaling,
    122       SmartPtr<Vector> x_scaling,
    123       SmartPtr<Vector> c_scaling,
    124       SmartPtr<Vector> d_scaling) const;
     118      SmartPtr<Vector>& x_scaling,
     119      SmartPtr<Vector>& c_scaling,
     120      SmartPtr<Vector>& d_scaling) const;
    125121    //@}
    126122
Note: See TracChangeset for help on using the changeset viewer.