Skip to main content

Validator

Struct Validator 

Source
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>

Source

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.

Source

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);
Source

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.

Source

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.

Source

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.

Source

pub fn validate(&self, plan: &Plan) -> Report

Runs plan from the initial state and checks the goal in the final state.

Validation stops at the first violation, which the report names together with the step, the failing condition and a repair hint.

Trait Implementations§

Source§

impl<'a> Debug for Validator<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Accept<V, T, O> for T
where V: Visitor<T, O>,

Source§

fn accept(&self, v: &V) -> O

Lets the visitor v visit self.
Source§

impl<V, T, O> AcceptMut<V, T, O> for T
where V: VisitorMut<T, O>,

Source§

fn accept_mut(&self, v: &mut V) -> O

Lets the mutable visitor v visit self.
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.