Skip to content

Commit

Permalink
solver: print some statistics when a solution is found
Browse files Browse the repository at this point in the history
  • Loading branch information
arbimo committed Mar 3, 2025
1 parent 80f2eff commit bb8d280
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion solver/src/solver/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use env_param::EnvParam;
use std::collections::BTreeMap;
use std::fmt::{Display, Error, Formatter};
use std::ops::{Index, IndexMut};
use std::time::Duration;
use std::time::{Duration, Instant};

static PRINT_RUNNING_STATS: EnvParam<bool> = EnvParam::new("ARIES_PRINT_RUNNING_STATS", "false");

Expand All @@ -27,6 +27,8 @@ pub struct Stats {
pub per_module_stat: BTreeMap<ReasonerId, ModuleStat>,
running: RunningStats,
best_cost: Option<IntCst>,
/// Timestamp marking the object creation (taken as the time at which the solver is started)
creation_timestamp: Instant,
}

#[derive(Clone, Default)]
Expand Down Expand Up @@ -56,6 +58,7 @@ impl Stats {
per_module_stat: per_mod,
running: Default::default(),
best_cost: None,
creation_timestamp: Instant::now(),
}
}

Expand All @@ -75,6 +78,12 @@ impl Stats {
pub fn add_solution(&mut self, cost: IntCst) {
self.num_solutions += 1;
self.best_cost = Some(cost);
println!(
"SOLUTION FOUND: cost: {cost} #decisions: {} #conflicts: {} wall-clock: {}ms",
self.num_decisions,
self.num_conflicts,
self.creation_timestamp.elapsed().as_millis()
);
self.print_running("*");
}

Expand Down

0 comments on commit bb8d280

Please sign in to comment.