Automata.Core - Core library (zero-dependency library, optimal if you do not need visualization).
Automata.Visualization - Full library that also includes visualization and rendering of automata.
The Automata library provides functionality for working with finite-state automata. The library is highly optimized and ideal for very large automata.
⭐ Example Features:
- Create automata from regular expressions, sequences, or other data.
- Convert NFAs to DFAs.
- Minimize Automata to their optimal minimal representation.
- Provides Alang (Automata Language) as an option for defining and creating automata.
- Perform many operations on automata (union, intersection, difference, complement, etc.).
- Visualize automata as graphs (Automata.Visualization).
The core library all provides essential tools for finite-state automata operations. It offers a fast, lightweight and clean solution without visualization features.
The following example utilizes regular expressions written in Alang
.
Alang
(Automata Language) is a language for defining automata using regular operations.
Read more about Alang
in the Automata documentation.
// Compile a regex to a FSA (all sequences of {a, b, c} where any 'a' must be followed by 'b' or 'c')
var fsa = AlangRegex.Compile("(a? (b | c) )+");
// Compile two other automata
var test1 = AlangRegex.Compile("a b b c b");
var test2 = AlangRegex.Compile("a b a a b");
// Test the language overlap of the FSA with the two test regexes
Console.WriteLine(fsa.Overlaps(test1)); //output: true
Console.WriteLine(fsa.Overlaps(test2)); //output: false
The Automata.Visualization library extends the core Automata functionality with visualization capabilities, utilizing MSAGL (Microsoft Automatic Graph Library) for layout.
🔑 Key Features:
- All Automata.Core functionality.
- Visualize automata as graphs.
var fsa = AlangRegex.Compile("(a? (b | c) )+"); // Create an FSA from a regex
Console.WriteLine("Creating a minimal FSA and displaying it."); // Write some info to the console
Graph graph = fsa.CreateGraph(displayStateIDs: true); // Create a graph object (FSA with layout)
GraphView graphView = GraphView.OpenNew(graph); // Open a new non-modal window that displays the graph
Console.WriteLine("FSA is displayed."); // Write some info to the console
Install the packages via the .NET CLI or Package Manager in Visual Studio.
dotnet add package Automata.Core
dotnet add package Automata.Visualization
- Automata.Core: .NET 9.0 and later
- Automata.Visualization: .NET 9.0 and later
- Requires Windows compile target
<TargetFramework>net9.0-windows</TargetFramework>
- Requires Windows compile target
-
Automata.Core:
- None
-
Automata.Visualization:
-
These dependencies will be automatically installed when you install
Automata.Visualization
via NuGet.
This project is licensed under the MIT License.
This repository uses the following libraries and tools:
- FSM layout and rendering (in project Automata.Visualization): Microsoft.MSAGL
- Docs generation: docfx
- Docs template SingulinkFX