https://github.com/sakryukov/generic-state-machine
Transition system and state machine generic classes can be instantiated with any enumeration types representing the sets of states and the input and output alphabets
https://github.com/sakryukov/generic-state-machine
acceptors csharp dotnet enumeration finite-state-machine generics graph-algorithms graphs np-hard state-machine transducers transition-matrix transition-systems transitions
Last synced: 27 days ago
JSON representation
Transition system and state machine generic classes can be instantiated with any enumeration types representing the sets of states and the input and output alphabets
- Host: GitHub
- URL: https://github.com/sakryukov/generic-state-machine
- Owner: SAKryukov
- License: mit
- Created: 2024-12-01T10:01:32.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-02-03T13:27:05.000Z (3 months ago)
- Last Synced: 2025-02-03T14:30:35.708Z (3 months ago)
- Topics: acceptors, csharp, dotnet, enumeration, finite-state-machine, generics, graph-algorithms, graphs, np-hard, state-machine, transducers, transition-matrix, transition-systems, transitions
- Language: C#
- Homepage: https://www.SAKryukov.org
- Size: 428 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Generic state machine
The classes [TransitionSystem](https://SAKryukov.GitHub.io/generic-state-machine#heading-class-transitionsystem),
[Acceptor](https://SAKryukov.GitHub.io/generic-state-machine#heading-class-acceptor),
and [Transducer](https://SAKryukov.GitHub.io/generic-state-machine#heading-class-transducer)
can be instantiated with any enumeration types representing the sets of states and the input and output alphabets. For example:~~~
enum RoomDoorState { Locked, Closed, Opened,
OpenedInside, ClosedInside, LockedInside };
TransitionSystem transitionSystem = new();
~~~Then the transition graph can be populated:
~~~
transitionSystem.AddValidStateTransition(RoomDoorState.ClosedInside, RoomDoorState.LockedInside,
(start, finish) => {
// command hardware actuator to lock the door
});
//...
transitionSystem.AddInvalidStateTransition(RoomDoorState.Locked, RoomDoorState.LockedInside,
(start, finish) =>
$"You cannot get in through the locked door"));
~~~Note that both valid and some invalid transitions can be defined. The purpose of the invalid transition is to provide some information on why the transition is not permitted.
Both valid and invalid transitions can come with optional handlers accepting two arguments, the enumeration values representing starting and finishing states. In the case of a valid transition, the handler provides a side effect of transition.
For example, in the hardware automation applications, it can operate the hardware. In the case of an invalid transition, the handler returns a comment string explaining why the transition is not permitted.Please see the comprehensive [API documentation](https://SAKryukov.GitHub.io/generic-state-machine).
For the rationale, general ideas, and mathematical aspects, please see the
[original publication](https://sakryukov.github.io/publications/2024-12-29.Enumeration-Based-Generic-State-Machine.html).