pub struct HtmlReportObserver { /* private fields */ }Expand description
Observer that generates an HTML execution report with metrics and charts.
§Output layout
By default, each run is written to:
target/observers_outputs/reports/<algorithm_slug>/run_<timestamp_ms>_<pid>/report.html.
Use HtmlReportObserver::with_flat_output if you prefer a flat output
folder without per-run subdirectories.
§Typical usage
Create and register the observer in your algorithm before calling run().
At the end of execution, the observer prints a clickable terminal link to
the generated HTML file.
Implementations§
Source§impl HtmlReportObserver
impl HtmlReportObserver
Sourcepub fn new(base_output_path: PathBuf) -> Self
pub fn new(base_output_path: PathBuf) -> Self
Creates a report observer with a custom base output directory.
The generated report path is:
<base>/<algorithm_slug>/run_<timestamp_ms>_<pid>/report.html.
Sourcepub fn new_default() -> Self
pub fn new_default() -> Self
Creates a report observer with default base directory:
target/observers_outputs/reports.
Examples found in repository?
15fn main() {
16 let seed = seed_from_cli_or(42);
17
18 let problem = KnapsackBuilder::new()
19 .with_capacity(90.0)
20 .add_item(12.0, 24.0)
21 .add_item(22.0, 33.0)
22 .add_item(41.0, 80.0)
23 .build();
24
25 let parameters = HillClimbingParameters::new(
26 BitFlipMutation::new(),
27 0.10,
28 TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(120)]),
29 )
30 .with_seed(seed);
31 let mut algorithm = HillClimbing::new(parameters);
32
33 algorithm.add_observer(Box::new(ConsoleObserver::new(true)));
34 algorithm.add_observer(Box::new(ChartObserver::new_default()));
35 algorithm.add_observer(Box::new(HtmlReportObserver::new_default()));
36
37 let result = algorithm
38 .run(&problem)
39 .expect("Hill Climbing run failed");
40
41 if let Some(best) = result.best_solution(&problem) {
42 println!(
43 "Hill-Climbing finished (seed={}). Best fitness={:.4}",
44 seed,
45 best.quality_value()
46 );
47 } else {
48 println!("Hill-Climbing finished with no solutions (seed={})", seed);
49 }
50}More examples
196fn main() {
197 if print_help_if_requested() {
198 return;
199 }
200
201 let seed = seed_from_cli_or(42);
202 let input_path = resolve_input_path();
203 let input_format = resolve_input_format(&input_path).unwrap_or_else(|msg| panic!("{}", msg));
204 let records_path = records_path_for_format(input_format);
205 let weight_key = weight_key_for_format(input_format);
206 let value_key = value_key_for_format(input_format);
207 let (capacity, row_limit) =
208 resolve_capacity_and_limit(&input_path, input_format).unwrap_or_else(|msg| panic!("{}", msg));
209
210 let records = read_records_from_input(&input_path, input_format, records_path)
211 .unwrap_or_else(|msg| panic!("{}", msg));
212
213 let (problem, loaded_items) =
214 build_knapsack_from_records(&records, capacity, row_limit, weight_key, value_key)
215 .unwrap_or_else(|msg| panic!("{}", msg));
216
217 // Build the algorithm
218 let parameters = GeneticAlgorithmParameters::new(
219 80,
220 0.85,
221 0.04,
222 SinglePointCrossover::new(),
223 BitFlipMutation::new(),
224 BinaryTournamentSelection::new(),
225 TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(60)]),
226 )
227 .with_seed(seed);
228
229 let chart_observer = ChartObserver::new_default();
230 let html_observer = HtmlReportObserver::new_default();
231
232 let mut algorithm = GeneticAlgorithm::new(parameters);
233 algorithm.add_observer(Box::new(chart_observer));
234 algorithm.add_observer(Box::new(html_observer));
235 let result = algorithm.run(&problem).expect("Large CSV GA run failed");
236
237 if let Some(best) = result.best_solution(&problem) {
238 println!(
239 "Large dataset GA demo finished (seed={}). input='{}', format={:?}, capacity={}, limit={}, records_path='{}', weight_key='{}', value_key='{}', items={}, best fitness={:.4}",
240 seed,
241 input_path.display(),
242 input_format,
243 capacity,
244 row_limit,
245 records_path,
246 weight_key,
247 value_key,
248 loaded_items,
249 best.quality_value()
250 );
251 } else {
252 println!("Large CSV GA demo finished with no solutions (seed={})", seed);
253 }
254}Sourcepub fn with_flat_output(self) -> Self
pub fn with_flat_output(self) -> Self
Disables automatic per-run subdirectories.
When enabled (default), each run gets its own timestamped folder.
When disabled, the report is written directly to
<base_output_path>/report.html.