55 f64 cost, prev_cost, delta_cost, initial_cost, best_cost;
56 f64 random_accept, delta_cost_over_t;
57 f64 total_increase=0.0, average_increase;
59 u32 number_of_increases = 0;
60 u32 accepted_this_temperature;
61 u32 best_saves_this_temperature;
69 fformat(stdout,
"Initial cost %.2f\n", initial_cost);
73 accepted_this_temperature = 0;
74 best_saves_this_temperature = 0;
84 delta_cost = cost - prev_cost;
88 accept = delta_cost < 0.0;
90 accept = delta_cost > 0.0;
98 fformat (stdout,
"New best cost %.2f\n", cost);
101 best_saves_this_temperature++;
104 accepted_this_temperature++;
111 delta_cost : -delta_cost;
113 number_of_increases++;
123 delta_cost_over_t = delta_cost / t;
125 if (random_accept < exp (-delta_cost_over_t))
127 accepted_this_temperature++;
136 fformat (stdout,
"Temp %.2f, cost %.2f, accepted %d, bests %d\n", t,
137 prev_cost, accepted_this_temperature,
138 best_saves_this_temperature);
139 fformat (stdout,
"Improvement %.2f\n", initial_cost - prev_cost);
140 fformat (stdout,
"-------------\n");
150 average_increase = total_increase / (
f64) number_of_increases;
152 average_increase / 0.22 ;
159 fformat (stdout,
"Average cost increase from a bad move: %.2f\n",
161 fformat (stdout,
"Suggested t0 = %.2f\n",
sll srl srl sll sra u16x4 i
u32 number_of_configurations_per_temperature
u32 number_of_temperatures
void(* anneal_restore_best_configuration)(void *opaque)
always_inline f64 random_f64(u32 *seed)
Generate f64 random number in the interval [0,1].
void(* anneal_new_configuration)(void *opaque)
#define CLIB_ANNEAL_MINIMIZE
#define CLIB_ANNEAL_VERBOSE
f64 suggested_initial_temperature
void clib_anneal(clib_anneal_param_t *p)
f64(* anneal_metric)(void *opaque)
void(* anneal_restore_previous_configuration)(void *opaque)
void(* anneal_save_best_configuration)(void *opaque)