00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef O2SCL_SIM_ANNEAL_H
00024 #define O2SCL_SIM_ANNEAL_H
00025
00026 #include <iostream>
00027 #include <o2scl/collection.h>
00028 #include <o2scl/multi_min.h>
00029 #include <o2scl/tptr_schedule.h>
00030 #include <o2scl/rnga.h>
00031 #include <o2scl/gsl_rnga.h>
00032 #include <o2scl/tptr_geoseries.h>
00033
00034 #ifndef DOXYGENP
00035 namespace o2scl {
00036 #endif
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #ifdef DOXYGENP
00057 template<class param_t, class func_t, class vec_t=ovector_view,
00058 class rng_t=gsl_rnga> class sim_anneal :
00059 public multi_min<param_t,func_t,dfunc_t,vec_t>
00060 #else
00061 template<class param_t, class func_t, class vec_t=ovector_view,
00062 class rng_t=gsl_rnga> class sim_anneal :
00063 public multi_min<param_t,func_t,func_t,vec_t>
00064 #endif
00065 {
00066
00067 public:
00068
00069 sim_anneal() {
00070 tp=&def_schedule;
00071
00072 this->ntrial=100;
00073 }
00074
00075 virtual ~sim_anneal() {}
00076
00077
00078
00079
00080 virtual int mmin(size_t nvar, vec_t &x, double &fmin, param_t &pa,
00081 func_t &func)
00082 {
00083 set_err_ret("Empty base function in sim_anneal::mmin()",
00084 gsl_nobase);
00085 }
00086
00087
00088 int set_tptr_schedule(tptr_schedule<vec_t> &tr) {
00089 tp=&tr;
00090 return 0;
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 virtual int print_iter(size_t nv, vec_t &x, double y, int iter,
00104 double tptr, std::string comment)
00105 {
00106 if (this->verbose<=0) return 0;
00107
00108 size_t i;
00109 char ch;
00110
00111 std::cout << comment << " Iteration: " << iter << std::endl;
00112 text_out_file outs(&std::cout,79);
00113 outs.word_out("x:");
00114 for(i=0;i<nv;i++) outs.double_out(x[i]);
00115 outs.end_line();
00116 std::cout << "y: " << y << " Tptr: " << tptr << std::endl;
00117 if (this->verbose>1) {
00118 std::cout << "Press a key and type enter to continue. ";
00119 std::cin >> ch;
00120 }
00121
00122 return 0;
00123 }
00124
00125
00126 rng_t def_rng;
00127
00128
00129 virtual const char *type() { return "sim_anneal"; }
00130
00131
00132 tptr_geoseries<vec_t> def_schedule;
00133
00134 #ifndef DOXYGEN_INTERNAL
00135
00136 protected:
00137
00138
00139 tptr_schedule<vec_t> *tp;
00140
00141 #endif
00142
00143 };
00144
00145 #ifndef DOXYGENP
00146 }
00147 #endif
00148
00149 #endif
00150