IpIpoptCalculatedQuantities.hpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. // Copyright (C) 2004, 2011 International Business Machines and others.
  2. // All Rights Reserved.
  3. // This code is published under the Eclipse Public License.
  4. //
  5. // $Id: IpIpoptCalculatedQuantities.hpp 2020 2011-06-16 20:46:16Z andreasw $
  6. //
  7. // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
  8. #ifndef __IPIPOPTCALCULATEDQUANTITIES_HPP__
  9. #define __IPIPOPTCALCULATEDQUANTITIES_HPP__
  10. #include "IpSmartPtr.hpp"
  11. #include "IpCachedResults.hpp"
  12. #include <string>
  13. namespace Ipopt
  14. {
  15. class IpoptNLP;
  16. class IpoptData;
  17. class Vector;
  18. class Matrix;
  19. class SymMatrix;
  20. class Journalist;
  21. class OptionsList;
  22. class RegisteredOptions;
  23. /** Norm types */
  24. enum ENormType {
  25. NORM_1=0,
  26. NORM_2,
  27. NORM_MAX
  28. };
  29. /** Base class for additional calculated quantities that is special
  30. * to a particular type of algorithm, such as the CG penalty
  31. * function, or using iterative linear solvers. The regular
  32. * IpoptCalculatedQuantities object should be given a derivation of
  33. * this base class when it is created. */
  34. class IpoptAdditionalCq : public ReferencedObject
  35. {
  36. public:
  37. /**@name Constructors/Destructors */
  38. //@{
  39. /** Default Constructor */
  40. IpoptAdditionalCq()
  41. {}
  42. /** Default destructor */
  43. virtual ~IpoptAdditionalCq()
  44. {}
  45. //@}
  46. /** This method is called to initialize the global algorithmic
  47. * parameters. The parameters are taken from the OptionsList
  48. * object. */
  49. virtual bool Initialize(const Journalist& jnlst,
  50. const OptionsList& options,
  51. const std::string& prefix) = 0;
  52. private:
  53. /**@name Default Compiler Generated Methods
  54. * (Hidden to avoid implicit creation/calling).
  55. * These methods are not implemented and
  56. * we do not want the compiler to implement
  57. * them for us, so we declare them private
  58. * and do not define them. This ensures that
  59. * they will not be implicitly created/called. */
  60. //@{
  61. /** Copy Constructor */
  62. IpoptAdditionalCq(const IpoptAdditionalCq&);
  63. /** Overloaded Equals Operator */
  64. void operator=(const IpoptAdditionalCq&);
  65. //@}
  66. };
  67. /** Class for all IPOPT specific calculated quantities.
  68. *
  69. */
  70. class IpoptCalculatedQuantities : public ReferencedObject
  71. {
  72. public:
  73. /**@name Constructors/Destructors */
  74. //@{
  75. /** Constructor */
  76. IpoptCalculatedQuantities(const SmartPtr<IpoptNLP>& ip_nlp,
  77. const SmartPtr<IpoptData>& ip_data);
  78. /** Default destructor */
  79. virtual ~IpoptCalculatedQuantities();
  80. //@}
  81. /** Method for setting pointer for additional calculated
  82. * quantities. This needs to be called before Initialized. */
  83. void SetAddCq(SmartPtr<IpoptAdditionalCq> add_cq)
  84. {
  85. DBG_ASSERT(!HaveAddCq());
  86. add_cq_ = add_cq;
  87. }
  88. /** Method detecting if additional object for calculated
  89. * quantities has already been set */
  90. bool HaveAddCq()
  91. {
  92. return IsValid(add_cq_);
  93. }
  94. /** This method must be called to initialize the global
  95. * algorithmic parameters. The parameters are taken from the
  96. * OptionsList object. */
  97. bool Initialize(const Journalist& jnlst,
  98. const OptionsList& options,
  99. const std::string& prefix);
  100. /** @name Slacks */
  101. //@{
  102. /** Slacks for x_L (at current iterate) */
  103. SmartPtr<const Vector> curr_slack_x_L();
  104. /** Slacks for x_U (at current iterate) */
  105. SmartPtr<const Vector> curr_slack_x_U();
  106. /** Slacks for s_L (at current iterate) */
  107. SmartPtr<const Vector> curr_slack_s_L();
  108. /** Slacks for s_U (at current iterate) */
  109. SmartPtr<const Vector> curr_slack_s_U();
  110. /** Slacks for x_L (at trial point) */
  111. SmartPtr<const Vector> trial_slack_x_L();
  112. /** Slacks for x_U (at trial point) */
  113. SmartPtr<const Vector> trial_slack_x_U();
  114. /** Slacks for s_L (at trial point) */
  115. SmartPtr<const Vector> trial_slack_s_L();
  116. /** Slacks for s_U (at trial point) */
  117. SmartPtr<const Vector> trial_slack_s_U();
  118. /** Indicating whether or not we "fudged" the slacks */
  119. Index AdjustedTrialSlacks();
  120. /** Reset the flags for "fudged" slacks */
  121. void ResetAdjustedTrialSlacks();
  122. //@}
  123. /** @name Objective function */
  124. //@{
  125. /** Value of objective function (at current point) */
  126. virtual Number curr_f();
  127. /** Unscaled value of the objective function (at the current point) */
  128. virtual Number unscaled_curr_f();
  129. /** Value of objective function (at trial point) */
  130. virtual Number trial_f();
  131. /** Unscaled value of the objective function (at the trial point) */
  132. virtual Number unscaled_trial_f();
  133. /** Gradient of objective function (at current point) */
  134. SmartPtr<const Vector> curr_grad_f();
  135. /** Gradient of objective function (at trial point) */
  136. SmartPtr<const Vector> trial_grad_f();
  137. //@}
  138. /** @name Barrier Objective Function */
  139. //@{
  140. /** Barrier Objective Function Value
  141. * (at current iterate with current mu)
  142. */
  143. virtual Number curr_barrier_obj();
  144. /** Barrier Objective Function Value
  145. * (at trial point with current mu)
  146. */
  147. virtual Number trial_barrier_obj();
  148. /** Gradient of barrier objective function with respect to x
  149. * (at current point with current mu) */
  150. SmartPtr<const Vector> curr_grad_barrier_obj_x();
  151. /** Gradient of barrier objective function with respect to s
  152. * (at current point with current mu) */
  153. SmartPtr<const Vector> curr_grad_barrier_obj_s();
  154. /** Gradient of the damping term with respect to x (times
  155. * kappa_d) */
  156. SmartPtr<const Vector> grad_kappa_times_damping_x();
  157. /** Gradient of the damping term with respect to s (times
  158. * kappa_d) */
  159. SmartPtr<const Vector> grad_kappa_times_damping_s();
  160. //@}
  161. /** @name Constraints */
  162. //@{
  163. /** c(x) (at current point) */
  164. SmartPtr<const Vector> curr_c();
  165. /** unscaled c(x) (at current point) */
  166. SmartPtr<const Vector> unscaled_curr_c();
  167. /** c(x) (at trial point) */
  168. SmartPtr<const Vector> trial_c();
  169. /** unscaled c(x) (at trial point) */
  170. SmartPtr<const Vector> unscaled_trial_c();
  171. /** d(x) (at current point) */
  172. SmartPtr<const Vector> curr_d();
  173. /** unscaled d(x) (at current point) */
  174. SmartPtr<const Vector> unscaled_curr_d();
  175. /** d(x) (at trial point) */
  176. SmartPtr<const Vector> trial_d();
  177. /** d(x) - s (at current point) */
  178. SmartPtr<const Vector> curr_d_minus_s();
  179. /** d(x) - s (at trial point) */
  180. SmartPtr<const Vector> trial_d_minus_s();
  181. /** Jacobian of c (at current point) */
  182. SmartPtr<const Matrix> curr_jac_c();
  183. /** Jacobian of c (at trial point) */
  184. SmartPtr<const Matrix> trial_jac_c();
  185. /** Jacobian of d (at current point) */
  186. SmartPtr<const Matrix> curr_jac_d();
  187. /** Jacobian of d (at trial point) */
  188. SmartPtr<const Matrix> trial_jac_d();
  189. /** Product of Jacobian (evaluated at current point) of C
  190. * transpose with general vector */
  191. SmartPtr<const Vector> curr_jac_cT_times_vec(const Vector& vec);
  192. /** Product of Jacobian (evaluated at trial point) of C
  193. * transpose with general vector */
  194. SmartPtr<const Vector> trial_jac_cT_times_vec(const Vector& vec);
  195. /** Product of Jacobian (evaluated at current point) of D
  196. * transpose with general vector */
  197. SmartPtr<const Vector> curr_jac_dT_times_vec(const Vector& vec);
  198. /** Product of Jacobian (evaluated at trial point) of D
  199. * transpose with general vector */
  200. SmartPtr<const Vector> trial_jac_dT_times_vec(const Vector& vec);
  201. /** Product of Jacobian (evaluated at current point) of C
  202. * transpose with current y_c */
  203. SmartPtr<const Vector> curr_jac_cT_times_curr_y_c();
  204. /** Product of Jacobian (evaluated at trial point) of C
  205. * transpose with trial y_c */
  206. SmartPtr<const Vector> trial_jac_cT_times_trial_y_c();
  207. /** Product of Jacobian (evaluated at current point) of D
  208. * transpose with current y_d */
  209. SmartPtr<const Vector> curr_jac_dT_times_curr_y_d();
  210. /** Product of Jacobian (evaluated at trial point) of D
  211. * transpose with trial y_d */
  212. SmartPtr<const Vector> trial_jac_dT_times_trial_y_d();
  213. /** Product of Jacobian (evaluated at current point) of C
  214. * with general vector */
  215. SmartPtr<const Vector> curr_jac_c_times_vec(const Vector& vec);
  216. /** Product of Jacobian (evaluated at current point) of D
  217. * with general vector */
  218. SmartPtr<const Vector> curr_jac_d_times_vec(const Vector& vec);
  219. /** Constraint Violation (at current iterate). This value should
  220. * be used in the line search, and not curr_primal_infeasibility().
  221. * What type of norm is used depends on constr_viol_normtype */
  222. virtual Number curr_constraint_violation();
  223. /** Constraint Violation (at trial point). This value should
  224. * be used in the line search, and not curr_primal_infeasibility().
  225. * What type of norm is used depends on constr_viol_normtype */
  226. virtual Number trial_constraint_violation();
  227. /** Real constraint violation in a given norm (at current
  228. * iterate). This considers the inequality constraints without
  229. * slacks. */
  230. virtual Number curr_nlp_constraint_violation(ENormType NormType);
  231. /** Unscaled real constraint violation in a given norm (at current
  232. * iterate). This considers the inequality constraints without
  233. * slacks. */
  234. virtual Number unscaled_curr_nlp_constraint_violation(ENormType NormType);
  235. /** Unscaled real constraint violation in a given norm (at trial
  236. * iterate). This considers the inequality constraints without
  237. * slacks. */
  238. virtual Number unscaled_trial_nlp_constraint_violation(ENormType NormType);
  239. //@}
  240. /** @name Hessian matrices */
  241. //@{
  242. /** exact Hessian at current iterate (uncached) */
  243. SmartPtr<const SymMatrix> curr_exact_hessian();
  244. //@}
  245. /** @name primal-dual error and its components */
  246. //@{
  247. /** x-part of gradient of Lagrangian function (at current point) */
  248. SmartPtr<const Vector> curr_grad_lag_x();
  249. /** x-part of gradient of Lagrangian function (at trial point) */
  250. SmartPtr<const Vector> trial_grad_lag_x();
  251. /** s-part of gradient of Lagrangian function (at current point) */
  252. SmartPtr<const Vector> curr_grad_lag_s();
  253. /** s-part of gradient of Lagrangian function (at trial point) */
  254. SmartPtr<const Vector> trial_grad_lag_s();
  255. /** x-part of gradient of Lagrangian function (at current point)
  256. including linear damping term */
  257. SmartPtr<const Vector> curr_grad_lag_with_damping_x();
  258. /** s-part of gradient of Lagrangian function (at current point)
  259. including linear damping term */
  260. SmartPtr<const Vector> curr_grad_lag_with_damping_s();
  261. /** Complementarity for x_L (for current iterate) */
  262. SmartPtr<const Vector> curr_compl_x_L();
  263. /** Complementarity for x_U (for current iterate) */
  264. SmartPtr<const Vector> curr_compl_x_U();
  265. /** Complementarity for s_L (for current iterate) */
  266. SmartPtr<const Vector> curr_compl_s_L();
  267. /** Complementarity for s_U (for current iterate) */
  268. SmartPtr<const Vector> curr_compl_s_U();
  269. /** Complementarity for x_L (for trial iterate) */
  270. SmartPtr<const Vector> trial_compl_x_L();
  271. /** Complementarity for x_U (for trial iterate) */
  272. SmartPtr<const Vector> trial_compl_x_U();
  273. /** Complementarity for s_L (for trial iterate) */
  274. SmartPtr<const Vector> trial_compl_s_L();
  275. /** Complementarity for s_U (for trial iterate) */
  276. SmartPtr<const Vector> trial_compl_s_U();
  277. /** Relaxed complementarity for x_L (for current iterate and current mu) */
  278. SmartPtr<const Vector> curr_relaxed_compl_x_L();
  279. /** Relaxed complementarity for x_U (for current iterate and current mu) */
  280. SmartPtr<const Vector> curr_relaxed_compl_x_U();
  281. /** Relaxed complementarity for s_L (for current iterate and current mu) */
  282. SmartPtr<const Vector> curr_relaxed_compl_s_L();
  283. /** Relaxed complementarity for s_U (for current iterate and current mu) */
  284. SmartPtr<const Vector> curr_relaxed_compl_s_U();
  285. /** Primal infeasibility in a given norm (at current iterate). */
  286. virtual Number curr_primal_infeasibility(ENormType NormType);
  287. /** Primal infeasibility in a given norm (at trial point) */
  288. virtual Number trial_primal_infeasibility(ENormType NormType);
  289. /** Dual infeasibility in a given norm (at current iterate) */
  290. virtual Number curr_dual_infeasibility(ENormType NormType);
  291. /** Dual infeasibility in a given norm (at trial iterate) */
  292. virtual Number trial_dual_infeasibility(ENormType NormType);
  293. /** Unscaled dual infeasibility in a given norm (at current iterate) */
  294. virtual Number unscaled_curr_dual_infeasibility(ENormType NormType);
  295. /** Complementarity (for all complementarity conditions together)
  296. * in a given norm (at current iterate) */
  297. virtual Number curr_complementarity(Number mu, ENormType NormType);
  298. /** Complementarity (for all complementarity conditions together)
  299. * in a given norm (at trial iterate) */
  300. virtual Number trial_complementarity(Number mu, ENormType NormType);
  301. /** Complementarity (for all complementarity conditions together)
  302. * in a given norm (at current iterate) without NLP scaling. */
  303. virtual Number unscaled_curr_complementarity(Number mu, ENormType NormType);
  304. /** Centrality measure (in spirit of the -infinity-neighborhood. */
  305. Number CalcCentralityMeasure(const Vector& compl_x_L,
  306. const Vector& compl_x_U,
  307. const Vector& compl_s_L,
  308. const Vector& compl_s_U);
  309. /** Centrality measure at current point */
  310. virtual Number curr_centrality_measure();
  311. /** Total optimality error for the original NLP at the current
  312. * iterate, using scaling factors based on multipliers. Note
  313. * that here the constraint violation is measured without slacks
  314. * (nlp_constraint_violation) */
  315. virtual Number curr_nlp_error();
  316. /** Total optimality error for the original NLP at the current
  317. * iterate, but using no scaling based on multipliers, and no
  318. * scaling for the NLP. Note that here the constraint violation
  319. * is measured without slacks (nlp_constraint_violation) */
  320. virtual Number unscaled_curr_nlp_error();
  321. /** Total optimality error for the barrier problem at the
  322. * current iterate, using scaling factors based on multipliers. */
  323. virtual Number curr_barrier_error();
  324. /** Norm of the primal-dual system for a given mu (at current
  325. * iterate). The norm is defined as the sum of the 1-norms of
  326. * dual infeasibiliy, primal infeasibility, and complementarity,
  327. * all divided by the number of elements of the vectors of which
  328. * the norm is taken.
  329. */
  330. virtual Number curr_primal_dual_system_error(Number mu);
  331. /** Norm of the primal-dual system for a given mu (at trial
  332. * iterate). The norm is defined as the sum of the 1-norms of
  333. * dual infeasibiliy, primal infeasibility, and complementarity,
  334. * all divided by the number of elements of the vectors of which
  335. * the norm is taken.
  336. */
  337. virtual Number trial_primal_dual_system_error(Number mu);
  338. //@}
  339. /** @name Computing fraction-to-the-boundary step sizes */
  340. //@{
  341. /** Fraction to the boundary from (current) primal variables x and s
  342. * for a given step */
  343. Number primal_frac_to_the_bound(Number tau,
  344. const Vector& delta_x,
  345. const Vector& delta_s);
  346. /** Fraction to the boundary from (current) primal variables x and s
  347. * for internal (current) step */
  348. Number curr_primal_frac_to_the_bound(Number tau);
  349. /** Fraction to the boundary from (current) dual variables z and v
  350. * for a given step */
  351. Number dual_frac_to_the_bound(Number tau,
  352. const Vector& delta_z_L,
  353. const Vector& delta_z_U,
  354. const Vector& delta_v_L,
  355. const Vector& delta_v_U);
  356. /** Fraction to the boundary from (current) dual variables z and v
  357. * for a given step, without caching */
  358. Number uncached_dual_frac_to_the_bound(Number tau,
  359. const Vector& delta_z_L,
  360. const Vector& delta_z_U,
  361. const Vector& delta_v_L,
  362. const Vector& delta_v_U);
  363. /** Fraction to the boundary from (current) dual variables z and v
  364. * for internal (current) step */
  365. Number curr_dual_frac_to_the_bound(Number tau);
  366. /** Fraction to the boundary from (current) slacks for a given
  367. * step in the slacks. Usually, one will use the
  368. * primal_frac_to_the_bound method to compute the primal fraction
  369. * to the boundary step size, but if it is cheaper to provide the
  370. * steps in the slacks directly (e.g. when the primal step sizes
  371. * are only temporary), the this method is more efficient. This
  372. * method does not cache computations. */
  373. Number uncached_slack_frac_to_the_bound(Number tau,
  374. const Vector& delta_x_L,
  375. const Vector& delta_x_U,
  376. const Vector& delta_s_L,
  377. const Vector& delta_s_U);
  378. //@}
  379. /** @name Sigma matrices */
  380. //@{
  381. SmartPtr<const Vector> curr_sigma_x();
  382. SmartPtr<const Vector> curr_sigma_s();
  383. //@}
  384. /** average of current values of the complementarities */
  385. Number curr_avrg_compl();
  386. /** average of trial values of the complementarities */
  387. Number trial_avrg_compl();
  388. /** inner_product of current barrier obj. fn. gradient with
  389. * current search direction */
  390. Number curr_gradBarrTDelta();
  391. /** Compute the norm of a specific type of a set of vectors (uncached) */
  392. Number
  393. CalcNormOfType(ENormType NormType,
  394. std::vector<SmartPtr<const Vector> > vecs);
  395. /** Compute the norm of a specific type of two vectors (uncached) */
  396. Number
  397. CalcNormOfType(ENormType NormType,
  398. const Vector& vec1, const Vector& vec2);
  399. /** Norm type used for calculating constraint violation */
  400. ENormType constr_viol_normtype() const
  401. {
  402. return constr_viol_normtype_;
  403. }
  404. /** Method returning true if this is a square problem */
  405. bool IsSquareProblem() const;
  406. /** Method returning the IpoptNLP object. This should only be
  407. * used with care! */
  408. SmartPtr<IpoptNLP>& GetIpoptNLP()
  409. {
  410. return ip_nlp_;
  411. }
  412. IpoptAdditionalCq& AdditionalCq()
  413. {
  414. DBG_ASSERT(IsValid(add_cq_));
  415. return *add_cq_;
  416. }
  417. /** Methods for IpoptType */
  418. //@{
  419. /** Called by IpoptType to register the options */
  420. static void RegisterOptions(SmartPtr<RegisteredOptions> roptions);
  421. //@}
  422. private:
  423. /**@name Default Compiler Generated Methods
  424. * (Hidden to avoid implicit creation/calling).
  425. * These methods are not implemented and
  426. * we do not want the compiler to implement
  427. * them for us, so we declare them private
  428. * and do not define them. This ensures that
  429. * they will not be implicitly created/called. */
  430. //@{
  431. /** Default Constructor */
  432. IpoptCalculatedQuantities();
  433. /** Copy Constructor */
  434. IpoptCalculatedQuantities(const IpoptCalculatedQuantities&);
  435. /** Overloaded Equals Operator */
  436. void operator=(const IpoptCalculatedQuantities&);
  437. //@}
  438. /** @name Pointers for easy access to data and NLP information */
  439. //@{
  440. /** Ipopt NLP object */
  441. SmartPtr<IpoptNLP> ip_nlp_;
  442. /** Ipopt Data object */
  443. SmartPtr<IpoptData> ip_data_;
  444. /** Chen-Goldfarb specific calculated quantities */
  445. SmartPtr<IpoptAdditionalCq> add_cq_;
  446. //@}
  447. /** @name Algorithmic Parameters that can be set throught the
  448. * options list. Those parameters are initialize by calling the
  449. * Initialize method.*/
  450. //@{
  451. /** Parameter in formula for computing overall primal-dual
  452. * optimality error */
  453. Number s_max_;
  454. /** Weighting factor for the linear damping term added to the
  455. * barrier objective funciton. */
  456. Number kappa_d_;
  457. /** fractional movement allowed in bounds */
  458. Number slack_move_;
  459. /** Norm type to be used when calculating the constraint violation */
  460. ENormType constr_viol_normtype_;
  461. /** Flag indicating whether the TNLP with identical structure has
  462. * already been solved before. */
  463. bool warm_start_same_structure_;
  464. /** Desired value of the barrier parameter */
  465. Number mu_target_;
  466. //@}
  467. /** @name Caches for slacks */
  468. //@{
  469. CachedResults< SmartPtr<Vector> > curr_slack_x_L_cache_;
  470. CachedResults< SmartPtr<Vector> > curr_slack_x_U_cache_;
  471. CachedResults< SmartPtr<Vector> > curr_slack_s_L_cache_;
  472. CachedResults< SmartPtr<Vector> > curr_slack_s_U_cache_;
  473. CachedResults< SmartPtr<Vector> > trial_slack_x_L_cache_;
  474. CachedResults< SmartPtr<Vector> > trial_slack_x_U_cache_;
  475. CachedResults< SmartPtr<Vector> > trial_slack_s_L_cache_;
  476. CachedResults< SmartPtr<Vector> > trial_slack_s_U_cache_;
  477. Index num_adjusted_slack_x_L_;
  478. Index num_adjusted_slack_x_U_;
  479. Index num_adjusted_slack_s_L_;
  480. Index num_adjusted_slack_s_U_;
  481. //@}
  482. /** @name Cached for objective function stuff */
  483. //@{
  484. CachedResults<Number> curr_f_cache_;
  485. CachedResults<Number> trial_f_cache_;
  486. CachedResults< SmartPtr<const Vector> > curr_grad_f_cache_;
  487. CachedResults< SmartPtr<const Vector> > trial_grad_f_cache_;
  488. //@}
  489. /** @name Caches for barrier function stuff */
  490. //@{
  491. CachedResults<Number> curr_barrier_obj_cache_;
  492. CachedResults<Number> trial_barrier_obj_cache_;
  493. CachedResults< SmartPtr<const Vector> > curr_grad_barrier_obj_x_cache_;
  494. CachedResults< SmartPtr<const Vector> > curr_grad_barrier_obj_s_cache_;
  495. CachedResults< SmartPtr<const Vector> > grad_kappa_times_damping_x_cache_;
  496. CachedResults< SmartPtr<const Vector> > grad_kappa_times_damping_s_cache_;
  497. //@}
  498. /** @name Caches for constraint stuff */
  499. //@{
  500. CachedResults< SmartPtr<const Vector> > curr_c_cache_;
  501. CachedResults< SmartPtr<const Vector> > trial_c_cache_;
  502. CachedResults< SmartPtr<const Vector> > curr_d_cache_;
  503. CachedResults< SmartPtr<const Vector> > trial_d_cache_;
  504. CachedResults< SmartPtr<const Vector> > curr_d_minus_s_cache_;
  505. CachedResults< SmartPtr<const Vector> > trial_d_minus_s_cache_;
  506. CachedResults< SmartPtr<const Matrix> > curr_jac_c_cache_;
  507. CachedResults< SmartPtr<const Matrix> > trial_jac_c_cache_;
  508. CachedResults< SmartPtr<const Matrix> > curr_jac_d_cache_;
  509. CachedResults< SmartPtr<const Matrix> > trial_jac_d_cache_;
  510. CachedResults< SmartPtr<const Vector> > curr_jac_cT_times_vec_cache_;
  511. CachedResults< SmartPtr<const Vector> > trial_jac_cT_times_vec_cache_;
  512. CachedResults< SmartPtr<const Vector> > curr_jac_dT_times_vec_cache_;
  513. CachedResults< SmartPtr<const Vector> > trial_jac_dT_times_vec_cache_;
  514. CachedResults< SmartPtr<const Vector> > curr_jac_c_times_vec_cache_;
  515. CachedResults< SmartPtr<const Vector> > curr_jac_d_times_vec_cache_;
  516. CachedResults<Number> curr_constraint_violation_cache_;
  517. CachedResults<Number> trial_constraint_violation_cache_;
  518. CachedResults<Number> curr_nlp_constraint_violation_cache_;
  519. CachedResults<Number> unscaled_curr_nlp_constraint_violation_cache_;
  520. CachedResults<Number> unscaled_trial_nlp_constraint_violation_cache_;
  521. //@}
  522. /** Cache for the exact Hessian */
  523. CachedResults< SmartPtr<const SymMatrix> > curr_exact_hessian_cache_;
  524. /** @name Components of primal-dual error */
  525. //@{
  526. CachedResults< SmartPtr<const Vector> > curr_grad_lag_x_cache_;
  527. CachedResults< SmartPtr<const Vector> > trial_grad_lag_x_cache_;
  528. CachedResults< SmartPtr<const Vector> > curr_grad_lag_s_cache_;
  529. CachedResults< SmartPtr<const Vector> > trial_grad_lag_s_cache_;
  530. CachedResults< SmartPtr<const Vector> > curr_grad_lag_with_damping_x_cache_;
  531. CachedResults< SmartPtr<const Vector> > curr_grad_lag_with_damping_s_cache_;
  532. CachedResults< SmartPtr<const Vector> > curr_compl_x_L_cache_;
  533. CachedResults< SmartPtr<const Vector> > curr_compl_x_U_cache_;
  534. CachedResults< SmartPtr<const Vector> > curr_compl_s_L_cache_;
  535. CachedResults< SmartPtr<const Vector> > curr_compl_s_U_cache_;
  536. CachedResults< SmartPtr<const Vector> > trial_compl_x_L_cache_;
  537. CachedResults< SmartPtr<const Vector> > trial_compl_x_U_cache_;
  538. CachedResults< SmartPtr<const Vector> > trial_compl_s_L_cache_;
  539. CachedResults< SmartPtr<const Vector> > trial_compl_s_U_cache_;
  540. CachedResults< SmartPtr<const Vector> > curr_relaxed_compl_x_L_cache_;
  541. CachedResults< SmartPtr<const Vector> > curr_relaxed_compl_x_U_cache_;
  542. CachedResults< SmartPtr<const Vector> > curr_relaxed_compl_s_L_cache_;
  543. CachedResults< SmartPtr<const Vector> > curr_relaxed_compl_s_U_cache_;
  544. CachedResults<Number> curr_primal_infeasibility_cache_;
  545. CachedResults<Number> trial_primal_infeasibility_cache_;
  546. CachedResults<Number> curr_dual_infeasibility_cache_;
  547. CachedResults<Number> trial_dual_infeasibility_cache_;
  548. CachedResults<Number> unscaled_curr_dual_infeasibility_cache_;
  549. CachedResults<Number> curr_complementarity_cache_;
  550. CachedResults<Number> trial_complementarity_cache_;
  551. CachedResults<Number> curr_centrality_measure_cache_;
  552. CachedResults<Number> curr_nlp_error_cache_;
  553. CachedResults<Number> unscaled_curr_nlp_error_cache_;
  554. CachedResults<Number> curr_barrier_error_cache_;
  555. CachedResults<Number> curr_primal_dual_system_error_cache_;
  556. CachedResults<Number> trial_primal_dual_system_error_cache_;
  557. //@}
  558. /** @name Caches for fraction to the boundary step sizes */
  559. //@{
  560. CachedResults<Number> primal_frac_to_the_bound_cache_;
  561. CachedResults<Number> dual_frac_to_the_bound_cache_;
  562. //@}
  563. /** @name Caches for sigma matrices */
  564. //@{
  565. CachedResults< SmartPtr<const Vector> > curr_sigma_x_cache_;
  566. CachedResults< SmartPtr<const Vector> > curr_sigma_s_cache_;
  567. //@}
  568. /** Cache for average of current complementarity */
  569. CachedResults<Number> curr_avrg_compl_cache_;
  570. /** Cache for average of trial complementarity */
  571. CachedResults<Number> trial_avrg_compl_cache_;
  572. /** Cache for grad barrier obj. fn inner product with step */
  573. CachedResults<Number> curr_gradBarrTDelta_cache_;
  574. /** @name Indicator vectors required for the linear damping terms
  575. * to handle unbounded solution sets. */
  576. //@{
  577. /** Indicator vector for selecting the elements in x that have
  578. * only lower bounds. */
  579. SmartPtr<Vector> dampind_x_L_;
  580. /** Indicator vector for selecting the elements in x that have
  581. * only upper bounds. */
  582. SmartPtr<Vector> dampind_x_U_;
  583. /** Indicator vector for selecting the elements in s that have
  584. * only lower bounds. */
  585. SmartPtr<Vector> dampind_s_L_;
  586. /** Indicator vector for selecting the elements in s that have
  587. * only upper bounds. */
  588. SmartPtr<Vector> dampind_s_U_;
  589. //@}
  590. /** @name Temporary vectors for intermediate calcuations. We keep
  591. * these around to avoid unnecessarily many new allocations of
  592. * Vectors. */
  593. //@{
  594. SmartPtr<Vector> tmp_x_;
  595. SmartPtr<Vector> tmp_s_;
  596. SmartPtr<Vector> tmp_c_;
  597. SmartPtr<Vector> tmp_d_;
  598. SmartPtr<Vector> tmp_x_L_;
  599. SmartPtr<Vector> tmp_x_U_;
  600. SmartPtr<Vector> tmp_s_L_;
  601. SmartPtr<Vector> tmp_s_U_;
  602. /** Accessor methods for the temporary vectors */
  603. Vector& Tmp_x();
  604. Vector& Tmp_s();
  605. Vector& Tmp_c();
  606. Vector& Tmp_d();
  607. Vector& Tmp_x_L();
  608. Vector& Tmp_x_U();
  609. Vector& Tmp_s_L();
  610. Vector& Tmp_s_U();
  611. //@}
  612. /** flag indicating if Initialize method has been called (for
  613. * debugging) */
  614. bool initialize_called_;
  615. /** @name Auxiliary functions */
  616. //@{
  617. /** Compute new vector containing the slack to a lower bound
  618. * (uncached)
  619. */
  620. SmartPtr<Vector> CalcSlack_L(const Matrix& P,
  621. const Vector& x,
  622. const Vector& x_bound);
  623. /** Compute new vector containing the slack to a upper bound
  624. * (uncached)
  625. */
  626. SmartPtr<Vector> CalcSlack_U(const Matrix& P,
  627. const Vector& x,
  628. const Vector& x_bound);
  629. /** Compute barrier term at given point
  630. * (uncached)
  631. */
  632. Number CalcBarrierTerm(Number mu,
  633. const Vector& slack_x_L,
  634. const Vector& slack_x_U,
  635. const Vector& slack_s_L,
  636. const Vector& slack_s_U);
  637. /** Compute complementarity for slack / multiplier pair */
  638. SmartPtr<const Vector> CalcCompl(const Vector& slack,
  639. const Vector& mult);
  640. /** Compute fraction to the boundary parameter for lower and upper bounds */
  641. Number CalcFracToBound(const Vector& slack_L,
  642. Vector& tmp_L,
  643. const Matrix& P_L,
  644. const Vector& slack_U,
  645. Vector& tmp_U,
  646. const Matrix& P_U,
  647. const Vector& delta,
  648. Number tau);
  649. /** Compute the scaling factors for the optimality error. */
  650. void ComputeOptimalityErrorScaling(const Vector& y_c, const Vector& y_d,
  651. const Vector& z_L, const Vector& z_U,
  652. const Vector& v_L, const Vector& v_U,
  653. Number s_max,
  654. Number& s_d, Number& s_c);
  655. /** Check if slacks are becoming too small. If slacks are
  656. * becoming too small, they are change. The return value is the
  657. * number of corrected slacks. */
  658. Index CalculateSafeSlack(SmartPtr<Vector>& slack,
  659. const SmartPtr<const Vector>& bound,
  660. const SmartPtr<const Vector>& curr_point,
  661. const SmartPtr<const Vector>& multiplier);
  662. /** Computes the indicator vectors that can be used to filter out
  663. * those entries in the slack_... variables, that correspond to
  664. * variables with only lower and upper bounds. This is required
  665. * for the linear damping term in the barrier objective function
  666. * to handle unbounded solution sets. */
  667. void ComputeDampingIndicators(SmartPtr<const Vector>& dampind_x_L,
  668. SmartPtr<const Vector>& dampind_x_U,
  669. SmartPtr<const Vector>& dampind_s_L,
  670. SmartPtr<const Vector>& dampind_s_U);
  671. /** Check if we are in the restoration phase. Returns true, if the
  672. * ip_nlp is of the type RestoIpoptNLP. ToDo: We probably want to
  673. * handle this more elegant and don't have an explicit dependency
  674. * here. Now I added this because otherwise the caching doesn't
  675. * work properly since the restoration phase objective function
  676. * depends on the current barrier parameter. */
  677. bool in_restoration_phase();
  678. //@}
  679. };
  680. } // namespace Ipopt
  681. #endif