internal Fsm(string Id, IFsmContext context, S GroundState, S EndState, MachineTransition <E, S> Transition, EntryFunction <S, A> Entry, ExitFunction <S, A> Exit) : base(Id, context, GroundState, EndState, Transition) { this.EntryFunc = Entry; this.ExitFunc = Exit; }
public Fsm(string Id, IFsmContext context, S GroundState, S EndState, IFsmFunction <E, S> transition) { this.Id = Id; this.Context = context; this.CurrentState = GroundState; this.EndState = EndState; this.Error = none <Exception>(); this.Transition = transition; this.ReceiptCount = 0; this.TransitionCount = 0; this.Runtime = stopwatch(false); }
static MachineTransition <T, T> Transition <T>(IFsmContext context, PrimalFsmSpec <T> spec) where T : unmanaged { var sources = range <T>(spec.StateCount).ToArray(); var random = context.Random; var rules = new List <TransitionRule <T, T> >(); foreach (var source in sources) { var evss = random.Next <T>(spec.MinEventSamples, spec.MaxEventSamples); var targets = from t in random.SampleDistinct(spec.StateCount, evss) where gmath.neq(t, source) select t; var events = random.SampleDistinct(spec.EventCount, evss); rules.AddRange(events.Zip(targets).Select(x => Fsm.TransitionRule(x.First, source, x.Second))); } return(rules.ToFunction()); }
public void SetFsmContext(IFsmContext context) { this.fsm_context = context; }
/// <summary> /// Defines a machine that supports entry/exit actions on a per-state basis /// </summary> /// <param name="id">Identifies the machine within the context of the executing process</param> /// <param name="s0">The ground-state</param> /// <param name="sZ">The end-state</param> /// <param name="t">The transition function</param> /// <param name="entry">The entry function</param> /// <param name="exit">The exit function</param> /// <typeparam name="E">The event type</typeparam> /// <typeparam name="S">The state type</typeparam> /// <typeparam name="A">The entry action type</typeparam> public static Fsm <E, S, A> Machine <E, S, A>(string id, IFsmContext context, S s0, S sZ, MachineTransition <E, S> t, EntryFunction <S, A> entry, ExitFunction <S, A> exit) => new Fsm <E, S, A>(id, context, s0, sZ, t, entry, exit);
/// <summary> /// Defines the most basic FSM, predicated only on ground-state, end-state and transition function /// </summary> /// <param name="id">Identifies the machine within the context of the executing process</param> /// <param name="s0">The ground-state</param> /// <param name="sZ">The end-state</param> /// <param name="f">The transiion function</param> /// <typeparam name="E">The event type</typeparam> /// <typeparam name="S">The state type</typeparam> public static Fsm <E, S> Machine <E, S>(string id, IFsmContext context, S s0, S sZ, MachineTransition <E, S> f) => new Fsm <E, S>(id, context, s0, sZ, f);