pub struct State { /* private fields */ }Expand description
Implementations§
Source§impl State
Operations to create .
impl State
Operations to create .
Sourcepub fn new_constraint_tag(&mut self) -> ConstraintTag
pub fn new_constraint_tag(&mut self) -> ConstraintTag
Create a new ConstraintTag.
Sourcepub fn new_literal(&mut self, name: Option<Arc<str>>) -> Literal
pub fn new_literal(&mut self, name: Option<Arc<str>>) -> Literal
Creates a new Boolean (0-1) variable.
The name is used in solver traces to identify individual domains. They are required to be unique. If the state already contains a domain with the given name, then this function will panic.
Creation of new Literals is not influenced by the current checkpoint of the state.
If a Literal is created at a non-zero checkpoint, then it will not ‘disappear’
when backtracking past the checkpoint where the domain was created.
Sourcepub fn new_interval_variable(
&mut self,
lower_bound: i32,
upper_bound: i32,
name: Option<Arc<str>>,
) -> DomainId
pub fn new_interval_variable( &mut self, lower_bound: i32, upper_bound: i32, name: Option<Arc<str>>, ) -> DomainId
Creates a new interval variable with the given lower and upper bound.
The name is used in solver traces to identify individual domains. They are required to be unique. If the state already contains a domain with the given name, then this function will panic.
Creation of new domains is not influenced by the current checkpoint of the state. If a domain is created at a non-zero checkpoint, then it will not ‘disappear’ when backtracking past the checkpoint where the domain was created.)
Sourcepub fn new_sparse_variable(
&mut self,
values: Vec<i32>,
name: Option<String>,
) -> DomainId
pub fn new_sparse_variable( &mut self, values: Vec<i32>, name: Option<String>, ) -> DomainId
Creates a new sparse domain with the given values.
Note that this is implemented as an interval domain with explicit holes in the domain. For very sparse domains, this can result in a high memory overhead.
For more information on creation of domains, see State::new_interval_variable.
Source§impl State
Operations to retrieve information about values
impl State
Operations to retrieve information about values
Sourcepub fn lower_bound<Var>(&self, variable: Var) -> i32where
Var: IntegerVariable,
pub fn lower_bound<Var>(&self, variable: Var) -> i32where
Var: IntegerVariable,
Returns the lower-bound of the given variable.
Sourcepub fn upper_bound<Var>(&self, variable: Var) -> i32where
Var: IntegerVariable,
pub fn upper_bound<Var>(&self, variable: Var) -> i32where
Var: IntegerVariable,
Returns the upper-bound of the given variable.
Sourcepub fn contains<Var>(&self, variable: Var, value: i32) -> boolwhere
Var: IntegerVariable,
pub fn contains<Var>(&self, variable: Var, value: i32) -> boolwhere
Var: IntegerVariable,
Returns whether the given variable contains the provided value.
Sourcepub fn fixed_value<Var>(&self, variable: Var) -> Option<i32>where
Var: IntegerVariable,
pub fn fixed_value<Var>(&self, variable: Var) -> Option<i32>where
Var: IntegerVariable,
Sourcepub fn truth_value(&self, predicate: Predicate) -> Option<bool>
pub fn truth_value(&self, predicate: Predicate) -> Option<bool>
Sourcepub fn get_checkpoint_for_predicate(
&self,
predicate: Predicate,
) -> Option<usize>
pub fn get_checkpoint_for_predicate( &self, predicate: Predicate, ) -> Option<usize>
Sourcepub fn get_literal_value(&self, literal: Literal) -> Option<bool>
pub fn get_literal_value(&self, literal: Literal) -> Option<bool>
Sourcepub fn get_checkpoint(&self) -> usize
pub fn get_checkpoint(&self) -> usize
Returns the number of created checkpoints.
Source§impl State
Operations for retrieving information about trail
impl State
Operations for retrieving information about trail
Sourcepub fn is_on_trail(&self, predicate: Predicate) -> bool
pub fn is_on_trail(&self, predicate: Predicate) -> bool
Source§impl State
Operations for adding constraints.
impl State
Operations for adding constraints.
Sourcepub fn add_propagator<Constructor>(
&mut self,
constructor: Constructor,
) -> PropagatorHandle<<Constructor as PropagatorConstructor>::PropagatorImpl>where
Constructor: PropagatorConstructor,
<Constructor as PropagatorConstructor>::PropagatorImpl: 'static,
pub fn add_propagator<Constructor>(
&mut self,
constructor: Constructor,
) -> PropagatorHandle<<Constructor as PropagatorConstructor>::PropagatorImpl>where
Constructor: PropagatorConstructor,
<Constructor as PropagatorConstructor>::PropagatorImpl: 'static,
Add a new propagator to the State. The constructor for that propagator should
subscribe to the appropriate domain events so that the propagator is called when
necessary.
While the propagator is added to the queue for propagation, this function does not
trigger a round of propagation. An explicit call to State::propagate_to_fixed_point is
necessary to run the new propagator for the first time.
Sourcepub fn add_inference_checker(
&mut self,
inference_code: InferenceCode,
checker: Box<dyn InferenceChecker<Predicate>>,
)
pub fn add_inference_checker( &mut self, inference_code: InferenceCode, checker: Box<dyn InferenceChecker<Predicate>>, )
Add an inference checker to the state.
The inference checker will be used to check propagations performed during
Self::propagate_to_fixed_point, if the check-propagations feature is enabled.
Multiple inference checkers may be added for the same inference code. In that case, if any checker accepts the inference, the inference is accepted.
Source§impl State
Operations for retrieving propagators.
impl State
Operations for retrieving propagators.
Sourcepub fn get_propagator<P>(&self, handle: PropagatorHandle<P>) -> Option<&P>where
P: Propagator,
pub fn get_propagator<P>(&self, handle: PropagatorHandle<P>) -> Option<&P>where
P: Propagator,
Get a reference to the propagator identified by the given handle.
For an exclusive reference, use State::get_propagator_mut.
Sourcepub fn get_propagator_mut<P>(
&mut self,
handle: PropagatorHandle<P>,
) -> Option<&mut P>where
P: Propagator,
pub fn get_propagator_mut<P>(
&mut self,
handle: PropagatorHandle<P>,
) -> Option<&mut P>where
P: Propagator,
Get an exclusive reference to the propagator identified by the given handle.
Source§impl State
Operations for modifying the state.
impl State
Operations for modifying the state.
Sourcepub fn post(&mut self, predicate: Predicate) -> Result<bool, EmptyDomain>
pub fn post(&mut self, predicate: Predicate) -> Result<bool, EmptyDomain>
Apply a Predicate to the State.
Returns true if a change to a domain occured, and false if the given Predicate was
already true.
If a domain becomes empty due to this operation, an EmptyDomain error is returned.
This method does not perform any propagation. For that, an explicit call to
State::propagate_to_fixed_point is required. This allows the
posting of multiple predicates before the entire propagation engine is invoked.
A call to State::restore_to that goes past the checkpoint at which a Predicate
was posted will undo the effect of that Predicate. See the documentation of
State::new_checkpoint and
State::restore_to for more information.
Sourcepub fn new_checkpoint(&mut self)
pub fn new_checkpoint(&mut self)
Create a checkpoint of the current State, that can be returned to with
State::restore_to.
The current checkpoint can be retrieved using the method State::get_checkpoint.
If the state is not at fixed-point, then this method will panic.
§Example
use pumpkin_core::predicate;
use pumpkin_core::state::State;
let mut state = State::default();
let variable = state.new_interval_variable(1, 10, Some("x1".into()));
assert_eq!(state.get_checkpoint(), 0);
state.new_checkpoint();
assert_eq!(state.get_checkpoint(), 1);
state
.post(predicate![variable <= 5])
.expect("The lower bound is 1 so no conflict");
assert_eq!(state.upper_bound(variable), 5);
state.restore_to(0);
assert_eq!(state.get_checkpoint(), 0);
assert_eq!(state.upper_bound(variable), 10);Sourcepub fn restore_to(&mut self, checkpoint: usize) -> Vec<(DomainId, i32)>
pub fn restore_to(&mut self, checkpoint: usize) -> Vec<(DomainId, i32)>
Restore to the given checkpoint and return the DomainIds which were fixed before
restoring, with their assigned values.
If the provided checkpoint is equal to the current checkpoint, this is a no-op. If the provided checkpoint is larger than the current checkpoint, this method will panic.
See State::new_checkpoint for an example.
Sourcepub fn propagate_to_fixed_point(&mut self) -> Result<(), Conflict>
pub fn propagate_to_fixed_point(&mut self) -> Result<(), Conflict>
Performs fixed-point propagation using the propagators defined in the State.
The posted Predicates (using State::post) and added propagators (using
State::add_propagator) cause propagators to be enqueued when the events that
they have subscribed to are triggered. As propagation causes more changes to be made,
more propagators are enqueued. This continues until applying all (enqueued)
propagators leads to no more domain changes.
It could be that the current State implies a conflict by propagation. In that case, an
error with Conflict is returned.
Once the State is conflicting, then the only operation that is defined is
State::restore_to. All other operations and queries on the state are unspecified.
Source§impl State
impl State
Sourcepub fn get_propagation_reason(
&mut self,
predicate: Predicate,
reason_buffer: &mut (impl Extend<Predicate> + AsRef<[Predicate]>),
current_nogood: CurrentNogood<'_>,
) -> Option<usize>
pub fn get_propagation_reason( &mut self, predicate: Predicate, reason_buffer: &mut (impl Extend<Predicate> + AsRef<[Predicate]>), current_nogood: CurrentNogood<'_>, ) -> Option<usize>
Get the reason for a predicate being true and store it in reason_buffer; additionally, if
the provided Predicate is explicitly on the trail, this method will return the
corresponding trail index.
The provided current_nogood can be used by the propagator to provide a different reason;
use CurrentNogood::empty otherwise.
All the predicates in the returned slice will evaluate to true.
If the provided predicate is not true, then this method will panic.
Source§impl State
impl State
pub fn get_domains(&mut self) -> Domains<'_>
pub fn get_propagation_context(&mut self) -> PropagationContext<'_>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for State
impl !RefUnwindSafe for State
impl !Send for State
impl !Sync for State
impl Unpin for State
impl !UnwindSafe for State
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more