Skip to main content

Plan

Struct Plan 

Source
pub struct Plan {
    pub steps: Vec<PlanStep>,
    pub cost: f64,
}
Expand description

The output produced by a planner when search succeeds.

This is the structure wrapped by SearchOutcome::Plan.

§Invariants

  • steps is ordered: steps[0] is applied first.
  • cost equals the sum of the applied operators’ cost values; it is not necessarily steps.len() because operator costs need not be unit.
  • An empty plan (steps is empty, cost == 0.0) is a valid result when the initial state already satisfies the goal.

§Examples

use miniplan::plan::{Plan, PlanStep};
use miniplan::task::OpId;

let plan = Plan::new();
assert!(plan.is_empty());
assert_eq!(plan.len(), 0);
assert_eq!(plan.cost, 0.0);

let mut plan = Plan::new();
plan.steps.push(PlanStep { op_id: OpId(0), op_name: "pick".into() });
plan.cost = 1.0;
assert!(!plan.is_empty());
assert_eq!(plan.len(), 1);

assert_eq!(
    plan.to_string(),
    "; cost = 1\n; length = 1\n(pick)\n"
);

Fields§

§steps: Vec<PlanStep>

Ordered list of PlanSteps; execute left-to-right.

§cost: f64

Accumulated cost of the steps.

Must stay in sync with steps — callers mutate both together.

Implementations§

Source§

impl Plan

Source

pub fn new() -> Self

Create an empty plan.

The returned value satisfies steps.is_empty() and cost == 0.0. This is equivalent to Plan::default().

§Examples
use miniplan::plan::Plan;

let plan = Plan::new();
assert!(plan.is_empty());
assert_eq!(plan.cost, 0.0);
Source

pub fn is_empty(&self) -> bool

Returns true if the plan has no steps.

§Examples
use miniplan::plan::Plan;

assert!(Plan::new().is_empty());
Source

pub fn len(&self) -> usize

Returns the number of steps in the plan.

This counts steps, not cost.

§Examples
use miniplan::plan::Plan;

assert_eq!(Plan::new().len(), 0);

Trait Implementations§

Source§

impl Clone for Plan

Source§

fn clone(&self) -> Plan

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Plan

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Plan

Source§

fn default() -> Self

Creates an empty plan with steps empty and cost set to 0.0.

Equivalent to Plan::new.

Source§

impl Display for Plan

Human-readable display format for a Plan.

Emits a PDDL-style plan file:

  • Line 1: ; cost = <cost> (semicolons are PDDL plan comments).
  • Line 2: ; length = <len>.
  • Lines 3..: one (<op_name>) per step, each terminated by \n.

The trailing newline after the last step matches the writeln! macro.

§Examples

use miniplan::plan::{Plan, PlanStep};
use miniplan::task::OpId;

let mut plan = Plan::new();
plan.steps.push(PlanStep { op_id: OpId(0), op_name: "pick".into() });
plan.steps.push(PlanStep { op_id: OpId(1), op_name: "place".into() });
plan.cost = 2.0;

assert_eq!(
    plan.to_string(),
    "; cost = 2\n; length = 2\n(pick)\n(place)\n"
);
Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Plan

Source§

fn eq(&self, other: &Plan) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Plan

Auto Trait Implementations§

§

impl Freeze for Plan

§

impl RefUnwindSafe for Plan

§

impl Send for Plan

§

impl Sync for Plan

§

impl Unpin for Plan

§

impl UnsafeUnpin for Plan

§

impl UnwindSafe for Plan

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

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

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.