00001 # include "ipopt_cppad_nlp.hpp"
00002
00003 class FG_info : public ipopt_cppad_fg_info
00004 {
00005 public:
00006 ADVector eval_r(size_t k, const ADVector& x)
00007 { ADVector fg(3);
00008
00009 fg[0] = x[0] * x[3] * (x[0] + x[1] + x[2]) + x[2];
00010
00011 fg[1] = x[0] * x[1] * x[2] * x[3];
00012
00013 fg[2] = x[0] * x[0] + x[1] * x[1] + x[2] * x[2] + x[3] * x[3];
00014 return fg;
00015 }
00016 bool retape(size_t k)
00017 { return false; }
00018 };
00019
00020 int main(void)
00021 { size_t n = 4, m = 2, j;
00022 NumberVector x_i(n), x_l(n), x_u(n);
00023 for(j = 0; j < n; j++)
00024 { x_l[j] = 1.0;
00025 x_i[j] = 3.0;
00026 x_u[j] = 5.0;
00027 }
00028 NumberVector g_l(m), g_u(m);
00029 g_l[0] = 25.0; g_l[1] = 40.0;
00030 g_u[0] = 1.0e19; g_u[1] = 40.0;
00031
00032
00033 using Ipopt::SmartPtr;
00034 using Ipopt::TNLP;
00035
00036
00037 FG_info fg_info;
00038 ipopt_cppad_solution solve;
00039 SmartPtr<TNLP> cppad_nlp = new ipopt_cppad_nlp
00040 (n, m, x_i, x_l, x_u, g_l, g_u, &fg_info, &solve);
00041
00042 SmartPtr<Ipopt::IpoptApplication> app = new Ipopt::IpoptApplication();
00043 app->Options()->SetIntegerValue("print_level", -2);
00044 app->Initialize();
00045 app->OptimizeTNLP(cppad_nlp);
00046
00047 std::cout << "solve.x = " << solve.x << std::endl;
00048
00049 return 0;
00050 }