Skip to content

Commit

Permalink
JigSAT: Add target phases
Browse files Browse the repository at this point in the history
  • Loading branch information
sarsko committed Jul 15, 2022
1 parent 9be58be commit 7953205
Show file tree
Hide file tree
Showing 18 changed files with 364 additions and 130 deletions.
1 change: 1 addition & 0 deletions JigSAT/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ rpath = false
[dependencies]
clap = "2.33.3"
log = "0.4"
rand = "0.8.5"

[dev-dependencies]
termcolor = "1.1"
Binary file modified JigSAT/StarExec/bin/jigsat
Binary file not shown.
Binary file modified JigSAT/StarExec/jigsat.zip
Binary file not shown.
20 changes: 18 additions & 2 deletions JigSAT/src/clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ impl Clause {
// Does not set lbd !
// Inits search to 1 and mark to 0. Sets abstraction.
pub(crate) fn new(lits: Vec<Lit>) -> Clause {
Clause { deleted: false, can_be_deleted: true, lbd: 0, search: 1, mark: 0, abstraction: calc_abstraction(&lits), lits }
Clause {
deleted: false,
can_be_deleted: true,
lbd: 0,
search: 1,
mark: 0,
abstraction: calc_abstraction(&lits),
lits,
}
}

pub(crate) fn swap(&mut self, i: usize, j: usize) {
Expand Down Expand Up @@ -143,7 +151,15 @@ impl Clause {
}

pub(crate) fn clause_from_vec(vec: &Vec<Lit>) -> Clause {
Clause { deleted: false, can_be_deleted: true, lbd: 0, search: 1, mark: 0, abstraction: calc_abstraction(vec), lits: vec.clone() }
Clause {
deleted: false,
can_be_deleted: true,
lbd: 0,
search: 1,
mark: 0,
abstraction: calc_abstraction(vec),
lits: vec.clone(),
}
}

#[inline(always)]
Expand Down
14 changes: 12 additions & 2 deletions JigSAT/src/conflict_analysis.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
use core::panic;

use crate::{clause::*, decision::*, formula::*, lit::*, minimize::*, solver::{Solver, SearchMode}, trail::*};
use crate::{
clause::*,
decision::*,
formula::*,
lit::*,
minimize::*,
solver::{SearchMode, Solver},
trail::*,
};

#[derive(Debug)]
pub enum Conflict {
Expand All @@ -9,7 +17,9 @@ pub enum Conflict {
Learned(u32, Clause),
}

pub(crate) fn analyze_conflict(f: &Formula, trail: &Trail, cref: usize, decisions: &mut impl Decisions, s: &mut Solver) -> Conflict {
pub(crate) fn analyze_conflict(
f: &Formula, trail: &Trail, cref: usize, decisions: &mut impl Decisions, s: &mut Solver,
) -> Conflict {
let decisionlevel = trail.decision_level();
if decisionlevel == 0 {
return Conflict::Ground;
Expand Down
26 changes: 11 additions & 15 deletions JigSAT/src/decision.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use crate::{assignments::*, formula::*, util::*, trail::*};
use std::{ops::{Index, IndexMut}, collections::BinaryHeap};
use crate::{assignments::*, formula::*, trail::*, util::*};
use std::{
collections::BinaryHeap,
ops::{Index, IndexMut},
};

const INVALID: usize = usize::MAX;
pub(crate) trait Decisions {
fn new(f: &Formula) -> Self where Self:Sized;
fn new(f: &Formula) -> Self
where
Self: Sized;

fn bump_vec_of_vars(&mut self, f: &Formula, v: Vec<usize>);

Expand All @@ -27,7 +32,6 @@ pub struct Node {
pub ts: usize,
}


impl Default for Node {
fn default() -> Self {
Node { next: usize::MAX, prev: usize::MAX, ts: 0 }
Expand Down Expand Up @@ -90,7 +94,6 @@ impl VMTF {
VMTF { linked_list, timestamp: f.num_vars + 1, start: head, search: head }
}


fn rescore(&mut self, _f: &Formula) {
let mut curr_score = self.linked_list.len();
let mut curr = self.start;
Expand Down Expand Up @@ -253,11 +256,7 @@ impl IndexMut<usize> for Heap {

impl Default for Heap {
fn default() -> Self {
Heap {
activity: Vec::new(),
heap: Vec::new(),
indices: Vec::new(),
}
Heap { activity: Vec::new(), heap: Vec::new(), indices: Vec::new() }
}
}

Expand Down Expand Up @@ -365,7 +364,6 @@ impl Heap {
}
self[idx] = x;
self.indices[x] = idx;

}

fn remove_min(&mut self) -> usize {
Expand Down Expand Up @@ -405,7 +403,6 @@ impl VSIDS {
}
}


impl Decisions for VSIDS {
fn new(formula: &Formula) -> Self {
let mut vsids = VSIDS::default();
Expand All @@ -414,7 +411,7 @@ impl Decisions for VSIDS {
vsids
}

fn get_next(&mut self, a: &Assignments, _f: &Formula) -> Option<usize> {
fn get_next(&mut self, a: &Assignments, _f: &Formula) -> Option<usize> {
while !self.empty() {
let next = self.remove_min();
if a[next] >= 2 {
Expand Down Expand Up @@ -468,7 +465,6 @@ impl Decisions for VSIDS {
fn bump_vec_of_vars(&mut self, f: &Formula, v: Vec<usize>) {}
}


/*
impl Decisions {
pub(crate) fn new(formula: &Formula) -> Self {
Expand Down Expand Up @@ -502,4 +498,4 @@ impl Decisions {
}
}
*/
*/
7 changes: 3 additions & 4 deletions JigSAT/src/formula.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{assignments::*, clause::*, solver::*, trail::*, watches::*, solver_types::*, lit::*};
use crate::{assignments::*, clause::*, lit::*, solver::*, solver_types::*, trail::*, watches::*};

use log::debug;
use std::{ops::{Index, IndexMut}};
use std::ops::{Index, IndexMut};
pub struct Formula {
pub clauses: Vec<Clause>,
learnt_core: Vec<Cref>,
Expand Down Expand Up @@ -164,7 +164,7 @@ impl Formula {
if self.learnt_core.len() == 0 {
return;
}
self.learnt_core.sort_unstable_by(|a , b | self.clauses[*a].less_than(&self.clauses[*b]));
self.learnt_core.sort_unstable_by(|a, b| self.clauses[*a].less_than(&self.clauses[*b]));
//s.max_len += self.len() + 300;
//self.num_reduced += 1;
if self[self.learnt_core[self.learnt_core.len() / 2]].lbd <= 3 {
Expand All @@ -189,7 +189,6 @@ impl Formula {
clause.can_be_deleted = true;
i += 1;
}

}

/*
Expand Down
7 changes: 4 additions & 3 deletions JigSAT/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ mod decision;
mod formula;
mod lit;
mod minimize;
mod modes;
pub mod parser;
mod preprocess;
mod restart;
mod solver;
mod solver_types;
mod target_phase;
mod trail;
mod unit_prop;
mod util;
mod watches;
mod modes;
mod restart;
mod solver_types;
5 changes: 0 additions & 5 deletions JigSAT/src/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ impl Lit {
(!self).code as usize
}

#[inline(always)]
pub fn phase_saved(idx: usize, assignments: &Assignments) -> Lit {
Lit { code: (idx << 1) as u32 | ((assignments[idx] == 1) as u32) }
}

// This is only called in the parser
pub fn new(idx: usize, polarity: bool) -> Lit {
Lit { code: (idx << 1) as u32 | (polarity as u32) }
Expand Down
21 changes: 14 additions & 7 deletions JigSAT/src/modes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// An attempt to separate out the modes and phases stuff

use crate::{solver::*, restart::*, decision::*};
use crate::{
decision::*,
restart::*,
solver::*,
target_phase::{self, TargetPhase},
};

pub(crate) fn adapt_solver(solver: &mut Solver, decisions: &mut impl Decisions) -> bool {
solver.adapt_strategies = false;
Expand All @@ -23,19 +28,21 @@ pub(crate) fn adapt_solver(solver: &mut Solver, decisions: &mut impl Decisions)
false
}

pub(crate) fn change_mode(solver: &mut Solver, decisions: &mut impl Decisions) {
pub(crate) fn change_mode(solver: &mut Solver, decisions: &mut impl Decisions, target_phase: &mut TargetPhase) {
match solver.search_mode {
SearchMode::Stable => {
println!("c Changing mode to Focus mode");
solver.restart.swap_mode();
decisions.set_var_decay(0.95);
solver.search_mode = SearchMode::Focus;
},
}
SearchMode::Focus => {
println!("c Changing mode to Stable mode");
solver.restart.swap_mode();
decisions.set_var_decay(0.75);
solver.search_mode = SearchMode::Stable;
// TODO: reset target_phase
},
_ => {},
target_phase.reset();
}
_ => {}
}
}
}
2 changes: 1 addition & 1 deletion JigSAT/src/preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use log::debug;
use std::collections::VecDeque;
//use std::collections::BinaryHeap;

use crate::{clause::*, formula::*, lit::*, trail::*, solver_types::*};
use crate::{clause::*, formula::*, lit::*, solver_types::*, trail::*};

#[derive(PartialEq)]
pub(crate) enum SubsumptionRes {
Expand Down
32 changes: 8 additions & 24 deletions JigSAT/src/restart.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use crate::solver::*;

pub(crate) enum RestartMode {
Expand All @@ -14,7 +13,6 @@ struct EMA {
period: usize,
}


impl EMA {
fn update(&mut self, next: f64) {
self.value += self.beta * (next - self.value);
Expand All @@ -30,13 +28,7 @@ impl EMA {
}
}
fn new(alpha: f64) -> Self {
EMA {
value: 1.0,
alpha,
beta: 1.0,
wait: 1,
period: 1,
}
EMA { value: 1.0, alpha, beta: 1.0, wait: 1, period: 1 }
}
}

Expand All @@ -51,7 +43,6 @@ pub(crate) struct Glucose {
block: f64,
num_restarts: usize,
num_blocked: usize,

}

impl Default for Glucose {
Expand Down Expand Up @@ -92,7 +83,9 @@ impl Glucose {
}

pub(crate) fn block_restart(&mut self, curr_confl: usize) -> bool {
if self.last_trail_size as f64 > self.block as f64 * self.ema_trail_wide.value && curr_confl >= self.minimum_conflicts_for_blocking_restarts {
if self.last_trail_size as f64 > self.block as f64 * self.ema_trail_wide.value
&& curr_confl >= self.minimum_conflicts_for_blocking_restarts
{
self.minimum_conflicts = curr_confl + 50;
self.num_blocked += 1;
return true;
Expand All @@ -110,12 +103,7 @@ struct Luby {

impl Default for Luby {
fn default() -> Self {
Luby {
num_restarts: 0,
step: 100,
curr_restarts: 0,
limit: 100,
}
Luby { num_restarts: 0, step: 100, curr_restarts: 0, limit: 100 }
}
}

Expand Down Expand Up @@ -152,16 +140,12 @@ impl Luby {
pub(crate) struct Restart {
restart: RestartMode,
luby: Luby,
pub(crate) glucose: Glucose
pub(crate) glucose: Glucose,
}

impl Restart {
pub(crate) fn new() -> Restart {
Restart {
restart: RestartMode::Glucose,
luby: Luby::default(),
glucose: Glucose::default(),
}
Restart { restart: RestartMode::Glucose, luby: Luby::default(), glucose: Glucose::default() }
}

pub(crate) fn set_restart_mode(&mut self, mode: RestartMode) {
Expand All @@ -185,7 +169,7 @@ impl Restart {
pub(crate) fn block_restart(&mut self, curr_confl: usize) -> bool {
match self.restart {
RestartMode::Glucose => self.glucose.block_restart(curr_confl),
RestartMode::Luby => { true },
RestartMode::Luby => true,
}
}
}
Loading

0 comments on commit 7953205

Please sign in to comment.