Commit 9ae7d681 authored by Bharat Garhewal's avatar Bharat Garhewal
Browse files

Removed redundant files

parent 597c2b90
/*!
Module containing implementation(s) for a System Under Learning/Testing (SUL/SUT).
### Note
We currently have only one implementation of the
[`SystemUnderLearning`](crate::sul::system_under_learning::SystemUnderLearning)
trait, which simulates a (known) FSM.
*/
pub mod simulator;
pub mod system_under_learning;
use super::system_under_learning::SystemUnderLearning;
use crate::automatadefs::definitions::{
fsm::{BMealy, FiniteStateMachine},
inputs::InputSymbolTrait,
outputs::OutputSymbolTrait,
state::StateTrait,
};
use std::fmt::Debug;
use std::hash::Hash;
use std::sync::Arc;
/**
`Simulator` is the System Under Learning/Testing (SUL/SUT)
that we want to learn. This struct uses an FSM to "simulate"
the behaviour of a real SUL.
*/
#[derive(Debug)]
pub struct Simulator<InputT, OutputT, StateT>
where
InputT: Debug + Clone + PartialEq + Hash + Eq,
OutputT: Debug + Clone + PartialEq + Hash + Eq,
StateT: Debug + Clone + PartialEq + Hash + Eq,
{
fsm: Arc<BMealy<InputT, OutputT, StateT>>,
initial_state: StateT,
curr_state: StateT,
cnt_inputs: usize,
cnt_resets: usize,
}
impl<InputT, OutputT, StateT> SystemUnderLearning for Simulator<InputT, OutputT, StateT>
where
InputT: InputSymbolTrait,
OutputT: OutputSymbolTrait,
StateT: StateTrait,
{
type MachineT = BMealy<InputT, OutputT, StateT>;
fn new(fsm: Arc<Self::MachineT>) -> Self {
Self {
initial_state: fsm.initial_state(),
curr_state: fsm.initial_state(),
fsm,
cnt_inputs: 0,
cnt_resets: 0,
}
}
fn step(&mut self, input_seq: &[InputT]) -> Box<[OutputT]> {
let (dest, out_seq) = self.fsm.trace_from(self.curr_state, input_seq);
self.cnt_inputs += input_seq.len();
self.curr_state = dest;
log::trace!(" {:?} / {:?}", input_seq, out_seq);
out_seq
}
fn reset(&mut self) {
self.cnt_resets += 1;
self.curr_state = self.initial_state;
log::trace!("\tRESET");
}
fn trace(&mut self, input_seq: &[InputT]) -> Box<[OutputT]> {
self.reset();
let (_dest, out_seq) = self.fsm.trace_from(self.curr_state, input_seq);
self.cnt_inputs += input_seq.len();
log::trace!(" {:?} / {:?}", input_seq, out_seq);
out_seq
}
fn get_counts(&mut self) -> (usize, usize) {
let ret = (self.cnt_inputs, self.cnt_resets);
self.cnt_inputs = 0;
self.cnt_resets = 0;
ret
}
fn get_alphabet(
&self,
) -> std::collections::HashSet<InputT, std::hash::BuildHasherDefault<fnv::FnvHasher>> {
self.fsm.input_alphabet()
}
}
use crate::automatadefs::definitions::fsm::FiniteStateMachine;
use fnv::FnvHashSet;
use std::sync::Arc;
/// Trait for a System Under Learning/Testing.
pub trait SystemUnderLearning {
type MachineT: FiniteStateMachine;
/// Constructor.
///
/// As the FSM can never be mutated while learning,
/// it is required to be wrapped in an [`Arc`].
#[must_use]
fn new(fsm: Arc<Self::MachineT>) -> Self;
/// Return the output sequence of the provided input sequence.
#[must_use]
fn step(
&mut self,
input_seq: &[<Self::MachineT as FiniteStateMachine>::InputT],
) -> Box<[<Self::MachineT as FiniteStateMachine>::OutputT]>;
/// Reset the SUL to its initial state.
fn reset(&mut self);
/// A [`step`](crate::sul::system_under_learning::SystemUnderLearning::step) and a
/// [`reset`](crate::sul::system_under_learning::SystemUnderLearning::reset).
#[must_use]
fn trace(
&mut self,
input_seq: &[<Self::MachineT as FiniteStateMachine>::InputT],
) -> Box<[<Self::MachineT as FiniteStateMachine>::OutputT]>;
/// Get the number of inputs and reset send to the SUL thus far,
/// and reset the counters.
#[must_use]
fn get_counts(&mut self) -> (usize, usize);
/// Get a copy of the input alphabet of the SUL.
#[must_use]
fn get_alphabet(&self) -> FnvHashSet<<Self::MachineT as FiniteStateMachine>::InputT>;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment