Sequential

Struct Sequential 

Source
pub struct Sequential<D> {
    pub inner: D,
    /* private fields */
}
Expand description

Wraps another decision maker by performing one read from sensor or one write to actuator at a time.

This is used for testing or developing new decision makers. The inner decision maker can be written using the assumption that there are no concurrent reads or writes.

Fields§

§inner: D

The inner decison maker.

Implementations§

Source§

impl<D> Sequential<D>

Source

pub fn new(inner: D) -> Self

Returns a new sequential decision maker.

Examples found in repository?
examples/bob_sleeps.rs (line 163)
140fn main() {
141    use asi::Runtime;
142
143    println!("Bob is sleeping.");
144    println!("Enter - One time step forward");
145    println!("'bye' - Exit");
146    println!("'wake up!' - Wake up Bob");
147    println!("");
148
149    let ref mut runtime = asi::StandardRuntime::new();
150    runtime.load(asi::Agent {
151        // Try remove the `()` to cause invalid memory access.
152        memory: vec![()],
153        // Don't need any sensors in this example.
154        sensors: Vec::<Sensor>::new(),
155        actuators: vec![
156            // Try comment this to write to wrong actuator.
157            Actuator::INeedJustFiveMinutes(false),
158            // Try comment this to cause invalid actuator access.
159            Actuator::LookAround(false),
160        ],
161        // Make sure Bob takes sequential decisions,
162        // because we don't want to think about concurrency.
163        decision_maker: asi::Sequential::new(Bob::Sleep),
164    });
165    runtime.start();
166
167    let stdin = ::std::io::stdin();
168    loop {
169        runtime.update(1.0);
170
171        let mut input = String::new();
172        stdin.read_line(&mut input).unwrap();
173        input = input.trim().into();
174
175        if input == "bye" {
176            println!("Bob: Bye!");
177            break;
178        } else if input == "wake up!" {
179            runtime.wake_up();
180        }
181    }
182}

Trait Implementations§

Source§

impl<D, T> DecisionMaker<T> for Sequential<D>
where D: DecisionMaker<T>,

Source§

fn next_action(&mut self, memory: &[T], dt: f64) -> Action

Outputs the next action to take from the memory states and time step.
Source§

fn feedback(&mut self, feedback: Result<Feedback, Error>)

Receiving feedback when something new happens.
Source§

fn shut_down(&mut self, dt: f64) -> f64

Return estimate of how long it takes to shut down from now, given a deadline. This is 0 if the decison maker is ready to shut down. When this is called, the decision maker should start preparing for shutdown. It might be called multiple times to check how the decision maker is preparing.

Auto Trait Implementations§

§

impl<D> Freeze for Sequential<D>
where D: Freeze,

§

impl<D> RefUnwindSafe for Sequential<D>
where D: RefUnwindSafe,

§

impl<D> Send for Sequential<D>
where D: Send,

§

impl<D> Sync for Sequential<D>
where D: Sync,

§

impl<D> Unpin for Sequential<D>
where D: Unpin,

§

impl<D> UnwindSafe for Sequential<D>
where D: UnwindSafe,

Blanket Implementations§

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 = 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.