00001 #include <stdio.h>
00002 #include <iostream>
00003 #include <sstream>
00004 #include <stdlib.h>
00005 #include <vector>
00006 #include <nlopt.h>
00007
00008 #include "nlopt_solver.h"
00009
00010
00011 int result = 0;
00012 NLoptSolver* nos_buf;
00013
00014 extern "C"{
00015 int get_result(){ return result+5 ; }
00016 }
00017
00018 extern "C"{
00019 int stop(){
00020 if ( nos_buf ) nos_buf->stop() ;
00021 return 0 ;
00022 }
00023 }
00024
00025 extern "C"{
00026 double* optimize(double* x,
00027 const double* x_min,
00028 const double* x_max,
00029 int (*f)(double*,double*), int (*df)(double*,double*),
00030 int (*g)(double*,double*), int (*dg)(double*,double*),
00031 int (*h)(double*,double*), int (*dh)(double*,double*),
00032 int m_x, int m_g, int m_h,
00033 double ftol, double xtol, double eqthre, int max_eval, double max_time,
00034 int log,
00035 Optimization::NLopt::Algorithm algorithm,
00036 double* fbuf, double* dfbuf, double* gbuf, double* dgbuf, double* hbuf, double* dhbuf) {
00037 NLoptSolver nos(x, x_min, x_max, f, df, g, dg, h, dh, m_x, m_g, m_h, ftol,xtol,eqthre,max_eval,max_time,
00038 (Optimization::NLopt::Algorithm) algorithm);
00039 nos_buf = &nos ;
00040 nos.fbuf = fbuf ; nos.dfbuf = dfbuf ;
00041 nos.gbuf = gbuf ; nos.dgbuf = dgbuf ;
00042 nos.hbuf = hbuf ; nos.dhbuf = dhbuf ;
00043 result = nos.Optimize();
00044 if ( log ) nos.output_result(result) ;
00045 nos_buf = 0 ;
00046 return x;
00047 }
00048 }