Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pumpkin-crates/core/src/basic_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod function;
mod predicate_id_generators;
mod propositional_conjunction;
mod random;
mod ref_or_owned;
pub(crate) mod sequence_generators;
mod solution;
mod stored_conflict_info;
Expand All @@ -19,7 +18,6 @@ pub use predicate_id_generators::PredicateId;
pub use predicate_id_generators::PredicateIdGenerator;
pub use propositional_conjunction::PropositionalConjunction;
pub use random::*;
pub(crate) use ref_or_owned::*;
pub use solution::ProblemSolution;
pub use solution::Solution;
pub use solution::SolutionReference;
Expand Down
49 changes: 0 additions & 49 deletions pumpkin-crates/core/src/basic_types/ref_or_owned.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ impl<'a> Watchers<'a> {
}
}

pub(crate) fn watch_all(&mut self, domain: DomainId, events: EnumSet<DomainEvent>) {
self.notification_engine
.watch_all(domain, events, self.propagator_var);
}

pub(crate) fn unwatch_all(&mut self, domain: DomainId) {
self.notification_engine
.unwatch_all(domain, self.propagator_var);
Expand Down
13 changes: 12 additions & 1 deletion pumpkin-crates/core/src/engine/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::propagation::Propagator;
use crate::propagation::PropagatorConstructor;
use crate::propagation::PropagatorConstructorContext;
use crate::propagation::PropagatorId;
use crate::propagation::PropagatorVarId;
use crate::propagation::store::PropagatorStore;
use crate::pumpkin_assert_advanced;
use crate::pumpkin_assert_eq_simple;
Expand Down Expand Up @@ -341,7 +342,17 @@ impl State {

let constructor_context =
PropagatorConstructorContext::new(original_handle.propagator_id(), self);
let propagator = constructor.create(constructor_context);
let (registration, propagator) = constructor.create(constructor_context);

for (domain_id, events, local_id) in registration.iter() {
let propagator_var = PropagatorVarId {
propagator: original_handle.propagator_id(),
variable: local_id,
};

self.notification_engine
.watch_all(domain_id, events, propagator_var);
Comment on lines +353 to +354

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this could also be called register or register_events

}

pumpkin_assert_simple!(
propagator.priority() as u8 <= 3,
Expand Down
28 changes: 19 additions & 9 deletions pumpkin-crates/core/src/engine/variables/affine_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use crate::engine::predicates::predicate_constructor::PredicateConstructor;
use crate::engine::variables::DomainId;
use crate::engine::variables::IntegerVariable;
use crate::math::num_ext::NumExt;
use crate::propagation::EventDispatcher;
use crate::propagation::EventTarget;
use crate::propagation::LocalId;

/// Models the constraint `y = ax + b`, by expressing the domain of `y` as a transformation of the
/// domain of `x`.
Expand Down Expand Up @@ -54,6 +57,22 @@ impl<Inner> AffineView<Inner> {
}
}

impl<Inner: EventTarget> EventTarget for AffineView<Inner> {
fn register(
&self,
registration: &mut impl EventDispatcher,
mut events: EnumSet<DomainEvent>,
local_id: LocalId,
) {
let bound = DomainEvent::LowerBound | DomainEvent::UpperBound;
let intersection = events.intersection(bound);
if intersection.len() == 1 && self.scale.is_negative() {
events = events.symmetric_difference(bound);
}
self.inner.register(registration, events, local_id);
}
}

impl<Var: IntegerVariable> CheckerVariable<Predicate> for AffineView<Var> {
fn does_atomic_constrain_self(&self, atomic: &Predicate) -> bool {
self.inner.does_atomic_constrain_self(atomic)
Expand Down Expand Up @@ -265,15 +284,6 @@ where
.map(|value| self.map(value))
}

fn watch_all(&self, watchers: &mut Watchers<'_>, mut events: EnumSet<DomainEvent>) {
let bound = DomainEvent::LowerBound | DomainEvent::UpperBound;
let intersection = events.intersection(bound);
if intersection.len() == 1 && self.scale.is_negative() {
events = events.symmetric_difference(bound);
}
self.inner.watch_all(watchers, events);
}

fn unwatch_all(&self, watchers: &mut Watchers<'_>) {
self.inner.unwatch_all(watchers);
}
Expand Down
23 changes: 11 additions & 12 deletions pumpkin-crates/core/src/engine/variables/constant.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
use enumset::EnumSet;
use pumpkin_checking::CheckerVariable;
use pumpkin_checking::IntExt;

use crate::engine::Assignments;
use crate::predicates::Predicate;
use crate::predicates::PredicateConstructor;
use crate::propagation::DomainEvent;
use crate::propagation::EventDispatcher;
use crate::propagation::EventTarget;
use crate::propagation::LocalId;
use crate::variables::IntegerVariable;
use crate::variables::TransformableVariable;

impl EventTarget for i32 {
fn register(&self, _: &mut impl EventDispatcher, _: EnumSet<DomainEvent>, _: LocalId) {}
}

impl IntegerVariable for i32 {
type AffineView = i32;

Expand Down Expand Up @@ -51,26 +60,16 @@ impl IntegerVariable for i32 {
std::iter::once(*self)
}

fn watch_all(
&self,
_watchers: &mut crate::engine::notifications::Watchers<'_>,
_events: enumset::EnumSet<crate::propagation::DomainEvent>,
) {
}

fn unwatch_all(&self, _watchers: &mut crate::engine::notifications::Watchers<'_>) {}

fn watch_all_backtrack(
&self,
_watchers: &mut crate::engine::notifications::Watchers<'_>,
_events: enumset::EnumSet<crate::propagation::DomainEvent>,
_events: EnumSet<DomainEvent>,
) {
}

fn unpack_event(
&self,
_event: crate::propagation::OpaqueDomainEvent,
) -> crate::propagation::DomainEvent {
fn unpack_event(&self, _event: crate::propagation::OpaqueDomainEvent) -> DomainEvent {
unreachable!()
}

Expand Down
18 changes: 14 additions & 4 deletions pumpkin-crates/core/src/engine/variables/domain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use crate::engine::variables::IntegerVariable;
use crate::predicates::Predicate;
use crate::predicates::PredicateConstructor;
use crate::predicates::PredicateType;
use crate::propagation::EventDispatcher;
use crate::propagation::EventTarget;
use crate::propagation::LocalId;
use crate::pumpkin_assert_simple;

/// A structure which represents the most basic [`IntegerVariable`]; it is simply the id which links
Expand All @@ -32,6 +35,17 @@ impl DomainId {
}
}

impl EventTarget for DomainId {
fn register(
&self,
registration: &mut impl EventDispatcher,
events: EnumSet<DomainEvent>,
local_id: LocalId,
) {
registration.register(*self, events, local_id);
}
}

impl CheckerVariable<Predicate> for DomainId {
fn does_atomic_constrain_self(&self, atomic: &Predicate) -> bool {
atomic.get_domain() == *self
Expand Down Expand Up @@ -155,10 +169,6 @@ impl IntegerVariable for DomainId {
assignment.get_domain_iterator(*self)
}

fn watch_all(&self, watchers: &mut Watchers<'_>, events: EnumSet<DomainEvent>) {
watchers.watch_all(*self, events);
}

fn unwatch_all(&self, watchers: &mut Watchers<'_>) {
watchers.unwatch_all(*self);
}
Expand Down
5 changes: 2 additions & 3 deletions pumpkin-crates/core/src/engine/variables/integer_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::engine::notifications::OpaqueDomainEvent;
use crate::engine::notifications::Watchers;
use crate::engine::predicates::predicate_constructor::PredicateConstructor;
use crate::predicates::Predicate;
use crate::propagation::EventTarget;

/// A trait specifying the required behaviour of an integer variable such as retrieving a
/// lower-bound ([`IntegerVariable::lower_bound`]).
Expand All @@ -19,6 +20,7 @@ pub trait IntegerVariable:
+ TransformableVariable<Self::AffineView>
+ Debug
+ CheckerVariable<Predicate>
+ EventTarget
{
type AffineView: IntegerVariable;

Expand Down Expand Up @@ -50,9 +52,6 @@ pub trait IntegerVariable:
/// Iterate over the values of the domain.
fn iterate_domain(&self, assignment: &Assignments) -> impl Iterator<Item = i32>;

/// Register a watch for this variable on the given domain events.
fn watch_all(&self, watchers: &mut Watchers<'_>, events: EnumSet<DomainEvent>);

/// Remove the watcher on this variable.
fn unwatch_all(&self, watchers: &mut Watchers<'_>);

Expand Down
19 changes: 15 additions & 4 deletions pumpkin-crates/core/src/engine/variables/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ use crate::engine::notifications::Watchers;
use crate::engine::predicates::predicate::Predicate;
use crate::engine::predicates::predicate_constructor::PredicateConstructor;
use crate::engine::variables::AffineView;
use crate::propagation::EventDispatcher;
use crate::propagation::EventTarget;
use crate::propagation::LocalId;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Literal {
Expand Down Expand Up @@ -73,6 +76,18 @@ macro_rules! forward {
}
}

impl EventTarget for Literal {
fn register(
&self,
registration: &mut impl EventDispatcher,
events: EnumSet<DomainEvent>,
local_id: LocalId,
) {
self.integer_variable
.register(registration, events, local_id);
}
}

impl CheckerVariable<Predicate> for Literal {
forward!(integer_variable, fn does_atomic_constrain_self(&self, atomic: &Predicate) -> bool);
forward!(integer_variable, fn atomic_less_than(&self, value: i32) -> Predicate);
Expand Down Expand Up @@ -164,10 +179,6 @@ impl IntegerVariable for Literal {
self.integer_variable.iterate_domain(assignment)
}

fn watch_all(&self, watchers: &mut Watchers<'_>, events: EnumSet<DomainEvent>) {
self.integer_variable.watch_all(watchers, events)
}

fn unwatch_all(&self, watchers: &mut Watchers<'_>) {
self.integer_variable.unwatch_all(watchers)
}
Expand Down
Loading
Loading