Skip to content

Commit

Permalink
Merge pull request #35 from vcoppe/rename-barrier
Browse files Browse the repository at this point in the history
Rename barrier to cache to match paper title
  • Loading branch information
xgillard authored Feb 2, 2024
2 parents 0b3b4f1 + 1d82c5d commit e9aa3b7
Show file tree
Hide file tree
Showing 35 changed files with 532 additions and 472 deletions.
2 changes: 1 addition & 1 deletion ddo/examples/alp/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn main() {
let cutoff = cutoff(args.duration);
let mut fringe = NoDupFringe::new(MaxUB::new(&ranking));

let mut solver = DefaultBarrierSolver::custom(
let mut solver = DefaultCachingSolver::custom(
&problem,
&relaxation,
&ranking,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/alp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn solve_id(id: &str) -> isize {
let cutoff = NoCutoff;
let mut fringe = NoDupFringe::new(MaxUB::new(&ranking));

let mut solver = DefaultBarrierSolver::new(
let mut solver = DefaultCachingSolver::new(
&problem,
&relaxation,
&ranking,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/golomb/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ fn main() {
let cutoff = TimeBudget::new(Duration::from_secs(args.timeout));//NoCutoff;
let mut fringe = SimpleFringe::new(MaxUB::new(&heuristic));

let mut solver = DefaultBarrierSolver::new(
let mut solver = DefaultCachingSolver::new(
&problem,
&relaxation,
&heuristic,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/golomb/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn solve_golomb(n: usize) -> isize {
let cutoff = NoCutoff;
let mut fringe = SimpleFringe::new(MaxUB::new(&heuristic));

let mut solver = DefaultBarrierSolver::new(
let mut solver = DefaultCachingSolver::new(
&problem,
&relaxation,
&heuristic,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/knapsack/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ fn main() {
let cutoff = TimeBudget::new(Duration::from_secs(15));//NoCutoff;
let mut fringe = SimpleFringe::new(MaxUB::new(&heuristic));

let mut solver = DefaultBarrierSolver::new(
let mut solver = DefaultCachingSolver::new(
&problem,
&relaxation,
&heuristic,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/knapsack/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn solve_id(id: &str) -> isize {
let mut fringe = NoDupFringe::new(MaxUB::new(&ranking));

// This solver compile DD that allow the definition of long arcs spanning over several layers.
let mut solver = DefaultBarrierSolver::new(
let mut solver = DefaultCachingSolver::new(
&problem,
&relaxation,
&ranking,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/lcs/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn main() {
let mut fringe = NoDupFringe::new(MaxUB::new(&ranking));

// This solver compile DD that allow the definition of long arcs spanning over several layers.
let mut solver = ParBarrierSolverPooled::custom(
let mut solver = ParCachingSolverPooled::custom(
&problem,
&relaxation,
&ranking,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/lcs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn solve_id(id: &str) -> isize {
let mut fringe = NoDupFringe::new(MaxUB::new(&ranking));

// This solver compile DD that allow the definition of long arcs spanning over several layers.
let mut solver = ParBarrierSolverPooled::new(
let mut solver = ParCachingSolverPooled::new(
&problem,
&relaxation,
&ranking,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/misp/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ fn main() {
let mut fringe = NoDupFringe::new(MaxUB::new(&ranking));

// This solver compile DD that allow the definition of long arcs spanning over several layers.
let mut solver = ParNoBarrierSolverLel::custom(
let mut solver = ParNoCachingSolverLel::custom(
&problem,
&relaxation,
&ranking,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/psp/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn main() {
let mut fringe = NoDupFringe::new(MaxUB::new(&ranking));

// This solver compile DD that allow the definition of long arcs spanning over several layers.
let mut solver = DefaultBarrierSolver::custom(
let mut solver = DefaultCachingSolver::custom(
&problem,
&relaxation,
&ranking,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/psp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod psp_test_utils {
let mut fringe = NoDupFringe::new(MaxUB::new(&ranking));

// This solver compile DD that allow the definition of long arcs spanning over several layers.
let mut solver = DefaultBarrierSolver::<PspState>::custom(
let mut solver = DefaultCachingSolver::<PspState>::custom(
&problem,
&relaxation,
&ranking,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/sop/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn main() {
let cutoff = cutoff(args.duration);
let mut fringe = NoDupFringe::new(MaxUB::new(&ranking));

let mut solver = DefaultBarrierSolver::custom(
let mut solver = DefaultCachingSolver::custom(
&problem,
&relaxation,
&ranking,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/sop/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn solve_id(id: &str) -> isize {
let cutoff = NoCutoff;
let mut fringe = NoDupFringe::new(MaxUB::new(&ranking));

let mut solver = DefaultBarrierSolver::new(
let mut solver = DefaultCachingSolver::new(
&problem,
&relaxation,
&ranking,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/srflp/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn main() {
let cutoff = cutoff(args.duration);
let mut fringe = NoDupFringe::new(MaxUB::new(&ranking));

let mut solver = DefaultBarrierSolver::custom(
let mut solver = DefaultCachingSolver::custom(
&problem,
&relaxation,
&ranking,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/srflp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn solve_id(id: &str) -> f64 {
let cutoff = NoCutoff;
let mut fringe = NoDupFringe::new(MaxUB::new(&ranking));

let mut solver = DefaultBarrierSolver::new(
let mut solver = DefaultCachingSolver::new(
&problem,
&relaxation,
&ranking,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/talentsched/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn main() {
let cutoff = cutoff(args.duration);
let mut fringe = NoDupFringe::new(MaxUB::new(&ranking));

let mut solver = DefaultBarrierSolver::custom(
let mut solver = DefaultCachingSolver::custom(
&problem,
&relaxation,
&ranking,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/talentsched/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn solve_id(id: &str) -> isize {
let cutoff = NoCutoff;
let mut fringe = NoDupFringe::new(MaxUB::new(&ranking));

let mut solver = DefaultBarrierSolver::new(
let mut solver = DefaultCachingSolver::new(
&problem,
&relaxation,
&ranking,
Expand Down
4 changes: 2 additions & 2 deletions ddo/examples/tsptw/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use std::{fs::File, path::Path, time::{Duration, Instant}};

use clap::Parser;
use ddo::{Completion, TimeBudget, NoDupFringe, MaxUB, Solution, SimpleDominanceChecker, Problem, DefaultBarrierSolver, Solver};
use ddo::{Completion, TimeBudget, NoDupFringe, MaxUB, Solution, SimpleDominanceChecker, Problem, DefaultCachingSolver, Solver};
use dominance::TsptwDominance;
use heuristics::{TsptwWidth, TsptwRanking};
use instance::TsptwInstance;
Expand Down Expand Up @@ -76,7 +76,7 @@ fn main() {
let dominance = SimpleDominanceChecker::new(TsptwDominance);
let cutoff = TimeBudget::new(Duration::from_secs(args.duration.unwrap_or(u64::MAX)));
let mut fringe = NoDupFringe::new(MaxUB::new(&TsptwRanking));
let mut solver = DefaultBarrierSolver::custom(
let mut solver = DefaultCachingSolver::custom(
&pb,
&relax,
&TsptwRanking,
Expand Down
4 changes: 2 additions & 2 deletions ddo/examples/tsptw/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use std::{fs::File, path::PathBuf};

use ddo::{MaxUB, NoDupFringe, Problem, Solver, DefaultBarrierSolver, SimpleDominanceChecker, NoCutoff};
use ddo::{MaxUB, NoDupFringe, Problem, Solver, DefaultCachingSolver, SimpleDominanceChecker, NoCutoff};

use crate::{dominance::TsptwDominance, heuristics::{TsptwRanking, TsptwWidth}, instance::TsptwInstance, model::Tsptw, relax::TsptwRelax};

Expand All @@ -39,7 +39,7 @@ pub fn solve(instance: &str, width: Option<usize>, threads: Option<usize>) -> f3
let width = TsptwWidth::new(pb.nb_variables(), width.unwrap_or(1));
let dominance = SimpleDominanceChecker::new(TsptwDominance);
let cutoff = NoCutoff;
let mut solver = DefaultBarrierSolver::custom(
let mut solver = DefaultCachingSolver::custom(
&pb,
&relax,
&TsptwRanking,
Expand Down
6 changes: 3 additions & 3 deletions ddo/examples/visualisation/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ fn main() {
let problem = read_instance(fname).unwrap();
let relaxation = KPRelax{pb: &problem};
let ranking = KPranking;
let mut barrier = SimpleBarrier::default();
barrier.initialize(&problem);
let mut cache = SimpleCache::default();
cache.initialize(&problem);
let dominance = EmptyDominanceChecker::default();

let residual = SubProblem {
Expand All @@ -281,7 +281,7 @@ fn main() {
max_width: 5,
residual: &residual,
best_lb: isize::MIN,
barrier: &barrier,
cache: &cache,
dominance: &dominance,
};

Expand Down
10 changes: 5 additions & 5 deletions ddo/src/abstraction/barrier.rs → ddo/src/abstraction/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ use std::sync::Arc;

use crate::{Threshold, SubProblem, Problem};

/// This trait abstracts away the implementation details of the solver barrier.
/// That is, a Barrier represents the data structure that stores thresholds that
/// This trait abstracts away the implementation details of the solver cache.
/// That is, a Cache represents the data structure that stores thresholds that
/// condition the re-exploration of nodes with a state already reached previously.
pub trait Barrier {
pub trait Cache {
type State;

/// Returns true if the subproblem still must be explored,
/// given the thresholds contained in the barrier.
/// given the thresholds contained in the cache.
fn must_explore(&self, subproblem: &SubProblem<Self::State>) -> bool {
let threshold = self.get_threshold(subproblem.state.as_ref(), subproblem.depth);
if let Some(threshold) = threshold {
Expand All @@ -38,7 +38,7 @@ pub trait Barrier {
}
}

/// Prepare the barrier to be used with the given problem
/// Prepare the cache to be used with the given problem
fn initialize(&mut self, problem: &dyn Problem<State = Self::State>);

/// Returns the threshold currently associated with the given state, if any.
Expand Down
4 changes: 2 additions & 2 deletions ddo/src/abstraction/mdd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

use crate::{SubProblem, Completion, Reason, Problem, Relaxation, StateRanking, Solution, Cutoff, Barrier, DominanceChecker};
use crate::{SubProblem, Completion, Reason, Problem, Relaxation, StateRanking, Solution, Cutoff, Cache, DominanceChecker};

// FIXME: Replace that with the following enum definition when const generics allow enum types
/// What type of cut-set are we using for relaxed DDs ?
Expand Down Expand Up @@ -66,7 +66,7 @@ pub struct CompilationInput<'a, State> {
/// The best known lower bound at the time when the dd is being compiled
pub best_lb: isize,
/// Data structure containing info about past compilations used to prune the search
pub barrier: &'a dyn Barrier<State = State>,
pub cache: &'a dyn Cache<State = State>,
pub dominance: &'a dyn DominanceChecker<State = State>,
}

Expand Down
4 changes: 2 additions & 2 deletions ddo/src/abstraction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ mod heuristics;
mod solver;
mod fringe;
mod mdd;
mod barrier;
mod cache;
mod dominance;

pub use dp::*;
pub use heuristics::*;
pub use solver::*;
pub use fringe::*;
pub use mdd::*;
pub use barrier::*;
pub use cache::*;
pub use dominance::*;
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ use std::{sync::Arc, marker::PhantomData};

use crate::*;

/// Dummy implementation of Barrier with no information stored at all.
/// Dummy implementation of Cache with no information stored at all.
#[derive(Debug, Clone, Copy)]
pub struct EmptyBarrier<T> {
pub struct EmptyCache<T> {
phantom: PhantomData<T>,
}
impl <T> Default for EmptyBarrier<T> {
impl <T> Default for EmptyCache<T> {
fn default() -> Self {
EmptyBarrier { phantom: Default::default() }
EmptyCache { phantom: Default::default() }
}
}
impl <T> EmptyBarrier<T> {
impl <T> EmptyCache<T> {
pub fn new() -> Self {
Default::default()
}
}

impl<T> Barrier for EmptyBarrier<T> {
impl<T> Cache for EmptyCache<T> {
type State = T;

#[inline(always)]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ use std::{sync::Arc, hash::Hash};

use dashmap::DashMap;

use crate::{Barrier, Threshold};
use crate::{Cache, Threshold};

/// Simple implementation of the Barrier using one hashmap for each layer,
/// Simple implementation of Cache using one hashmap for each layer,
/// each protected with a read-write lock.
#[derive(Debug)]
pub struct SimpleBarrier<T>
pub struct SimpleCache<T>
where T: Hash + Eq {
thresholds_by_layer: Vec<DashMap<Arc<T>, Threshold, fxhash::FxBuildHasher>>,
}
impl <T> Default for SimpleBarrier<T>
impl <T> Default for SimpleCache<T>
where T: Hash + Eq {
fn default() -> Self {
Self { thresholds_by_layer: vec![] }
}
}

impl<T> Barrier for SimpleBarrier<T>
impl<T> Cache for SimpleCache<T>
where T: Hash + Eq {
type State = T;

Expand Down
Loading

0 comments on commit e9aa3b7

Please sign in to comment.