1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//! # PDDL plan validation
//!
//! An independent plan validator for PDDL, a second opinion next to
//! [VAL](https://github.com/KCL-Planning/VAL). It implements the published semantics on
//! the [`pddl`] syntax tree and shares no grounding or search code with any planner, so
//! it does not share their bugs either.
//!
//! ```
//! use pddl::{Domain, Parser, Problem};
//! use pddl_validate::{ValidationStatus, Validator, ViolationKind};
//!
//! let domain = Domain::from_str(
//! "(define (domain logistics) (:requirements :typing)
//! (:types truck place)
//! (:predicates (at ?t - truck ?p - place))
//! (:action drive
//! :parameters (?t - truck ?from ?to - place)
//! :precondition (at ?t ?from)
//! :effect (and (not (at ?t ?from)) (at ?t ?to))))",
//! ).unwrap();
//! let problem = Problem::from_str(
//! "(define (problem deliver) (:domain logistics)
//! (:objects t1 - truck home shop - place)
//! (:init (at t1 home))
//! (:goal (at t1 shop)))",
//! ).unwrap();
//! let validator = Validator::new(&domain, &problem).unwrap();
//!
//! let report = validator.validate_text("(drive t1 home shop)\n; cost = 1 (unit cost)");
//! assert_eq!(report.status(), ValidationStatus::Valid);
//!
//! let report = validator.validate_text("(drive t1 shop home)");
//! let violation = report.violation().unwrap();
//! assert_eq!(violation.step.as_ref().unwrap().number, 1);
//! assert!(matches!(violation.kind, ViolationKind::PreconditionUnsatisfied(_)));
//! assert_eq!(violation.advice(),
//! "(drive t1 shop home) has an unsatisfied precondition at step 1: (Set (at t1 shop) to true)");
//! ```
//!
//! ## Scope
//!
//! - **Classical plans** (level 1): STRIPS, typing, negative and disjunctive
//! preconditions, equality, `exists`, `forall`, `imply`, conditional effects and
//! stratified derived predicates.
//! - **Numeric plans** (level 2): numeric fluents in conditions and effects (`assign`,
//! `increase`, `decrease`, `scale-up`, `scale-down`), action costs and the problem's
//! `:metric`, which [`Report::metric`] returns for a valid plan.
//!
//! - **Temporal plans** (level 3): durative actions with `at start`, `over all` and
//! `at end` conditions and effects, timestamped plans (`t: (action args) [d]`),
//! duration constraints and inequalities, conditional effects with `at start` or
//! `at end` conditions, linear continuous effects (`#t`), timed initial literals, the
//! epsilon separation of interfering events ([`Validator::with_epsilon`]) and
//! `total-time` as the makespan.
//!
//! - **PDDL+** (level 4): processes, which run while their precondition holds and change
//! fluents linearly, and events, which fire as soon as their precondition holds,
//! in cascades of up to 1000 rounds at one time. The validator finds the times at
//! which processes switch and events trigger exactly, at the roots of the linear
//! conditions.
//!
//! Every construct outside this scope makes the report
//! [`ValidationStatus::Unsupported`], never valid: continuous change whose rate depends
//! on a changing fluent (such as acceleration), conditions that are not linear in time,
//! discrete effects of processes, dynamics that switch without end, derived predicates
//! in temporal plans, preferences, constraints and object fluents.
//!
//! ## Semantics
//!
//! - Names are case-insensitive. Reports show them in ASCII lowercase.
//! - Closed world: an atom not in the state is false.
//! - A step's precondition and the conditions of its `when` effects are evaluated in the
//! state before the step. The next state is the old one minus deleted atoms plus added
//! ones, so an atom that a step both deletes and adds stays true.
//! - Derived predicates are the least fixpoint of their rules, stratum by stratum, and are
//! recomputed after every step.
//! - Numbers are `f64`. Comparisons allow a relative tolerance
//! ([`Validator::with_tolerance`], [`DEFAULT_TOLERANCE`]). A comparison that reads a
//! fluent without a value, divides by zero or leaves the finite range is unknown, and
//! conditions follow three-valued (Kleene) logic: `(or (p) (> (f) 0))` holds if `(p)`
//! holds, and `(and (q) (> (f) 0))` fails on `(q)` if `(q)` is false. A precondition
//! or goal that is still unknown makes the plan invalid, and so does an effect or
//! `when` condition that reads an undefined value. A derived predicate whose rule is
//! unknown is not derived. A metric with an undefined value leaves the plan valid,
//! without a [`Report::metric`]. A nullary `total-cost` without an initial value
//! starts at 0.
//! - Updates of one fluent in one step combine if all are `increase` or `decrease`;
//! any other combination is a [`ViolationKind::ConflictingUpdates`].
//! - In a metric, `total-time` is the number of steps of a sequential plan and the
//! makespan of a temporal one.
//! - Temporal plans follow PDDL 2.1 and VAL. Events at one time form a happening whose
//! conditions are checked in the state before it and whose effects apply at once.
//! `over all` conditions must hold strictly between an action's start and end, and
//! interfering events must be at least epsilon apart. Durations satisfy their
//! constraints within an absolute tolerance ([`Validator::with_duration_tolerance`],
//! [`DEFAULT_DURATION_TOLERANCE`]), and a ground durative action must not overlap itself.
//! - PDDL+ work is bounded: at most 100 000 segments (process switches and event
//! firings) between two plan happenings and 1000 event rounds at one time. A model past
//! either bound, even a legal but very busy one, is reported unsupported as
//! [`Construct::ZenoDynamics`], never valid.
//! - Validation stops at the first violation. Steps count from 1, as in VAL.
//!
//! The crate is `no_std` with `alloc`. That is nominal for now: the `pddl` crate it reads
//! needs `std`.
extern crate alloc;
pub use Atom;
pub use ;
pub use ;
pub use ;
pub use ;
/// The overall result of validating a plan.
///
/// [`ValidationStatus::Unsupported`] is distinct from both other outcomes: a plan that uses
/// constructs the validator cannot interpret is never reported as valid.