Skip to content

Commit

Permalink
Add StageManager::segment_progress_ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
shnarazk committed Sep 21, 2024
1 parent 5ebd423 commit 50603c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/cdb/ema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct ProgressLBD {
impl Default for ProgressLBD {
fn default() -> ProgressLBD {
ProgressLBD {
ema: Ewa2::new(0.0).with_value(16.0),
ema: Ewa2::new(0.0),
num: 0,
sum: 0,
}
Expand All @@ -24,7 +24,7 @@ impl Default for ProgressLBD {
impl Instantiate for ProgressLBD {
fn instantiate(_config: &Config, _: &CNFDescription) -> Self {
ProgressLBD {
ema: Ewa2::new(0.0).with_slow(LBD_EWA_SLOW).with_value(16.0),
ema: Ewa2::new(0.0).with_slow(LBD_EWA_SLOW),
..ProgressLBD::default()
}
}
Expand Down
12 changes: 0 additions & 12 deletions src/primitive/ema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ pub trait EmaIF {
}
}

pub trait EmaSingleIF: EmaIF {
/// return the current value.
fn get(&self) -> f64 {
self.get_fast()
}
}

/// API for Exponential Moving Average, EMA, like `get`, `reset`, `update` and so on.
pub trait EmaMutIF: EmaIF {
/// the type of the argument of `update`.
Expand Down Expand Up @@ -437,9 +430,4 @@ impl<const N: usize> Ewa2<N> {
self.sx = 1.0 - self.se;
self
}
pub fn with_value(mut self, val: f64) -> Self {
self.ema.fast = val;
self.ema.slow = val;
self
}
}
19 changes: 12 additions & 7 deletions src/solver/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,18 @@ impl StageManager {
pub fn current_segment(&self) -> usize {
self.segment
}
/// returns a recommending number of redicible learnt clauses, based on
/// the length of span.
pub fn num_reducible(&self, reducing_factor: f64) -> usize {
let span: f64 = self.span_ema.get();
let keep = span.powf(1.0 - reducing_factor) as usize;
(span as usize).saturating_sub(keep)
}
/// returns the maximum factor so far.
/// None: `luby_iter.max_value` holds the maximum value so far.
/// This means it is the value found at the last segment.
/// So the current value should be the next value, which is the double.
pub fn max_scale(&self) -> usize {
self.max_scale_of_segment
}
/// returns (0, 1]
pub fn segment_progress_ratio(&self) -> f64 {
(2 * (self.cycle - self.segment_starting_cycle + 1)) as f64
/ self.max_scale_of_segment as f64
}
pub fn cycle_starting_stage(&self) -> usize {
self.cycle_starting_stage
}
Expand All @@ -181,4 +179,11 @@ impl StageManager {
pub fn set_span_base(&mut self, span_base: f64) {
self.span_base = span_base;
}
/// returns a recommending number of redicible learnt clauses, based on
/// the length of span.
pub fn num_reducible(&self, reducing_factor: f64) -> usize {
let span: f64 = self.span_ema.get();
let keep = span.powf(1.0 - reducing_factor) as usize;
(span as usize).saturating_sub(keep)
}
}
6 changes: 5 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,11 @@ impl StateIF for State {
println!(
// "\x1B[2K misc|ccut:{}, vdcy:{}, core:{}, /ppc:{}",
"\x1B[2K{:>12}|ccut:{}, vdcy:{}, core:{}, /ppc:{}",
format!("Luby{}", self.stm.current_segment(),),
format!(
"Luby{},{:>4.2}",
self.stm.current_segment(),
self.stm.segment_progress_ratio(),
),
fm!(
"{:>9.4}",
self,
Expand Down

0 comments on commit 50603c1

Please sign in to comment.