31 using namespace Ipopt;
40 Index& nnz_h_lag, IndexStyleEnum& index_style)
51 nnz_h_lag = n*(n-1)/2+n;
56 index_style = C_STYLE;
62 Index m, Number* g_l, Number* g_u)
65 for (Index i=0; i<n; i++) {
71 for (Index i=0; i<m; i++) {
80 bool init_z, Number* z_L, Number* z_U,
81 Index m,
bool init_lambda,
87 assert(init_x ==
true);
88 assert(init_z ==
false);
89 assert(init_lambda ==
false);
92 for (Index i=0; i<n/2; i++) {
107 for (Index i=0; i<n-1; i++) {
108 a1 = x[i]*x[i]-x[i+1];
110 obj_value += 100.*a1*a1 + a2*a2;
118 for (Index i=0; i<m; i++) {
119 g[i] = 3.*pow(x[i+1],3.) + 2.*x[i+2] - 5.
120 + sin(x[i+1]-x[i+2])*sin(x[i+1]+x[i+2]) + 4.*x[i+1]
121 - x[i]*exp(x[i]-x[i+1]) - 3.;
138 eval_obj(n,x,obj_value);
146 gradient(
tag_f,n,x,grad_f);
154 eval_constraints(n,x,m,g);
160 Index m, Index nele_jac, Index* iRow, Index *jCol,
163 if (values == NULL) {
168 for(Index i=0; i<m; i++)
169 for(Index j=0; j<n; j++)
178 jacobian(
tag_g,m,n,x,Jac);
181 for(Index i=0; i<m; i++)
182 for(Index j=0; j<n; j++)
183 values[idx++] = Jac[i][j];
191 Number obj_factor, Index m,
const Number* lambda,
192 bool new_lambda, Index nele_hess, Index* iRow,
193 Index* jCol, Number* values)
195 if (values == NULL) {
201 for (Index row = 0; row < n; row++) {
202 for (Index col = 0; col <= row; col++) {
209 assert(idx == nele_hess);
215 for(Index i = 0; i<n ; i++)
217 for(Index i = 0; i<m ; i++)
218 x_lam[n+i] = lambda[i];
219 x_lam[n+m] = obj_factor;
221 hessian(
tag_L,n+m+1,x_lam,Hess);
225 for(Index i = 0; i<n ; i++)
227 for(Index j = 0; j<=i ; j++)
229 values[idx++] = Hess[i][j];
238 Index n,
const Number* x,
const Number* z_L,
const Number* z_U,
239 Index m,
const Number* g,
const Number* lambda,
241 const IpoptData* ip_data,
242 IpoptCalculatedQuantities* ip_cq)
245 printf(
"\n\nObjective value\n");
246 printf(
"f(x*) = %e\n", obj_value);
252 for(Index i=0;i<m;i++)
256 for(Index i=0;i<n+m+1;i++)
266 Number *xp =
new double[n];
267 Number *lamp =
new double[m];
268 Number *zl =
new double[m];
269 Number *zu =
new double[m];
271 adouble *xa =
new adouble[n];
272 adouble *g =
new adouble[m];
273 adouble *lam =
new adouble[m];
279 Jac =
new double*[m];
280 for(Index i=0;i<m;i++)
281 Jac[i] =
new double[n];
283 x_lam =
new double[n+m+1];
285 Hess =
new double*[n+m+1];
286 for(Index i=0;i<n+m+1;i++)
287 Hess[i] =
new double[i+1];
289 get_starting_point(n, 1, xp, 0, zl, zu, m, 0, lamp);
293 for(Index i=0;i<n;i++)
296 eval_obj(n,xa,obj_value);
304 for(Index i=0;i<n;i++)
307 eval_constraints(n,xa,m,g);
310 for(Index i=0;i<m;i++)
317 for(Index i=0;i<n;i++)
319 for(Index i=0;i<m;i++)
323 eval_obj(n,xa,obj_value);
326 eval_constraints(n,xa,m,g);
328 for(Index i=0;i<m;i++)
329 obj_value += g[i]*lam[i];
virtual bool eval_f(Index n, const Number *x, bool new_x, Number &obj_value)
virtual bool eval_jac_g(Index n, const Number *x, bool new_x, Index m, Index nele_jac, Index *iRow, Index *jCol, Number *values)
virtual bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m, Number *g_l, Number *g_u)
virtual bool eval_g(Index n, const Number *x, bool new_x, Index m, Number *g)
virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag, IndexStyleEnum &index_style)
virtual bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor, Index m, const Number *lambda, bool new_lambda, Index nele_hess, Index *iRow, Index *jCol, Number *values)
virtual void generate_tapes(Index n, Index m)
bool eval_constraints(Index n, const T *x, Index m, T *g)
bool eval_obj(Index n, const T *x, T &obj_value)
virtual bool eval_grad_f(Index n, const Number *x, bool new_x, Number *grad_f)
virtual void finalize_solution(SolverReturn status, Index n, const Number *x, const Number *z_L, const Number *z_U, Index m, const Number *g, const Number *lambda, Number obj_value, const IpoptData *ip_data, IpoptCalculatedQuantities *ip_cq)
virtual bool get_starting_point(Index n, bool init_x, Number *x, bool init_z, Number *z_L, Number *z_U, Index m, bool init_lambda, Number *lambda)