test.cpp
Go to the documentation of this file.
00001 #include <nlopt.hpp>
00002 #include <nlopt.h>
00003 #include <vector>
00004 #include <iostream>
00005 
00006 //#include "my_param.h"
00007 //#include "eus_function.cpp"
00008 #include "nlopt_solver.h"
00009 
00010 
00011 int f(double* x, double* ret)
00012 {
00013         ret[0] = sqrt(x[1]) ;
00014         return 0 ;
00015  }
00016 
00017 int df(double* x, double* grad){
00018         grad[0] = 0.0;
00019         grad[1] = 0.5 / sqrt(x[1]);
00020         return 0;
00021 }
00022 
00023 int g1(double* x, double* ret)
00024 {
00025         ret[0] = x[0] + x[1] - 10 ;
00026         return 0 ;
00027 }
00028 
00029 int dg1(double* x, double* grad) {
00030         grad[0] = grad[1] = 1 ;
00031         return 0;
00032 }
00033 
00034 int h1(double* x, double* ret) {
00035         double a = 2, b = 0;
00036         ret[0] = ((a * x[0] + b) * (a * x[0] + b) * (a * x[0] + b) - x[1]);
00037         return 0;
00038 }
00039 
00040 int dh1(double* x, double* grad) {
00041         double a = 2, b = 0;
00042         grad[0] = 3 * a * (a * x[0] + b) * (a * x[0] + b);
00043         grad[1] = -1.0;
00044         return 0;
00045 }
00046 
00047 int nop(double* x, double* grad) {
00048         return 0;
00049 }
00050 
00051 int main(){
00052         double x[2] = { 1, 9 };
00053         double x_min[2] = {0,0} ;
00054         double x_max[2] = {10,10} ;
00055         NLoptSolver nos(x,x_min,x_max,f,df,g1,dg1,h1,dh1,2,1,1,1e-16,1e-8,1e-4,-1,-1,Optimization::NLopt::COBYLA) ;
00056         //NLoptSolver nos(x,x_min,x_max,f,df,nop,nop,nop,nop,2,1,1,Optimization::NLopt::DIRECT) ;
00057         nos.output_result(nos.Optimize()) ;
00058         return 0 ;
00059 }


eus_nlopt
Author(s):
autogenerated on Wed Sep 16 2015 04:37:02