pub enum Domain {
Bool,
Int(Vec<Range<i32>>),
Empty(ReturnType),
Reference(Name),
Set(SetAttr, Box<Domain>),
Matrix(Box<Domain>, Vec<Domain>),
Tuple(Vec<Domain>),
Record(Vec<RecordEntry>),
}
Variants§
Bool
Int(Vec<Range<i32>>)
An integer domain.
-
If multiple ranges are inside the domain, the values in the domain are the union of these ranges.
-
If no ranges are given, the int domain is considered unconstrained, and can take any integer value.
Empty(ReturnType)
An empty domain of the given type.
Reference(Name)
Set(SetAttr, Box<Domain>)
Matrix(Box<Domain>, Vec<Domain>)
A n-dimensional matrix with a value domain and n-index domains
Tuple(Vec<Domain>)
Record(Vec<RecordEntry>)
Implementations§
Source§impl Domain
impl Domain
Sourcepub fn contains(&self, lit: &Literal) -> Result<bool, DomainOpError>
pub fn contains(&self, lit: &Literal) -> Result<bool, DomainOpError>
Returns true if lit
is a member of the domain.
§Errors
DomainOpError::InputContainsReference
if the input domain is a reference or contains a reference, meaning that its members cannot be determined.
Sourcepub fn values_i32(&self) -> Result<Vec<i32>, DomainOpError>
pub fn values_i32(&self) -> Result<Vec<i32>, DomainOpError>
Returns a list of all possible values in the domain.
§Errors
DomainOpError::InputNotInteger
if the domain is not an integer domain.DomainOpError::InputUnbounded
if the domain is unbounded.
Sourcepub fn from_slice_i32(elements: &[i32]) -> Domain
pub fn from_slice_i32(elements: &[i32]) -> Domain
Creates an Domain::Int
containing the given integers.
Domain::from_set_i32
should be used instead where possible, as it is cheaper (it does
not need to sort its input).
§Examples
use conjure_cp_core::ast::{Domain,Range};
use conjure_cp_core::{domain_int,range};
let elements = vec![1,2,3,4,5];
let domain = Domain::from_slice_i32(&elements);
assert_eq!(domain,domain_int!(1..5));
use conjure_cp_core::ast::{Domain,Range};
use conjure_cp_core::{domain_int,range};
let elements = vec![1,2,4,5,7,8,9,10];
let domain = Domain::from_slice_i32(&elements);
assert_eq!(domain,domain_int!(1..2,4..5,7..10));
use conjure_cp_core::ast::{Domain,Range,ReturnType};
let elements = vec![];
let domain = Domain::from_slice_i32(&elements);
assert!(matches!(domain,Domain::Empty(ReturnType::Int)))
Sourcepub fn from_set_i32(elements: &BTreeSet<i32>) -> Domain
pub fn from_set_i32(elements: &BTreeSet<i32>) -> Domain
Creates an Domain::Int
containing the given integers.
§Examples
use conjure_cp_core::ast::{Domain,Range};
use conjure_cp_core::{domain_int,range};
use std::collections::BTreeSet;
let elements = BTreeSet::from([1,2,3,4,5]);
let domain = Domain::from_set_i32(&elements);
assert_eq!(domain,domain_int!(1..5));
use conjure_cp_core::ast::{Domain,Range};
use conjure_cp_core::{domain_int,range};
use std::collections::BTreeSet;
let elements = BTreeSet::from([1,2,4,5,7,8,9,10]);
let domain = Domain::from_set_i32(&elements);
assert_eq!(domain,domain_int!(1..2,4..5,7..10));
use conjure_cp_core::ast::{Domain,Range,ReturnType};
use std::collections::BTreeSet;
let elements = BTreeSet::from([]);
let domain = Domain::from_set_i32(&elements);
assert!(matches!(domain,Domain::Empty(ReturnType::Int)))
Sourcepub fn from_literal_vec(literals: Vec<Literal>) -> Result<Domain, DomainOpError>
pub fn from_literal_vec(literals: Vec<Literal>) -> Result<Domain, DomainOpError>
For a vector of literals, creates a domain that contains all the elements.
The literals must all be of the same type.
For abstract literals, this method merges the element domains of the literals, but not the index domains. Thus, for fixed-sized abstract literals (matrices, tuples, records, etc.), all literals in the vector must also have the same size / index domain:
- Matrices: all literals must have the same index domain.
- Tuples: all literals must have the same number of elements.
- Records: all literals must have the same fields.
§Errors
- DomainOpError::InputWrongType if the input literals are of a different type to each-other, as described above.
§Examples
use conjure_cp_core::ast::{Domain,Range,Literal,ReturnType};
let domain = Domain::from_literal_vec(vec![]);
assert_eq!(domain,Ok(Domain::Empty(ReturnType::Unknown)));
use conjure_cp_core::ast::{Domain,Range,Literal, AbstractLiteral};
use conjure_cp_core::{domain_int, range, matrix};
// `[1,2;int(2..3)], [4,5; int(2..3)]` has domain
// `matrix indexed by [int(2..3)] of int(1..2,4..5)`
let matrix_1 = Literal::AbstractLiteral(matrix![Literal::Int(1),Literal::Int(2);domain_int!(2..3)]);
let matrix_2 = Literal::AbstractLiteral(matrix![Literal::Int(4),Literal::Int(5);domain_int!(2..3)]);
let domain = Domain::from_literal_vec(vec![matrix_1,matrix_2]);
let expected_domain = Ok(Domain::Matrix(
Box::new(domain_int!(1..2,4..5)),vec![domain_int!(2..3)]));
assert_eq!(domain,expected_domain);
use conjure_cp_core::ast::{Domain,Range,Literal, AbstractLiteral,DomainOpError};
use conjure_cp_core::{domain_int, range, matrix};
// `[1,2;int(2..3)], [4,5; int(1..2)]` cannot be combined
// `matrix indexed by [int(2..3)] of int(1..2,4..5)`
let matrix_1 = Literal::AbstractLiteral(matrix![Literal::Int(1),Literal::Int(2);domain_int!(2..3)]);
let matrix_2 = Literal::AbstractLiteral(matrix![Literal::Int(4),Literal::Int(5);domain_int!(1..2)]);
let domain = Domain::from_literal_vec(vec![matrix_1,matrix_2]);
assert_eq!(domain,Err(DomainOpError::InputWrongType));
use conjure_cp_core::ast::{Domain,Range,Literal, AbstractLiteral};
use conjure_cp_core::{domain_int,range, matrix};
// `[[1,2; int(1..2)];int(2)], [[4,5; int(1..2)]; int(2)]` has domain
// `matrix indexed by [int(2),int(1..2)] of int(1..2,4..5)`
let matrix_1 = Literal::AbstractLiteral(matrix![Literal::AbstractLiteral(matrix![Literal::Int(1),Literal::Int(2);domain_int!(1..2)]); domain_int!(2)]);
let matrix_2 = Literal::AbstractLiteral(matrix![Literal::AbstractLiteral(matrix![Literal::Int(4),Literal::Int(5);domain_int!(1..2)]); domain_int!(2)]);
let domain = Domain::from_literal_vec(vec![matrix_1,matrix_2]);
let expected_domain = Ok(Domain::Matrix(
Box::new(domain_int!(1..2,4..5)),
vec![domain_int!(2),domain_int!(1..2)]));
assert_eq!(domain,expected_domain);
Sourcepub fn values(&self) -> Result<Vec<Literal>, DomainOpError>
pub fn values(&self) -> Result<Vec<Literal>, DomainOpError>
Gets all the Literal
values inside this domain.
§Errors
DomainOpError::InputNotInteger
if the domain is not an integer domain.DomainOpError::InputContainsReference
if the domain is a reference or contains a reference, meaning that its values cannot be determined.
Sourcepub fn length(&self) -> Result<usize, DomainOpError>
pub fn length(&self) -> Result<usize, DomainOpError>
Gets the length of this domain.
§Errors
DomainOpError::InputUnbounded
if the input domain is of infinite size.DomainOpError::InputContainsReference
if the input domain is or contains a domain reference, meaning that its size cannot be determined.
Sourcepub fn apply_i32(
&self,
op: fn(i32, i32) -> Option<i32>,
other: &Domain,
) -> Result<Domain, DomainOpError>
pub fn apply_i32( &self, op: fn(i32, i32) -> Option<i32>, other: &Domain, ) -> Result<Domain, DomainOpError>
Returns the domain that is the result of applying a binary operation to two integer domains.
The given operator may return None
if the operation is not defined for its arguments.
Undefined values will not be included in the resulting domain.
§Errors
DomainOpError::InputUnbounded
if either of the input domains are unbounded.DomainOpError::InputNotInteger
if either of the input domains are not integers.
Sourcepub fn is_finite(&self) -> Result<bool, DomainOpError>
pub fn is_finite(&self) -> Result<bool, DomainOpError>
Returns true if the domain is finite.
§Errors
DomainOpError::InputContainsReference
if the input domain is or contains a domain reference, meaning that its size cannot be determined.
Sourcepub fn resolve(self, symbols: &SymbolTable) -> Domain
pub fn resolve(self, symbols: &SymbolTable) -> Domain
Resolves this domain to a ground domain, using the symbol table provided to resolve references.
A domain is ground iff it is not a domain reference, nor contains any domain references.
See also: SymbolTable::resolve_domain
.
§Panics
- If a reference domain in
self
does not exist in the given symbol table.
Sourcepub fn intersect(&self, other: &Domain) -> Result<Domain, DomainOpError>
pub fn intersect(&self, other: &Domain) -> Result<Domain, DomainOpError>
Calculates the intersection of two domains.
§Errors
DomainOpError::InputUnbounded
if either of the input domains are unbounded.DomainOpError::InputWrongType
if the input domains are different types, or are not integer or set domains.
Sourcepub fn union(&self, other: &Domain) -> Result<Domain, DomainOpError>
pub fn union(&self, other: &Domain) -> Result<Domain, DomainOpError>
Calculates the union of two domains.
§Errors
DomainOpError::InputUnbounded
if either of the input domains are unbounded.DomainOpError::InputWrongType
if the input domains are different types, or are not integer set, or matrix domains. This is also thrown if the matrix domains that have different index domains.
Trait Implementations§
Source§impl Biplate<Domain> for Domain
impl Biplate<Domain> for Domain
Source§fn biplate(&self) -> (Tree<Domain>, Box<dyn Fn(Tree<Domain>) -> Domain>)
fn biplate(&self) -> (Tree<Domain>, Box<dyn Fn(Tree<Domain>) -> Domain>)
§fn with_children_bi(&self, children: VecDeque<To>) -> Self
fn with_children_bi(&self, children: VecDeque<To>) -> Self
§fn descend_bi(&self, op: &impl Fn(To) -> To) -> Self
fn descend_bi(&self, op: &impl Fn(To) -> To) -> Self
Uniplate::descend
] Read more§fn universe_bi(&self) -> VecDeque<To>
fn universe_bi(&self) -> VecDeque<To>
§fn children_bi(&self) -> VecDeque<To>
fn children_bi(&self) -> VecDeque<To>
§fn transform_bi(&self, op: &impl Fn(To) -> To) -> Self
fn transform_bi(&self, op: &impl Fn(To) -> To) -> Self
§fn holes_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
fn holes_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
§fn contexts_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
fn contexts_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
Source§impl<'de> Deserialize<'de> for Domain
impl<'de> Deserialize<'de> for Domain
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Domain, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Domain, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Domain
impl Serialize for Domain
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl Typeable for Domain
impl Typeable for Domain
fn return_type(&self) -> Option<ReturnType>
Source§impl Uniplate for Domain
impl Uniplate for Domain
Source§fn uniplate(&self) -> (Tree<Domain>, Box<dyn Fn(Tree<Domain>) -> Domain>)
fn uniplate(&self) -> (Tree<Domain>, Box<dyn Fn(Tree<Domain>) -> Domain>)
Uniplate
. Read more§fn descend(&self, op: &impl Fn(Self) -> Self) -> Self
fn descend(&self, op: &impl Fn(Self) -> Self) -> Self
§fn universe(&self) -> VecDeque<Self>
fn universe(&self) -> VecDeque<Self>
§fn with_children(&self, children: VecDeque<Self>) -> Self
fn with_children(&self, children: VecDeque<Self>) -> Self
§fn transform(&self, f: &impl Fn(Self) -> Self) -> Self
fn transform(&self, f: &impl Fn(Self) -> Self) -> Self
§fn rewrite(&self, f: &impl Fn(Self) -> Option<Self>) -> Self
fn rewrite(&self, f: &impl Fn(Self) -> Option<Self>) -> Self
§fn cata<T>(&self, op: &impl Fn(Self, VecDeque<T>) -> T) -> T
fn cata<T>(&self, op: &impl Fn(Self, VecDeque<T>) -> T) -> T
impl Eq for Domain
impl StructuralPartialEq for Domain
Auto Trait Implementations§
impl Freeze for Domain
impl RefUnwindSafe for Domain
impl Send for Domain
impl Sync for Domain
impl Unpin for Domain
impl UnwindSafe for Domain
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 40 bytes
Size for each variant:
Bool
: 0 bytesInt
: 28 bytesEmpty
: 36 bytesReference
: 36 bytesSet
: 20 bytesMatrix
: 36 bytesTuple
: 28 bytesRecord
: 28 bytes