1 // Copyright (C) 2004, 2006 International Business Machines and others. 2 // All Rights Reserved. 3 // This code is published under the Common Public License. 4 // 5 // $Id: IpIpoptAlg.hpp 759 2006-07-07 03:07:08Z andreasw $ 6 // 7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 8 9 #ifndef __IPIPOPTALG_HPP__ 10 #define __IPIPOPTALG_HPP__ 11 12 #include "IpIpoptNLP.hpp" 13 #include "IpAlgStrategy.hpp" 14 #include "IpPDSystemSolver.hpp" 15 #include "IpLineSearch.hpp" 16 #include "IpMuUpdate.hpp" 17 #include "IpConvCheck.hpp" 18 #include "IpOptionsList.hpp" 19 #include "IpIterateInitializer.hpp" 20 #include "IpIterationOutput.hpp" 21 #include "IpAlgTypes.hpp" 22 #include "IpHessianUpdater.hpp" 23 #include "IpEqMultCalculator.hpp" 24 25 namespace SimTKIpopt 26 { 27 28 /** @name Exceptions */ 29 //@{ 30 DECLARE_STD_EXCEPTION(STEP_COMPUTATION_FAILED); 31 //@} 32 33 /** The main ipopt algorithm class. 34 * Main Ipopt algorithm class, contains the main optimize method, 35 * handles the execution of the optimization. 36 * The constructor initializes the data structures through the nlp, 37 * and the Optimize method then assumes that everything is 38 * initialized and ready to go. 39 * After an optimization is complete, the user can access the 40 * solution through the passed in ip_data structure. 41 * Multiple calls to the Optimize method are allowed as long as the 42 * structure of the problem remains the same (i.e. starting point 43 * or nlp parameter changes only). 44 */ 45 class IpoptAlgorithm : public AlgorithmStrategyObject 46 { 47 public: 48 49 /**@name Constructors/Destructors */ 50 //@{ 51 /** Constructor. (The IpoptAlgorithm uses smart pointers for these 52 * passed-in pieces to make sure that a user of IpoptAlgoroithm 53 * cannot pass in an object created on the stack!) 54 */ 55 IpoptAlgorithm(const SmartPtr<PDSystemSolver>& pd_solver, 56 const SmartPtr<LineSearch>& line_search, 57 const SmartPtr<MuUpdate>& mu_update, 58 const SmartPtr<ConvergenceCheck>& conv_check, 59 const SmartPtr<IterateInitializer>& iterate_initializer, 60 const SmartPtr<IterationOutput>& iter_output, 61 const SmartPtr<HessianUpdater>& hessian_updater, 62 const SmartPtr<EqMultiplierCalculator>& eq_multiplier_calculator = NULL); 63 64 /** Default destructor */ 65 virtual ~IpoptAlgorithm(); 66 //@} 67 68 69 /** overloaded from AlgorithmStrategyObject */ 70 virtual bool InitializeImpl(const OptionsList& options, 71 const std::string& prefix) override; 72 73 /** Main solve method. */ 74 SolverReturn Optimize(); 75 76 /** Methods for IpoptType */ 77 //@{ 78 static void RegisterOptions(SmartPtr<RegisteredOptions> roptions); 79 //@} 80 81 private: 82 /**@name Default Compiler Generated Methods 83 * (Hidden to avoid implicit creation/calling). 84 * These methods are not implemented and 85 * we do not want the compiler to implement 86 * them for us, so we declare them private 87 * and do not define them. This ensures that 88 * they will not be implicitly created/called. */ 89 //@{ 90 /** Default Constructor */ 91 IpoptAlgorithm(); 92 93 /** Copy Constructor */ 94 IpoptAlgorithm(const IpoptAlgorithm&); 95 96 /** Overloaded Equals Operator */ 97 void operator=(const IpoptAlgorithm&); 98 //@} 99 100 /** @name Strategy objects */ 101 //@{ 102 SmartPtr<PDSystemSolver> pd_solver_; 103 SmartPtr<LineSearch> line_search_; 104 SmartPtr<MuUpdate> mu_update_; 105 SmartPtr<ConvergenceCheck> conv_check_; 106 SmartPtr<IterateInitializer> iterate_initializer_; 107 SmartPtr<IterationOutput> iter_output_; 108 SmartPtr<HessianUpdater> hessian_updater_; 109 /** The multipler calculator (for y_c and y_d) has to be set only 110 * if option recalc_y is set to true */ 111 SmartPtr<EqMultiplierCalculator> eq_multiplier_calculator_; 112 //@} 113 114 /** @name Main steps of the algorthim */ 115 //@{ 116 /** Method for updating the current Hessian. This can either just 117 * evaluate the exact Hessian (based on the current iterate), or 118 * perform a quasi-Newton update. 119 */ 120 void UpdateHessian(); 121 122 /** Method to update the barrier parameter. Returns false, if the 123 * algorithm can't continue with the regular procedure and needs 124 * to revert to a fallback mechanism in the line search (such as 125 * restoration phase) */ 126 bool UpdateBarrierParameter(); 127 128 /** Method to setup the call to the PDSystemSolver. Returns 129 * false, if the algorithm can't continue with the regular 130 * procedure and needs to revert to a fallback mechanism in the 131 * line search (such as restoration phase) */ 132 bool ComputeSearchDirection(); 133 134 /** Method computing the new iterate (usually vialine search). 135 * The acceptable point is the one in trial after return. 136 */ 137 void ComputeAcceptableTrialPoint(); 138 139 /** Method for accepting the trial point as the new iteration, 140 * possibly after adjusting the variable bounds in the NLP. */ 141 void AcceptTrialPoint(); 142 143 /** Do all the output for one iteration */ 144 void OutputIteration(); 145 146 /** Sets up initial values for the iterates, 147 * Corrects the initial values for x and s (force in bounds) 148 */ 149 void InitializeIterates(); 150 151 /** Print the problem size statistics */ 152 void PrintProblemStatistics(); 153 //@} 154 155 /** @name internal flags */ 156 //@{ 157 /** Flag indicating if the statistic should not be printed */ 158 bool skip_print_problem_stats_; 159 //@} 160 161 /** @name Algorithmic parameters */ 162 //@{ 163 /** safeguard factor for bound multipliers. If value >= 1, then 164 * the dual variables will never deviate from the primal estimate 165 * by more than the factors kappa_sigma and 1./kappa_sigma. 166 */ 167 Number kappa_sigma_; 168 /** Flag indicating whether the y multipliers should be 169 * recalculated with the eq_mutliplier_calculator object for each 170 * new point. */ 171 bool recalc_y_; 172 /** Feasibility threshold for recalc_y */ 173 Number recalc_y_feas_tol_; 174 //@} 175 176 /** @name auxilliary functions */ 177 //@{ 178 void calc_number_of_bounds( 179 const Vector& x, 180 const Vector& x_L, 181 const Vector& x_U, 182 const Matrix& Px_L, 183 const Matrix& Px_U, 184 Index& n_tot, 185 Index& n_only_lower, 186 Index& n_both, 187 Index& n_only_upper); 188 189 /** Method for ensuring that the trial multipliers are not too far 190 * from the primal estime. If a correction is made, new_trial_z 191 * is a pointer to the corrected multiplier, and the return value 192 * of this method give the magnitutde of the largest correction 193 * that we done. If no correction was made, new_trial_z is just 194 * a pointer to trial_z, and the return value is zero. 195 */ 196 Number correct_bound_multiplier(const Vector& trial_z, 197 const Vector& trial_slack, 198 const Vector& trial_compl, 199 SmartPtr<const Vector>& new_trial_z); 200 //@} 201 }; 202 203 } // namespace Ipopt 204 205 #endif 206