Skip to content
Merged
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
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions pumpkin-crates/constraints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "pumpkin-constraints"
version = "0.2.2"
repository.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
description = "The constraints of the Pumpkin constraint programming solver."

[lints]
workspace = true

[dependencies]
pumpkin-core = { version = "0.2.2", path = "../core" }
pumpkin-propagators = {version = "0.2.2", path="../propagators"}

[features]
clap = ["pumpkin-core/clap", "pumpkin-propagators/clap"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::Constraint;
use pumpkin_core::constraints::Constraint;
use pumpkin_core::proof::ConstraintTag;
use pumpkin_core::variables::IntegerVariable;

use super::binary_not_equals;
use crate::proof::ConstraintTag;
use crate::variables::IntegerVariable;

/// Creates the [`Constraint`] that enforces that all the given `variables` are distinct.
pub fn all_different<Var: IntegerVariable + 'static>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
use pumpkin_core::ConstraintOperationError;
use pumpkin_core::Solver;
use pumpkin_core::constraints::Constraint;
use pumpkin_core::constraints::NegatableConstraint;
use pumpkin_core::options::ReifiedPropagatorArgs;
use pumpkin_core::proof::ConstraintTag;
use pumpkin_core::variables::IntegerVariable;
use pumpkin_core::variables::Literal;
use pumpkin_core::variables::TransformableVariable;
use pumpkin_propagators::arithmetic::BinaryEqualsPropagatorArgs;
use pumpkin_propagators::arithmetic::BinaryNotEqualsPropagatorArgs;
use pumpkin_propagators::arithmetic::LinearNotEqualPropagatorArgs;

use super::less_than_or_equals;
use crate::ConstraintOperationError;
use crate::Solver;
use crate::constraints::Constraint;
use crate::constraints::NegatableConstraint;
use crate::proof::ConstraintTag;
use crate::propagators::ReifiedPropagatorArgs;
use crate::propagators::binary::BinaryEqualsPropagatorArgs;
use crate::propagators::binary::BinaryNotEqualsPropagatorArgs;
use crate::propagators::linear_not_equal::LinearNotEqualPropagatorArgs;
use crate::variables::IntegerVariable;
use crate::variables::Literal;
use crate::variables::TransformableVariable;

struct EqualConstraint<Var> {
terms: Box<[Var]>,
rhs: i32,
constraint_tag: ConstraintTag,
}

/// Creates the [`NegatableConstraint`] `\sum terms_i = rhs`.
/// Creates the [`NegatableConstraint`] ` terms_i = rhs`.
///
/// Its negation is [`not_equals`].
pub fn equals<Var: IntegerVariable + Clone + 'static>(
Expand Down Expand Up @@ -54,7 +55,7 @@ struct NotEqualConstraint<Var> {
constraint_tag: ConstraintTag,
}

/// Create the [`NegatableConstraint`] `\sum terms_i != rhs`.
/// Create the [`NegatableConstraint`] ` terms_i != rhs`.
///
/// Its negation is [`equals`].
pub fn not_equals<Var: IntegerVariable + Clone + 'static>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use crate::ConstraintOperationError;
use crate::Solver;
use crate::constraints::Constraint;
use crate::constraints::NegatableConstraint;
use crate::proof::ConstraintTag;
use crate::propagators::linear_less_or_equal::LinearLessOrEqualPropagatorArgs;
use crate::variables::IntegerVariable;

/// Create the [`NegatableConstraint`] `\sum terms_i <= rhs`.
use pumpkin_core::ConstraintOperationError;
use pumpkin_core::Solver;
use pumpkin_core::constraints::Constraint;
use pumpkin_core::constraints::NegatableConstraint;
use pumpkin_core::proof::ConstraintTag;
use pumpkin_core::variables::IntegerVariable;
use pumpkin_core::variables::Literal;
use pumpkin_propagators::arithmetic::LinearLessOrEqualPropagatorArgs;

/// Create the [`NegatableConstraint`] `∑ terms_i <= rhs`.
///
/// Its negation is `\sum terms_i > rhs`
/// Its negation is ` terms_i > rhs`
pub fn less_than_or_equals<Var: IntegerVariable + 'static>(
terms: impl Into<Box<[Var]>>,
rhs: i32,
Expand All @@ -21,9 +22,9 @@ pub fn less_than_or_equals<Var: IntegerVariable + 'static>(
}
}

/// Create the [`NegatableConstraint`] `\sum terms_i < rhs`.
/// Create the [`NegatableConstraint`] ` terms_i < rhs`.
///
/// Its negation is `\sum terms_i <= rhs`
/// Its negation is ` terms_i <= rhs`
pub fn less_than<Var: IntegerVariable + 'static>(
terms: impl Into<Box<[Var]>>,
rhs: i32,
Expand All @@ -32,9 +33,9 @@ pub fn less_than<Var: IntegerVariable + 'static>(
less_than_or_equals(terms, rhs - 1, constraint_tag)
}

/// Create the [`NegatableConstraint`] `\sum terms_i > rhs`.
/// Create the [`NegatableConstraint`] ` terms_i > rhs`.
///
/// Its negation is `\sum terms_i <= rhs`
/// Its negation is ` terms_i <= rhs`
pub fn greater_than<Var: IntegerVariable + 'static>(
terms: impl Into<Box<[Var]>>,
rhs: i32,
Expand All @@ -43,9 +44,9 @@ pub fn greater_than<Var: IntegerVariable + 'static>(
greater_than_or_equals(terms, rhs + 1, constraint_tag)
}

/// Create the [`NegatableConstraint`] `\sum terms_i >= rhs`.
/// Create the [`NegatableConstraint`] ` terms_i >= rhs`.
///
/// Its negation is `\sum terms_i < rhs`
/// Its negation is ` terms_i < rhs`
pub fn greater_than_or_equals<Var: IntegerVariable + 'static>(
terms: impl Into<Box<[Var]>>,
rhs: i32,
Expand Down Expand Up @@ -118,7 +119,7 @@ impl<Var: IntegerVariable + 'static> Constraint for Inequality<Var> {
fn implied_by(
self,
solver: &mut Solver,
reification_literal: crate::variables::Literal,
reification_literal: Literal,
) -> Result<(), ConstraintOperationError> {
LinearLessOrEqualPropagatorArgs {
x: self.terms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ mod inequality;

pub use equality::*;
pub use inequality::*;

use super::Constraint;
use crate::proof::ConstraintTag;
use crate::propagators::absolute_value::AbsoluteValueArgs;
use crate::propagators::integer_division::DivisionArgs;
use crate::propagators::integer_multiplication::IntegerMultiplicationArgs;
use crate::propagators::maximum::MaximumArgs;
use crate::variables::IntegerVariable;
use pumpkin_core::constraints::Constraint;
use pumpkin_core::proof::ConstraintTag;
use pumpkin_core::variables::IntegerVariable;
use pumpkin_propagators::arithmetic::AbsoluteValueArgs;
use pumpkin_propagators::arithmetic::DivisionArgs;
use pumpkin_propagators::arithmetic::IntegerMultiplicationArgs;
use pumpkin_propagators::arithmetic::MaximumArgs;

/// Creates the [`Constraint`] `a + b = c`.
pub fn plus<Var: IntegerVariable + 'static>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use super::Constraint;
use pumpkin_core::ConstraintOperationError;
use pumpkin_core::Solver;
use pumpkin_core::constraints::Constraint;
use pumpkin_core::proof::ConstraintTag;
use pumpkin_core::variables::AffineView;
use pumpkin_core::variables::DomainId;
use pumpkin_core::variables::Literal;
use pumpkin_core::variables::TransformableVariable;

use super::equals;
use super::less_than_or_equals;
use crate::ConstraintOperationError;
use crate::Solver;
use crate::proof::ConstraintTag;
use crate::variables::AffineView;
use crate::variables::DomainId;
use crate::variables::Literal;
use crate::variables::TransformableVariable;

/// Creates the [`Constraint`] `\sum weights_i * bools_i <= rhs`.
/// Creates the [`Constraint`] ` weights_i * bools_i <= rhs`.
pub fn boolean_less_than_or_equals(
weights: impl Into<Box<[i32]>>,
bools: impl Into<Box<[Literal]>>,
Expand All @@ -24,7 +25,7 @@ pub fn boolean_less_than_or_equals(
}
}

/// Creates the [`Constraint`] `\sum weights_i * bools_i == rhs`.
/// Creates the [`Constraint`] ` weights_i * bools_i == rhs`.
pub fn boolean_equals(
weights: impl Into<Box<[i32]>>,
bools: impl Into<Box<[Literal]>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::Constraint;
use super::NegatableConstraint;
use crate::ConstraintOperationError;
use crate::Solver;
use crate::proof::ConstraintTag;
use crate::variables::Literal;
use pumpkin_core::ConstraintOperationError;
use pumpkin_core::Solver;
use pumpkin_core::constraints::Constraint;
use pumpkin_core::constraints::NegatableConstraint;
use pumpkin_core::proof::ConstraintTag;
use pumpkin_core::variables::Literal;

/// Creates the [`NegatableConstraint`] `\/ literal`
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use std::fmt::Debug;

use super::Constraint;
use crate::ConstraintOperationError;
use crate::Solver;
use crate::constraint_arguments::CumulativePropagationMethod;
use crate::proof::ConstraintTag;
use crate::propagators::ArgTask;
use crate::propagators::CumulativeOptions;
use crate::propagators::TimeTableOverIntervalIncrementalPropagator;
use crate::propagators::TimeTableOverIntervalPropagator;
use crate::propagators::TimeTablePerPointIncrementalPropagator;
use crate::propagators::TimeTablePerPointPropagator;
use crate::pumpkin_assert_simple;
use crate::variables::IntegerVariable;
use crate::variables::Literal;
use pumpkin_core::ConstraintOperationError;
use pumpkin_core::Solver;
use pumpkin_core::asserts::pumpkin_assert_simple;
use pumpkin_core::constraints::Constraint;
use pumpkin_core::proof::ConstraintTag;
use pumpkin_core::variables::IntegerVariable;
use pumpkin_core::variables::Literal;
use pumpkin_propagators::cumulative::ArgTask;
use pumpkin_propagators::cumulative::options::CumulativeOptions;
use pumpkin_propagators::cumulative::options::CumulativePropagationMethod;
use pumpkin_propagators::cumulative::time_table::TimeTableOverIntervalIncrementalPropagator;
use pumpkin_propagators::cumulative::time_table::TimeTableOverIntervalPropagator;
use pumpkin_propagators::cumulative::time_table::TimeTablePerPointIncrementalPropagator;
use pumpkin_propagators::cumulative::time_table::TimeTablePerPointPropagator;

/// Creates the [Cumulative](https://sofdem.github.io/gccat/gccat/Ccumulative.html) [`Constraint`].
///
Expand Down Expand Up @@ -43,7 +43,7 @@ use crate::variables::Literal;
/// # use pumpkin_core::results::SatisfactionResult;
/// # use pumpkin_core::constraints;
/// # use pumpkin_core::constraints::Constraint;
/// # use crate::pumpkin_core::results::ProblemSolution;
/// # use pumpkin_core::results::ProblemSolution;
/// let solver = Solver::default();
///
/// let mut solver = Solver::default();
Expand All @@ -60,7 +60,7 @@ use crate::variables::Literal;
/// let resource_capacity = 2;
///
/// solver
/// .add_constraint(constraints::cumulative(
/// .add_constraint(pumpkin_constraints::cumulative(
/// start_times.clone(),
/// durations.clone(),
/// resource_requirements.clone(),
Expand Down Expand Up @@ -149,7 +149,7 @@ where
)
}

/// Creates the [Cumulative](https://sofdem.github.io/gccat/gccat/Ccumulative.html) constraint
/// Creates the [Cumulative](https://sofdem.github.io/gccat/gccat/Ccumulative.html) [`Constraint`]
/// with the provided [`CumulativeOptions`].
///
/// See the documentation of [`cumulative`] for more information about the constraint.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use crate::constraints::Constraint;
use crate::proof::ConstraintTag;
use crate::propagators::disjunctive_propagator::DisjunctiveConstructor;
use crate::propagators::disjunctive_task::ArgDisjunctiveTask;
use crate::variables::IntegerVariable;
use crate::variables::TransformableVariable;
use pumpkin_core::ConstraintOperationError;
use pumpkin_core::Solver;
use pumpkin_core::constraints::Constraint;
use pumpkin_core::proof::ConstraintTag;
use pumpkin_core::variables::IntegerVariable;
use pumpkin_core::variables::Literal;
use pumpkin_core::variables::TransformableVariable;
use pumpkin_propagators::disjunctive::ArgDisjunctiveTask;
use pumpkin_propagators::disjunctive::DisjunctiveConstructor;

/// Creates the [Disjunctive](https://sofdem.github.io/gccat/gccat/Cdisjunctive.html) [`Constraint`] (also called the `NoOverlap` Constraint or the `Unary Resource` Constraint).
///
Expand Down Expand Up @@ -37,7 +40,7 @@ struct DisjunctiveConstraint<Var> {
}

impl<Var: IntegerVariable + 'static> Constraint for DisjunctiveConstraint<Var> {
fn post(self, solver: &mut crate::Solver) -> Result<(), crate::ConstraintOperationError> {
fn post(self, solver: &mut Solver) -> Result<(), ConstraintOperationError> {
// We post both the propagator on the lower-bound and the propagator on the upper-bound.
DisjunctiveConstructor::new(self.tasks.clone(), self.constraint_tag).post(solver)?;
DisjunctiveConstructor::new(
Expand All @@ -54,9 +57,9 @@ impl<Var: IntegerVariable + 'static> Constraint for DisjunctiveConstraint<Var> {

fn implied_by(
self,
solver: &mut crate::Solver,
reification_literal: crate::variables::Literal,
) -> Result<(), crate::ConstraintOperationError> {
solver: &mut Solver,
reification_literal: Literal,
) -> Result<(), ConstraintOperationError> {
// We post both the propagator on the lower-bound and the propagator on the upper-bound.
DisjunctiveConstructor::new(self.tasks.clone(), self.constraint_tag)
.implied_by(solver, reification_literal)?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::Constraint;
use crate::proof::ConstraintTag;
use crate::propagators::element::ElementArgs;
use crate::variables::IntegerVariable;
use pumpkin_core::constraints::Constraint;
use pumpkin_core::proof::ConstraintTag;
use pumpkin_core::variables::IntegerVariable;
use pumpkin_propagators::element::ElementArgs;

/// Creates the [element](https://sofdem.github.io/gccat/gccat/Celement.html) [`Constraint`] which states that `array[index] = rhs`.
pub fn element<ElementVar: IntegerVariable + 'static>(
Expand Down
Loading