test.cpp
Go to the documentation of this file.
1 #include <nlopt.hpp>
2 #include <nlopt.h>
3 #include <vector>
4 #include <iostream>
5 
6 //#include "my_param.h"
7 //#include "eus_function.cpp"
8 #include "nlopt_solver.h"
9 
10 
11 int f(double* x, double* ret)
12 {
13  ret[0] = sqrt(x[1]) ;
14  return 0 ;
15  }
16 
17 int df(double* x, double* grad){
18  grad[0] = 0.0;
19  grad[1] = 0.5 / sqrt(x[1]);
20  return 0;
21 }
22 
23 int g1(double* x, double* ret)
24 {
25  ret[0] = x[0] + x[1] - 10 ;
26  return 0 ;
27 }
28 
29 int dg1(double* x, double* grad) {
30  grad[0] = grad[1] = 1 ;
31  return 0;
32 }
33 
34 int h1(double* x, double* ret) {
35  double a = 2, b = 0;
36  ret[0] = ((a * x[0] + b) * (a * x[0] + b) * (a * x[0] + b) - x[1]);
37  return 0;
38 }
39 
40 int dh1(double* x, double* grad) {
41  double a = 2, b = 0;
42  grad[0] = 3 * a * (a * x[0] + b) * (a * x[0] + b);
43  grad[1] = -1.0;
44  return 0;
45 }
46 
47 int nop(double* x, double* grad) {
48  return 0;
49 }
50 
51 int main(){
52  double x[2] = { 1, 9 };
53  double x_min[2] = {0,0} ;
54  double x_max[2] = {10,10} ;
55  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) ;
56  //NLoptSolver nos(x,x_min,x_max,f,df,nop,nop,nop,nop,2,1,1,Optimization::NLopt::DIRECT) ;
57  nos.output_result(nos.Optimize()) ;
58  return 0 ;
59 }
NLoptSolver
Definition: nlopt_solver.h:5
nlopt_solver.h
dg1
int dg1(double *x, double *grad)
Definition: test.cpp:29
NLoptSolver::Optimize
int Optimize()
Definition: nlopt_solver.cpp:332
g1
int g1(double *x, double *ret)
Definition: test.cpp:23
main
int main()
Definition: test.cpp:51
nop
int nop(double *x, double *grad)
Definition: test.cpp:47
dh1
int dh1(double *x, double *grad)
Definition: test.cpp:40
NLoptSolver::output_result
void output_result(int result)
Definition: nlopt_solver.h:69
h1
int h1(double *x, double *ret)
Definition: test.cpp:34
sqrt
double sqrt()
Optimization::NLopt::COBYLA
@ COBYLA
Definition: my_param.h:58
df
int df(double *x, double *grad)
Definition: test.cpp:17
f
int f(double *x, double *ret)
Definition: test.cpp:11
a
char a[26]


eus_nlopt
Author(s):
autogenerated on Wed Jan 24 2024 04:05:11