00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _SIMAN_H_
00011 #define _SIMAN_H_
00012
00013 #include "linalg.h"
00014
00015 inline double zero(matrix const& x) { return 0.0; }
00016
00017 class AbstractFunction {
00018 public:
00019
00020 virtual double operator()(matrix const& args)=0;
00021
00022 };
00023
00024 class Function {
00025 public:
00026 Function() { funk=zero; }
00027 Function(double (*f)(matrix const&), unsigned n) { funk = f; dim=n; }
00028 virtual ~Function() {}
00029 double operator()(matrix const& args) const {
00030 return funk(args);
00031 }
00032 unsigned getdim() const { return dim; }
00033 protected:
00034 double (*funk)(matrix const&);
00035 unsigned dim;
00036 };
00037
00038
00039 class SimAnneal {
00040 public:
00041 SimAnneal(Function *ff, matrix simplex,
00042 double temptr=0.01, unsigned it=100, double tol=0.001,
00043 long s=12345, unsigned steps=10);
00044
00045 ~SimAnneal() { }
00046 void optimize();
00047 void anneal();
00048 void set_tt(double t) { tt = -t; }
00049 void calcyb() { yb = (*funk)(pb); }
00050 double funceval(matrix &x) { return((*funk)(x)); }
00051 void set_simplex(matrix const& simplex) {
00052
00053
00054 p = simplex;
00055 y = pval(simplex);
00056 }
00057 matrix get_pb() const { return pb; }
00058 double get_yb() const { return yb; }
00059 unsigned getdim() { return ndim; }
00060
00061
00062 private:
00063 Function *funk;
00064
00065 unsigned ndim;
00066
00067 long seed;
00068 double ftol;
00069 int iter;
00070 unsigned static_iter;
00071 double tt;
00072
00073
00074 matrix psum;
00075 matrix pb;
00076 double yb;
00077
00078 matrix p;
00079 matrix y;
00080
00081 unsigned nosteps;
00082
00083
00084 double amotsa(int ihi, double &yhi, double const fac);
00085 void calc_psum();
00086 void amebsa();
00087 matrix pval(matrix const& pp);
00088
00089 };
00090
00091
00092
00093
00094
00095 matrix newsimplex(matrix const& pb, double epsilon=0.5);
00096
00097 #endif // _SIMAN_H_