pub struct Validator<'a> { /* private fields */ }Expand description
Validates plans for one domain and problem.
Construction checks the domain and problem once; Validator::validate can then run
any number of plans. Validation never panics, whatever the plan.
§Examples
use pddl::{Domain, Parser, Problem};
use pddl_validate::{ValidationStatus, Validator};
let domain = Domain::from_str(
"(define (domain switch) (:predicates (on))
(:action flip :parameters () :precondition (not (on)) :effect (on)))",
).unwrap();
let problem = Problem::from_str(
"(define (problem light) (:domain switch) (:init) (:goal (on)))",
).unwrap();
let validator = Validator::new(&domain, &problem).unwrap();
assert_eq!(validator.validate_text("(flip)").status(), ValidationStatus::Valid);
let report = validator.validate_text("(flip)\n(flip)");
assert_eq!(report.status(), ValidationStatus::Invalid);
assert_eq!(report.violation().unwrap().to_string(),
"step 2 (flip): unsatisfied precondition: (not (on))");Implementations§
Source§impl<'a> Validator<'a>
impl<'a> Validator<'a>
Sourcepub fn new(domain: &'a Domain, problem: &'a Problem) -> Result<Self, ModelError>
pub fn new(domain: &'a Domain, problem: &'a Problem) -> Result<Self, ModelError>
Checks domain and problem and prepares the initial state.
A task that uses a construct the validator does not interpret yet, such as
preferences, still builds a validator, whose every report is
ValidationStatus::Unsupported.
§Errors
A ModelError if the problem is for another domain, or if a formula uses an
undeclared type, predicate, function, object or variable, applies a symbol to the
wrong number of arguments, or sets a derived predicate or =; also for two actions
of one name.
Sourcepub fn with_tolerance(self, tolerance: f64) -> Self
pub fn with_tolerance(self, tolerance: f64) -> Self
Sets the relative tolerance of numeric comparisons, DEFAULT_TOLERANCE unless
set.
Two values a and b are equal if |a - b| <= tolerance * max(1, |a|, |b|);
otherwise they compare as numbers. So (= (x) 0.3) holds after (x) was set to
0.1 and increased by 0.2, and exactly one of <, = and > holds for any pair.
A tolerance of 0 compares exactly; a negative or NaN tolerance counts as 0.
§Examples
use pddl::{Domain, Parser, Problem};
use pddl_validate::{ValidationStatus, Validator};
let domain = Domain::from_str("(define (domain d) (:predicates (done)) (:functions (x))
(:action add :parameters () :effect (increase (x) 0.2))
(:action check :parameters () :precondition (= (x) 0.3) :effect (done)))").unwrap();
let problem = Problem::from_str("(define (problem p) (:domain d)
(:init (= (x) 0.1)) (:goal (done)))").unwrap();
let validator = Validator::new(&domain, &problem).unwrap();
assert_eq!(validator.validate_text("(add) (check)").status(), ValidationStatus::Valid);
let exact = validator.with_tolerance(0.0);
assert_eq!(exact.validate_text("(add) (check)").status(), ValidationStatus::Invalid);Sourcepub fn with_epsilon(self, epsilon: f64) -> Self
pub fn with_epsilon(self, epsilon: f64) -> Self
Sets the least time between two interfering events of a temporal plan,
DEFAULT_EPSILON (VAL’s default) unless set.
Two events interfere (PDDL 2.1 mutex) when one changes an atom or fluent the other
reads or changes, except two increase/decrease updates of one fluent. Such
events must be at least epsilon apart; at the same time or closer, the plan is
invalid with ViolationKind::Interference. A negative or NaN epsilon counts
as 0, which forbids only simultaneous interference.
Sourcepub fn with_duration_tolerance(self, tolerance: f64) -> Self
pub fn with_duration_tolerance(self, tolerance: f64) -> Self
Sets the absolute tolerance of a temporal plan’s durations against the actions’
:duration constraints, DEFAULT_DURATION_TOLERANCE unless set.
A duration d satisfies a constraint with bound b when |d - b| <= tolerance,
and otherwise compares as a number under Validator::with_tolerance. A negative
or NaN tolerance counts as 0.
Sourcepub fn validate_text(&self, text: &str) -> Report
pub fn validate_text(&self, text: &str) -> Report
Parses text as a plan file and validates it.
A plan file that cannot be read is ValidationStatus::Invalid
with ViolationKind::PlanSyntax.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Forget for Validator<'a>
impl<'a> Freeze for Validator<'a>
impl<'a> Move for Validator<'a>
impl<'a> RefUnwindSafe for Validator<'a>
impl<'a> Send for Validator<'a>
impl<'a> Sync for Validator<'a>
impl<'a> Unpin for Validator<'a>
impl<'a> UnsafeUnpin for Validator<'a>
impl<'a> UnwindSafe for Validator<'a>
Blanket Implementations§
Source§impl<V, T, O> AcceptMut<V, T, O> for Twhere
V: VisitorMut<T, O>,
impl<V, T, O> AcceptMut<V, T, O> for Twhere
V: VisitorMut<T, O>,
Source§fn accept_mut(&self, v: &mut V) -> O
fn accept_mut(&self, v: &mut V) -> O
v visit self.