pub trait RandomWalk {
    type State: PartialEq + Clone;

    // Required methods
    fn make_move<R: Rng>(&mut self, rng: &mut R);
    fn get_state(&self) -> Self::State;
    fn set_state(&mut self, state: Self::State);

    // Provided methods
    fn walk<R: Rng>(
        &mut self,
        src: Self::State,
        tgt: Self::State,
        rng: &mut R
    ) -> u32 { ... }
    fn walk_until_limit<R: Rng>(
        &mut self,
        src: Self::State,
        tgt: Self::State,
        rng: &mut R,
        limit: u32
    ) -> Result<u32, u32> { ... }
}
Expand description

Implement random walks on a state machine.

Required Associated Types§

source

type State: PartialEq + Clone

The representation of state in this state machine.

Required Methods§

source

fn make_move<R: Rng>(&mut self, rng: &mut R)

Make a random move on the internal state machine.

source

fn get_state(&self) -> Self::State

Return the current state of the machine.

source

fn set_state(&mut self, state: Self::State)

Set the state of the internal state machine.

Provided Methods§

source

fn walk<R: Rng>( &mut self, src: Self::State, tgt: Self::State, rng: &mut R ) -> u32

Perform a random walk, starting at src, and making random moves until the tgt state is reached. This does not terminate at zero steps if src and tgt are the same, a move is always made first before continuing until tgt.

Returns the number of steps it took. This method could block forever if the state diverges somehow and never arrives at tgt. See also walk_until_limit.

source

fn walk_until_limit<R: Rng>( &mut self, src: Self::State, tgt: Self::State, rng: &mut R, limit: u32 ) -> Result<u32, u32>

Same as walk_until, but also takes a limit parameter, specifying the maximum length of the walk we should allow before bailing out. Returns Ok(num_steps) if tgt is reached at or before the limit, and Err(limit) otherwise.

Panics

Panics if limit is zero.

Implementors§