pub struct Domain { /* private fields */ }Expand description
The Domain type specifies a problem domain in which to plan.
§Usage
This is the top-level type of a domain description. See also Problem.
§Example
let input = r#"(define (domain briefcase-world)
(:requirements :strips :equality :typing :conditional-effects)
(:types location physob)
(:constants
B ; the briefcase
P ; the paycheck
D
- physob)
(:predicates (at ?x - physob ?y - location) ; an item is at a location
(in ?x ?y - physob)) ; an item is in another item
(:constraints (and))
; Move briefcase from one location to another.
(:action mov-B
:parameters (?m ?l - location)
:precondition (and (at B ?m) (not (= ?m ?l)))
:effect (and (at B ?l) (not (at B ?m))
(forall (?z)
(when (and (in ?z) (not (= ?z B)))
(and (at ?z ?l) (not (at ?z ?m)))))) )
; Put the item in the briefcase.
(:action put-in
:parameters (?x - physob ?l - location)
:precondition (not (= ?x B)) ; the item must not be the briefcase itself
:effect (when (and (at ?x ?l) (at B ?l))
(in ?x)) )
; Take the item out of the briefcase.
(:action take-out
:parameters (?x - physob)
:precondition (not (= ?x B)) ; the item must be the briefcase itself
:effect (not (in ?x)) )
)"#;
let domain = Domain::from_str(input).unwrap();
assert_eq!(domain.name(), "briefcase-world");
assert_eq!(domain.requirements().len(), 4);
assert_eq!(domain.types().len(), 2);
assert_eq!(domain.constants().len(), 3);
assert_eq!(domain.predicates().len(), 2);
assert!(domain.constraints().is_empty());
assert_eq!(domain.structure().len(), 3);Implementations§
Source§impl Domain
impl Domain
Sourcepub fn builder(name: Name, structure: StructureDefs) -> Self
pub fn builder(name: Name, structure: StructureDefs) -> Self
Creates a builder to easily construct Domain instances.
Sourcepub fn with_extends<N: IntoIterator<Item = Name>>(self, names: N) -> Self
pub fn with_extends<N: IntoIterator<Item = Name>>(self, names: N) -> Self
Adds a list of optional domain names this domain definition extends upon. This is a PDDL 1.2 construct.
Sourcepub fn with_requirements(self, requirements: Requirements) -> Self
pub fn with_requirements(self, requirements: Requirements) -> Self
Adds a list of optional domain requirements.
Sourcepub fn with_types<T: Into<Types>>(self, types: T) -> Self
pub fn with_types<T: Into<Types>>(self, types: T) -> Self
Adds a list of optional type declarations.
Sourcepub fn with_constants<C: Into<Constants>>(self, constants: C) -> Self
pub fn with_constants<C: Into<Constants>>(self, constants: C) -> Self
Adds a list of optional constant declarations.
Sourcepub fn with_predicates<P: Into<PredicateDefinitions>>(
self,
predicates: P,
) -> Self
pub fn with_predicates<P: Into<PredicateDefinitions>>( self, predicates: P, ) -> Self
Adds a list of optional predicate definitions.
Sourcepub fn with_functions<F: Into<Functions>>(self, functions: F) -> Self
pub fn with_functions<F: Into<Functions>>(self, functions: F) -> Self
Adds a list of optional function definitions.
Sourcepub fn with_constraints(self, constraints: DomainConstraintsDef) -> Self
pub fn with_constraints(self, constraints: DomainConstraintsDef) -> Self
Adds a list of optional constraints.
Sourcepub fn with_timeless(self, timeless: Timeless) -> Self
pub fn with_timeless(self, timeless: Timeless) -> Self
Adds a list of timeless predicates.
Sourcepub fn extends(&self) -> &[Name]
pub fn extends(&self) -> &[Name]
Gets the names of the domains this definition extends. This is a PDDL 1.2 construct.
Sourcepub const fn requirements(&self) -> &Requirements
pub const fn requirements(&self) -> &Requirements
Returns the optional domain requirements. If no requirements were specified by the domain, STRIPS is implied.
Sourcepub const fn predicates(&self) -> &PredicateDefinitions
pub const fn predicates(&self) -> &PredicateDefinitions
Returns the optional predicate definitions.
Sourcepub const fn constraints(&self) -> &ConGD
pub const fn constraints(&self) -> &ConGD
Returns the optional constraint declaration.
Sourcepub const fn structure(&self) -> &StructureDefs
pub const fn structure(&self) -> &StructureDefs
Returns the domain structure definitions.
Trait Implementations§
Source§impl AsRef<PredicateDefinitions> for Domain
impl AsRef<PredicateDefinitions> for Domain
Source§fn as_ref(&self) -> &PredicateDefinitions
fn as_ref(&self) -> &PredicateDefinitions
Source§impl AsRef<Requirements> for Domain
impl AsRef<Requirements> for Domain
Source§fn as_ref(&self) -> &Requirements
fn as_ref(&self) -> &Requirements
Source§impl AsRef<StructureDefs> for Domain
impl AsRef<StructureDefs> for Domain
Source§fn as_ref(&self) -> &StructureDefs
fn as_ref(&self) -> &StructureDefs
Source§impl Parser for Domain
Available on crate feature parser only.
impl Parser for Domain
parser only.Source§fn parse<'a, S: Into<Span<'a>>>(input: S) -> ParseResult<'a, Self::Item>
fn parse<'a, S: Into<Span<'a>>>(input: S) -> ParseResult<'a, Self::Item>
Parses a domain definition.
§Example
let input = r#"
; A toy domain.
(define (domain briefcase-world)
; If no requirements are provided, :strips is implied.
(:requirements :strips :equality :typing :conditional-effects)
(:types location physob) ; type definitions could also be represented as predicates
(:constants B P D - physob)
(:predicates (at ?x - physob ?y - location)
(in ?x ?y - physob))
(:constraints (and))
; Move briefcase from one location to another.
(:action mov-B
:parameters (?m ?l - location)
:precondition (and (at B ?m) (not (= ?m ?l)))
:effect (and (at B ?l) (not (at B ?m))
(forall (?z)
(when (and (in ?z) (not (= ?z B)))
(and (at ?z ?l) (not (at ?z ?m)))))) )
; Put the item in the briefcase if it is not already in there.
(:action put-in
:parameters (?x - physob ?l - location)
:precondition (not (= ?x B))
:effect (when (and (at ?x ?l) (at B ?l))
(in ?x)) )
; Take the item out of the briefcase if it is in there.
(:action take-out
:parameters (?x - physob)
:precondition (not (= ?x B))
:effect (not (in ?x)) )
)"#;
let (_, domain) = Domain::parse(input).unwrap();
assert_eq!(domain.name(), &Name::new("briefcase-world"));
assert_eq!(domain.requirements().len(), 4);
assert_eq!(domain.types().len(), 2);
assert_eq!(domain.constants().len(), 3);
assert_eq!(domain.predicates().len(), 2);
assert!(domain.constraints().is_empty());
assert_eq!(domain.structure().len(), 3);§See also
See parse_domain.
type Item = Domain
Source§fn parse_span(input: Span<'_>) -> ParseResult<'_, Self::Item>
fn parse_span(input: Span<'_>) -> ParseResult<'_, Self::Item>
input into the specified Item type.Source§fn from_str(input: &str) -> Result<Self::Item, Err<ParseError<'_>>>
fn from_str(input: &str) -> Result<Self::Item, Err<ParseError<'_>>>
Parser::parse method to parse the input and, if successful,
discards the unparsed remaining input.