Skip to content

Commit

Permalink
Simplify code requiring some features
Browse files Browse the repository at this point in the history
  • Loading branch information
shnarazk committed Dec 14, 2024
1 parent a992ed8 commit 455828f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/assign/learning_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ impl ActivityIF<VarId> for AssignStack {
fn reward_at_analysis(&mut self, vi: VarId) {
self.var[vi].turn_on(FlagVar::USED);
}
#[cfg(feature = "spin")]
#[inline]
fn reward_at_assign(&mut self, vi: VarId) {
#[cfg(feature = "spin")]
if let Some(b) = self.var[vi].assign {
self.var[vi].spin.update(b, self.tick);
}
}
#[cfg(not(feature = "spin"))]
#[inline]
fn reward_at_assign(&mut self, _vi: VarId) {}
#[inline]
fn reward_at_propagation(&mut self, _vi: VarId) {}
#[inline]
Expand Down
24 changes: 19 additions & 5 deletions src/bin/splw.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#[cfg(not(feature = "graph_view"))]
fn main() {
panic!("Not compiled with required features.");
}

#[cfg(feature = "graph_view")]
#[allow(unused_imports)]
use {
crossterm::{
Expand Down Expand Up @@ -34,6 +40,7 @@ use {
},
};

#[cfg(feature = "graph_view")]
#[derive(Debug)]
pub struct App {
solver: Splr,
Expand All @@ -49,6 +56,7 @@ pub struct App {
var_spin_shift_stats: [u64; 21],
}

#[cfg(feature = "graph_view")]
impl App {
fn solver(solver: Splr, state: SearchState) -> Self {
App {
Expand Down Expand Up @@ -250,6 +258,7 @@ impl App {
}
}

#[cfg(feature = "graph_view")]
impl App {
/// var activity histogram
fn var_activity_bar_chart(&self) -> BarChart<'_> {
Expand Down Expand Up @@ -400,6 +409,7 @@ impl App {
}
}

#[cfg(feature = "graph_view")]
fn main() -> Result<(), Box<dyn Error>> {
let mut config = Config::default();
config.inject_from_args();
Expand Down Expand Up @@ -478,12 +488,13 @@ fn main() -> Result<(), Box<dyn Error>> {
Ok(())
}

const RED: &str = "\x1B[001m\x1B[031m";
const GREEN: &str = "\x1B[001m\x1B[032m";
const BLUE: &str = "\x1B[001m\x1B[034m";
const RESET: &str = "\x1B[000m";

#[cfg(feature = "graph_view")]
fn colored(v: Result<bool, &SolverError>, no_color: bool) -> Cow<'static, str> {
const RED: &str = "\x1B[001m\x1B[031m";
const GREEN: &str = "\x1B[001m\x1B[032m";
const BLUE: &str = "\x1B[001m\x1B[034m";
const RESET: &str = "\x1B[000m";

if no_color {
match v {
Ok(false) => Cow::Borrowed("s UNSATISFIABLE"),
Expand All @@ -498,6 +509,8 @@ fn colored(v: Result<bool, &SolverError>, no_color: bool) -> Cow<'static, str> {
}
}
}

#[cfg(feature = "graph_view")]
fn save_result<S: AsRef<str> + std::fmt::Display>(
s: &mut Splr,
res: &SolverResult,
Expand Down Expand Up @@ -616,6 +629,7 @@ fn save_result<S: AsRef<str> + std::fmt::Display>(
}
}

#[cfg(feature = "graph_view")]
fn report(s: &Splr, out: &mut dyn io::Write) -> std::io::Result<()> {
let state = &s.state;
let elapsed: Duration = s.state.start.elapsed();
Expand Down

0 comments on commit 455828f

Please sign in to comment.