Skip to content

Commit afa0e3d

Browse files
committed
annealing parameters
1 parent 70fbb07 commit afa0e3d

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

marathon/annealing_parameters.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
};

0 commit comments

Comments
 (0)