From 6d037d5c5b4c1c855c407e68d2e59965e4dcf67b Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Wed, 22 Apr 2009 16:47:04 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@28 ed2142bd-67ad-457f-ba7c-d818d4011675 --- test/makefile | 10 ++++ test/test_optimizer.cpp | 155 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 test/makefile create mode 100644 test/test_optimizer.cpp (limited to 'test') diff --git a/test/makefile b/test/makefile new file mode 100644 index 0000000..9933620 --- /dev/null +++ b/test/makefile @@ -0,0 +1,10 @@ +targets=test_optimizer + +all:$(targets) + +test_optimizer:test_optimizer.cpp + g++ $< -o $@ -I .. -O3 + + +clean: + rm -f $(targets) *.o *~ diff --git a/test/test_optimizer.cpp b/test/test_optimizer.cpp new file mode 100644 index 0000000..b6d70a7 --- /dev/null +++ b/test/test_optimizer.cpp @@ -0,0 +1,155 @@ +#include +#include +//#include +#include +#include +using namespace opt_utilities; +using namespace std; + + +class foo1 + :public func_obj > +{ + foo1* do_clone()const + { + return new foo1(*this); + } + + double do_eval(const vector& p) + { + double result=0; + for(int i=0;i!=p.size();++i) + { + result+=p[i]*p[i]; + } + return result; + } +}; + +class foo2 + :public func_obj > +{ + foo2* do_clone()const + { + return new foo2(*this); + } + + double do_eval(const vector& p) + { + double result=0; + for(int i=0;i!=p.size();++i) + { + result+=(i+1)*p[i]*p[i]; + } + return result; + } +}; + +class foo3 + :public func_obj > +{ + foo3* do_clone()const + { + return new foo3(*this); + } + + double do_eval(const vector& p) + { + double result=0; + for(int i=0;i > +{ + foo4* do_clone()const + { + return new foo4(*this); + } + + double do_eval(const vector& p) + { + double result=0; + for(int i=0;i > +{ + foo5* do_clone()const + { + return new foo5(*this); + } + + double do_eval(const vector& p) + { + const double pi=3.14159265358979323846; + double result=0; + result+=10*p.size(); + for(int i=0;i >& fo, + const opt_method >& optm) +{ + const int problem_size=5; + optimizer > opt; + opt.set_opt_method(optm); + opt.set_func_obj(fo); + vector p(problem_size); + for(int i=0;i > pm_simplex; + powell_method > pm_powell; + test_opt(foo1(),pm_powell); + test_opt(foo2(),pm_powell); + test_opt(foo3(),pm_powell); + test_opt(foo4(),pm_powell); + test_opt(foo5(),pm_powell); +} -- cgit v1.2.2