File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ template <int ITER_PERIOD = 1 << 20 >
2+ struct AnnealingParameters {
3+ const double start_temp;
4+ const double end_temp;
5+ double cur_temp;
6+ double ln_p[ITER_PERIOD];
7+ AnnealingParameters (double start_temp, double end_temp, Rand& rnd)
8+ : start_temp(start_temp), end_temp(end_temp), cur_temp(start_temp) {
9+ for (int i=0 ; i<ITER_PERIOD; i++) {
10+ ln_p[i] = log (rnd.NextDouble ());
11+ }
12+ }
13+
14+ inline void update_temp_linear (double ratio) {
15+ cur_temp = start_temp + (end_temp - start_temp) * ratio;
16+ }
17+
18+ inline void update_temp_pow (double ratio) {
19+ cur_temp = start_temp * pow (end_temp / start_temp, ratio);
20+ }
21+
22+ // p < exp(diff / temp) を変形すると、diff > temp * ln_p
23+ // diff がこの値を超えていたら採用できる
24+ inline bool is_acceptable (int iter, int diff) const {
25+ return diff > cur_temp * ln_p[iter % ITER_PERIOD];
26+ }
27+ };
You can’t perform that action at this time.
0 commit comments