pub struct Task {
pub variables: Vec<Variable>,
pub operators: Vec<Operator>,
pub initial: State,
pub goal: Vec<Fact>,
pub axioms: Vec<Axiom>,
}Expand description
A SAS+ planning task with Fast Downward’s extensions: conditional effects and axioms (derived variables).
The fields are public and unchecked; Task::validate checks that they
are consistent.
Fields§
§variables: Vec<Variable>The variables, indexed by VarId.
operators: Vec<Operator>The operators, indexed by OpId.
initial: StateAs in Fast Downward, the values of derived variables here are their
defaults, which hold unless an axiom derives otherwise. Use
Task::initial_state for the state with axioms evaluated.
goal: Vec<Fact>The goal, a partial state.
axioms: Vec<Axiom>The axiom rules that compute the derived variables.
Implementations§
Source§impl Task
impl Task
Sourcepub fn validate(&self) -> Result<(), TaskError>
pub fn validate(&self) -> Result<(), TaskError>
Checks that the task is consistent, so the other methods can index it without panicking.
§Errors
Returns the first problem found, checking the initial state, the goal, the operators and then the axioms, in order:
TaskError::InitialStateArityifinitialhas the wrong length;TaskError::UnknownVariableorTaskError::ValueOutOfRangefor a fact outside the variables or their domains;TaskError::ContradictoryGoalandTaskError::ContradictoryPreconditionfor two required values of one variable;TaskError::DerivedVariableEffectfor an operator that sets a derived variable, andTaskError::DuplicateEffectfor two unconditional effects on one variable;TaskError::AxiomHeadNotDerivedandTaskError::AxiomLayerfor axioms that break the layering.
Sourcepub fn num_variables(&self) -> usize
pub fn num_variables(&self) -> usize
The number of variables, state and derived.
Sourcepub fn is_applicable(&self, op: OpId, state: &State) -> bool
pub fn is_applicable(&self, op: OpId, state: &State) -> bool
Whether operator op’s precondition holds in state.
§Panics
If op is not an operator of the task, or state lacks a variable
the precondition mentions.
Sourcepub fn apply(&self, op: OpId, state: &State) -> State
pub fn apply(&self, op: OpId, state: &State) -> State
The successor state. Effect conditions are evaluated in state;
derived variables are then re-evaluated.
Like Task::is_applicable and Task::is_goal, this reads derived
variables from state as given, so state must have them evaluated:
start from Task::initial_state (not Task::initial) or call
Task::evaluate_axioms first. States returned by apply are.
§Panics
If op is not an operator of the task, or state has fewer values
than the task has variables.
Sourcepub fn evaluate_axioms(&self, state: &mut State)
pub fn evaluate_axioms(&self, state: &mut State)
Recomputes all derived variables of state from its state variables:
each derived variable is reset to its default (its value in
Task::initial), then the axioms fire layer by layer until nothing
changes, as in Fast Downward. A variable keeps the first non-default
value derived for it.
This allocates nothing but rescans the rules of a layer until none fires; search code that needs speed on axiom-heavy tasks should index the rules itself.
§Panics
If state has fewer values than the task has variables.
Sourcepub fn initial_state(&self) -> State
pub fn initial_state(&self) -> State
The initial state with derived variables evaluated.
Sourcepub fn applicable_operators<'a>(
&'a self,
state: &'a State,
) -> impl Iterator<Item = OpId> + 'a
pub fn applicable_operators<'a>( &'a self, state: &'a State, ) -> impl Iterator<Item = OpId> + 'a
The operators applicable in state, in id order.
Sourcepub fn costs(&self) -> Vec<u64>
pub fn costs(&self) -> Vec<u64>
Operator costs indexed by operator id (the label cost function).
Sourcepub fn validate_plan(&self, plan: &[OpId]) -> Option<u64>
pub fn validate_plan(&self, plan: &[OpId]) -> Option<u64>
Checks that plan is applicable from the initial state and reaches the goal.
Returns the plan cost, or None if an operator is not applicable where
the plan uses it or the plan does not end in a goal state.
§Panics
If plan names an operator the task does not have.
Sourcepub fn perfect_heuristic(&self) -> impl Fn(&State) -> Option<u64> + '_
pub fn perfect_heuristic(&self) -> impl Fn(&State) -> Option<u64> + '_
Optimal plan cost from state (with derived variables evaluated),
by building the full state space over all state variables.
Exponential; intended for tests on tiny tasks.
The returned function gives None for states from which no goal is
reachable.
§Panics
If the state space over the state variables has more than
usize::MAX states. The returned function panics on states with
fewer values than the task has variables.