@@ -310,24 +310,47 @@ impl<G: HillClimbGenotype, F: Fitness<Genotype = G>, SR: StrategyReporter<Genoty
310
310
. add_duration ( StrategyAction :: SetupAndCleanup , now. elapsed ( ) ) ;
311
311
312
312
match self . config . variant {
313
- HillClimbVariant :: Stochastic => self . fitness . call_for_state_chromosome (
314
- & self . genotype ,
315
- & mut self . state ,
316
- & self . config ,
317
- ) ,
313
+ HillClimbVariant :: Stochastic => {
314
+ self . fitness . call_for_state_chromosome (
315
+ & self . genotype ,
316
+ & mut self . state ,
317
+ & self . config ,
318
+ ) ;
319
+ self . state . update_best_chromosome_from_state_chromosome (
320
+ & mut self . genotype ,
321
+ & self . config ,
322
+ & mut self . reporter ,
323
+ ) ;
324
+ }
318
325
HillClimbVariant :: SteepestAscent => {
319
- // skip so calculate_for_chromosome does not have to be implemented on Fitness
326
+ // population of one
327
+ self . state . population . chromosomes . push (
328
+ self . genotype
329
+ . chromosome_cloner ( self . state . chromosome . as_ref ( ) . unwrap ( ) ) ,
330
+ ) ;
331
+ // calculate_for_chromosome does not have to be implemented on Fitness
332
+ self . fitness . call_for_state_population (
333
+ & self . genotype ,
334
+ & mut self . state ,
335
+ & self . config ,
336
+ None ,
337
+ ) ;
338
+ self . state . update_best_chromosome_from_state_population (
339
+ & mut self . genotype ,
340
+ & self . config ,
341
+ & mut self . reporter ,
342
+ & mut self . rng ,
343
+ ) ;
344
+ // cleanup population
345
+ self . genotype
346
+ . chromosome_destructor_truncate ( & mut self . state . population . chromosomes , 0 ) ;
320
347
}
321
348
}
322
349
323
- // best by definition
350
+ // in case fitness_score is None, set best by definition anyway
324
351
self . state . best_generation = self . state . current_generation ;
325
- self . state . best_fitness_score = self . state . chromosome . as_ref ( ) . unwrap ( ) . fitness_score ( ) ;
326
352
self . genotype
327
353
. save_best_genes ( self . state . chromosome . as_ref ( ) . unwrap ( ) ) ;
328
-
329
- self . reporter
330
- . on_new_best_chromosome ( & self . genotype , & self . state , & self . config ) ;
331
354
}
332
355
pub fn cleanup ( & mut self , fitness_thread_local : Option < & mut ThreadLocal < RefCell < F > > > ) {
333
356
let now = Instant :: now ( ) ;
0 commit comments