ddo/abstraction/
fringe.rs

1// Copyright 2020 Xavier Gillard
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy of
4// this software and associated documentation files (the "Software"), to deal in
5// the Software without restriction, including without limitation the rights to
6// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7// the Software, and to permit persons to whom the Software is furnished to do so,
8// subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in all
11// copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20use crate::SubProblem;
21
22
23/// This trait abstracts away the implementation details of the solver fringe.
24/// That is, a Fringe represents the global priority queue which stores all 
25/// the nodes remaining to explore.
26pub trait Fringe {
27    type State;
28
29    /// This is how you push a node onto the fringe.
30    fn push(&mut self, node: SubProblem<Self::State>);
31    /// This method yields the most promising node from the fringe.
32    /// # Note:
33    /// The solvers rely on the assumption that a fringe will pop nodes in
34    /// descending upper bound order. Hence, it is a requirement for any fringe
35    /// implementation to enforce that requirement.
36    fn pop(&mut self) -> Option<SubProblem<Self::State>>;
37    /// This method clears the fringe: it removes all nodes from the queue.
38    fn clear(&mut self);
39    /// Yields the length of the queue.
40    fn len(&self) -> usize;
41    /// Returns true iff the fringe is empty (len == 0)
42    fn is_empty(&self) -> bool {
43        self.len() == 0
44    }
45}