diff --git a/Automata theory.sln b/Automata theory.sln
new file mode 100644
index 0000000..5df03cc
--- /dev/null
+++ b/Automata theory.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.7.34009.444
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Automata theory", "Automata theory\Automata theory.csproj", "{AA601AB6-1E54-4DDC-846A-F4A0230049F2}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {AA601AB6-1E54-4DDC-846A-F4A0230049F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AA601AB6-1E54-4DDC-846A-F4A0230049F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AA601AB6-1E54-4DDC-846A-F4A0230049F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AA601AB6-1E54-4DDC-846A-F4A0230049F2}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {F1B09C6C-E1E2-44EC-A734-8B45DF914DEA}
+ EndGlobalSection
+EndGlobal
diff --git a/Automata theory/Automata theory.csproj b/Automata theory/Automata theory.csproj
new file mode 100644
index 0000000..bcee313
--- /dev/null
+++ b/Automata theory/Automata theory.csproj
@@ -0,0 +1,244 @@
+
+
+
+
+ {BAA0C2D2-18E2-41B9-852F-F413020CAA33};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+ Debug
+ AnyCPU
+ {AA601AB6-1E54-4DDC-846A-F4A0230049F2}
+ Library
+ false
+ Automata_theory
+ Automata theory
+ 3
+ v4.7.2
+ VSTO40
+ true
+ HomeSite
+
+
+
+ False
+ Microsoft Visual Studio 2010 Tools for Office Runtime %28x86 and x64%29
+ true
+
+
+
+
+ Excel
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ false
+ $(DefineConstants);DEBUG;TRACE
+ 4
+
+
+
+ pdbonly
+ true
+ bin\Release\
+ false
+ $(DefineConstants);TRACE
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ False
+
+
+ False
+
+
+ False
+
+
+ False
+
+
+ False
+
+
+
+
+ True
+
+
+
+
+ False
+ true
+
+
+ False
+ true
+
+
+ False
+
+
+
+
+
+
+ Form
+
+
+ Form1.cs
+
+
+
+
+
+
+
+
+ Code
+
+
+ Form1.cs
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+ Designer
+
+
+ True
+ Resources.resx
+
+
+ Ribbon1.cs
+
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+ True
+ Settings.settings
+
+
+ Component
+
+
+ Ribbon1.cs
+
+
+ Code
+
+
+ ThisAddIn.cs
+
+
+ ThisAddIn.Designer.xml
+
+
+
+
+ 10.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+
+
+ true
+
+
+ Automata theory_TemporaryKey.pfx
+
+
+ 71E2C301299111CED893BA74AE375E6B8A8E71C9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Automata theory/Common.cs b/Automata theory/Common.cs
new file mode 100644
index 0000000..29cab84
--- /dev/null
+++ b/Automata theory/Common.cs
@@ -0,0 +1,330 @@
+using Microsoft.Office.Interop.Excel;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using static Automata_theory.Common;
+
+namespace Automata_theory
+{
+ public static class Common
+ {
+ public enum DisplayMode
+ {
+ OnlyStates,
+ OnlyOutput,
+ Everything
+ }
+
+ public static Dictionary SubScripts = new Dictionary()
+ {
+ { 0, "\u2080" },
+ { 1, "\u2081" },
+ { 2, "\u2082" },
+ { 3, "\u2083" },
+ { 4, "\u2084" },
+ { 5, "\u2085" },
+ { 6, "\u2086" },
+ { 7, "\u2087" },
+ { 8, "\u2088" },
+ { 9, "\u2089" },
+ { 10, "\u2081\u2080" }
+ };
+
+ public static AutomataTableBase CreateTable(string msg = "Выберите совмещенную таблицу:")
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox(msg, Type: 8);
+ List outputs = new List();
+ AutomataTableBase table = new AutomataTableBase(RG.Columns.Count - 1, RG.Rows.Count - 1);
+ for (int i = 2; i < RG.Columns.Count + 1; i++)
+ {
+ AutomataStateBase state = new AutomataStateBase(RG.Rows.Count - 1, i - 1);
+ for (int j = 2; j < RG.Rows.Count + 1; j++)
+ {
+ string text = RG.Columns[i].Rows[j].Value2;
+ string toState = text.Split('/')[0].Trim().Trim('S').Trim('b');
+ int ToState = -1; if (int.TryParse(toState, out _)) ToState = Convert.ToInt32(toState) - 1;
+ string output = text.Split('/')[1].Trim().Trim('y');
+ int Output = -1; if (Char.IsNumber(output[0])) Output = Convert.ToInt32(output);
+ if (!outputs.Contains(Output) && Output != -1) outputs.Add(Output);
+ AutomataCellBase cell = new AutomataCellBase(ToState, Output);
+ state.Cells[j - 2] = cell;
+ }
+ table.States[i - 2] = state;
+ }
+ table.Outputs = outputs.Count;
+ return table;
+ }
+
+ public static void DisplayTable(AutomataTableBase table, DisplayMode displayMode = DisplayMode.Everything, string stateLetter = "s", bool displayLetter = true)
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox($"Куда вставить таблицу ({table.States[0].Cells.Length}х{table.States.Length}):", Type: 8);
+ for (int i = 0; i < table.States[0].Cells.Length; i++)
+ RG.Columns[1].Rows[i + 2].Value2 = "x" + SubScripts[i + 1];
+ for (int i = 0; i < table.States.Length; i++)
+ {
+ RG.Columns[i + 2].Rows[1].Value2 = (displayLetter ? stateLetter : "") + (displayLetter ? SubScripts[i + 1].ToString() : (i + 1).ToString());
+ for (int j = 0; j < table.States[i].Cells.Length; j++)
+ switch (displayMode)
+ {
+ case DisplayMode.OnlyStates:
+ RG.Columns[i + 2].Rows[j + 2].Value2 = table.States[i].Cells[j].State != -1 ? stateLetter + (table.States[i].Cells[j].State + 1) : "--";
+ break;
+ case DisplayMode.OnlyOutput:
+ RG.Columns[i + 2].Rows[j + 2].Value2 = table.States[i].Cells[j].Output != -1 ? "y" + table.States[i].Cells[j].Output : "--";
+ break;
+ case DisplayMode.Everything:
+ RG.Columns[i + 2].Rows[j + 2].Value2 = (table.States[i].Cells[j].State != -1 ? stateLetter + (table.States[i].Cells[j].State + 1) : "--") + "/"
+ + (table.States[i].Cells[j].Output != -1 ? "y" + table.States[i].Cells[j].Output : "--");
+ break;
+ }
+ }
+ }
+
+ public static void DisplayTables(List tables, DisplayMode displayMode = DisplayMode.Everything)
+ {
+ for (int i = 0; i < tables.Count; i++)
+ {
+ DisplayTable(tables[i], displayMode, $"{(char)(98 + i)}", false);
+ }
+ }
+
+ public static void DisplayTable(AutomataTableSP table, DisplayMode displayMode = DisplayMode.Everything, string stateLetter = "с")
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox($"Куда вставить таблицу ({table.States[0].Cells.Length}х{table.States.Length}):", Type: 8);
+ for (int i = 0; i < table.States[0].Cells.Length / 2; i++)
+ for (int j = 0; j < Laba5_1.CurrentPartition.BBlocks.Count; j++)
+ RG.Columns[1].Rows[2 + j + i * Laba5_1.CurrentPartition.BBlocks.Count].Value2 = $"x{SubScripts[i+1]} x b{SubScripts[j+1]}";
+
+ for (int i = 0; i < table.States.Length; i++)
+ {
+ RG.Columns[i + 2].Rows[1].Value2 = stateLetter + SubScripts[(i + 1)];
+ for (int j = 0; j < table.States[i].Cells.Length; j++)
+ switch (displayMode)
+ {
+ case DisplayMode.OnlyStates:
+ RG.Columns[i + 2].Rows[j + 2].Value2 =
+ table.States[i].Cells[j].State != -1 ?
+ stateLetter + (table.States[i].Cells[j].State + 1) : "--";
+ break;
+ case DisplayMode.OnlyOutput:
+ RG.Columns[i + 2].Rows[j + 2].Value2 =
+ table.States[i].Cells[j].Output != -1 ?
+ "y" + table.States[i].Cells[j].Output : "--";
+ break;
+ case DisplayMode.Everything:
+ RG.Columns[i + 2].Rows[j + 2].Value2 =
+ (table.States[i].Cells[j].State != -1 ?
+ stateLetter + (table.States[i].Cells[j].State + 1) : "--") + "/"
+ + (table.States[i].Cells[j].Output != -1 ?
+ "y" + table.States[i].Cells[j].Output : "--");
+ break;
+ }
+ }
+ }
+
+ public static void DisplayTable(AutomataTableCombined table, DisplayMode displayMode = DisplayMode.Everything, bool displayFirst = true)
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox($"Куда вставить таблицу ({table.States[0].Cells.Length+1}х{table.States.Length+1}):", Type: 8);
+ for (int i = 0; i < table.States[0].Cells.Length; i++)
+ RG.Columns[1].Rows[i + 2].Value2 = $"x{SubScripts[i + 1]}{(displayFirst ? $"(x1{i + 1})" : "")}";
+
+ for (int i = 0; i < table.States.Length; i++)
+ {
+ RG.Columns[i + 2].Rows[1].Value2 = $"S{i + 1}(S1{table.States[i].Number[0] + 1}, S2{table.States[i].Number[1] + 1})";
+ for (int j = 0; j < table.States[i].Cells.Length; j++)
+ switch (displayMode)
+ {
+ case DisplayMode.OnlyStates:
+ RG.Columns[i + 2].Rows[j + 2].Value2 =
+ $"S{Laba5.ReverseState(table, table.States[i].Cells[j].State) + 1}(S1{table.States[i].Cells[j].State[0] + 1}, S2{table.States[i].Cells[j].State[1] + 1})";
+ break;
+ case DisplayMode.OnlyOutput:
+ RG.Columns[i + 2].Rows[j + 2].Value2 =
+ "y" + table.States[i].Cells[j].Output;
+ break;
+ case DisplayMode.Everything:
+ RG.Columns[i + 2].Rows[j + 2].Value2 =
+ $"S{Laba5.ReverseState(table, table.States[i].Cells[j].State) + 1}(S1{table.States[i].Cells[j].State[0] + 1}, S2{table.States[i].Cells[j].State[1] + 1})" +
+ "/y" + table.States[i].Cells[j].Output;
+ break;
+ }
+ }
+ }
+
+ public static void DisplayTable(OutputTranslation table, string upperRow = "y1")
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox($"Куда вставить таблицу переводов ({table.Translation.GetLength(0) + 1}х{table.Translation.GetLength(1) + 1}):", Type: 8);
+ for (int i = 0; i < table.Translation.GetLength(1); i++)
+ RG.Columns[1].Rows[i + 2].Value2 = $"y2{i + 1}";
+
+ for (int i = 0; i < table.Translation.GetLength(0); i++)
+ {
+ RG.Columns[i + 2].Rows[1].Value2 = $"{upperRow}{i + 1}";
+ for (int j = 0; j < table.Translation.GetLength(1); j++)
+ {
+ RG.Columns[i + 2].Rows[j + 2].Value2 =
+ upperRow[0].ToString() + table.Translation[i, j];
+ }
+ }
+ }
+
+ public static void DisplayTable(AutomataTableRelative table, int num, bool bin = false, bool delay = false)
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox($"Куда вставить таблицу переходов автомата {(char)(66 + num)} ({table.Rows.Count}х{table.StateCount}):", Type: 8);
+ for (int i = 0; i < table.StateCount; i++)
+ RG.Columns[2 + i].Rows[1].Value2 = bin ? $"{i}" : $"{(char)(98 + num)}{SubScripts[i + 1]}";
+
+ for (int i = 0; i < table.Rows.Count; i++)
+ {
+ RG.Columns[1].Rows[2 + i].Value2 = bin ? table.Rows[i].BinName : table.Rows[i].Name;
+ for (int j = 0; j < table.Rows[i].Cells.Count; j++)
+ {
+ RG.Columns[2 + j].Rows[2 + i].Value2 = table.Rows[i].Cells[j].State == -1 ? "--" : (table.Rows[i].Cells[j].State == -2 ? "*" :
+ (bin ? $"{Math.Abs(table.Rows[i].Cells[j].State - 1)}" : $"{(char)(98 + num)}{table.Rows[i].Cells[j].State + 1}"));
+ }
+ }
+ }
+
+ public static void DisplayTables(List tables)
+ {
+ for (int i = 0; i < tables.Count; i++)
+ {
+ DisplayTable(tables[i], i, false);
+ }
+ }
+
+ public static void DisplayTable(AutomataTableG table, bool bin = false)
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox($"Куда вставить таблицу функции g:", Type: 8);
+ for (int i = 0; i < table.States.Length; i++)
+ {
+ RG.Columns[2 + i].Rows[1].Value2 = $"{table.Titles[i]}";
+ RG.Columns[2 + i].Rows[2].Value2 = bin ? $"{table.BinTitles[i]}" : $"{i + 1}";
+ }
+
+ for (int i = 0; i < table.Inputs; i++)
+ {
+ RG.Columns[1].Rows[i + 3].NumberFormat = "";
+ RG.Columns[1].Rows[i + 3].Value2 = bin ? $"{Laba7.MakeBinary(i, table.Inputs)}" : $"x{SubScripts[i+1]}";
+ for (int j = 0; j < table.States.Length; j++)
+ RG.Columns[j + 2].Rows[i + 3].Value2 = table.States[j].Cells[i].Output != -1 ?
+ (bin ? $"{table.States[j].Cells[i].Output - 1}" : "y" + table.States[j].Cells[i].Output) : "--";
+ }
+ }
+
+ private static void DisplayTable(ImplicatorsTable table, Range RG, int order)
+ {
+ RG.Rows[1].Columns[order * 4 + 2].Value2 = "№";
+ if (order == 0)
+ RG.Rows[1].Columns[3].Value2 = "Члены СДНФ";
+ else RG.Rows[1].Columns[order * 4 + 3].Value2 = "Импликанты";
+ for (int i = 0; i < table.Implicants.Count; i++)
+ {
+ RG.Rows[i + 2].Columns[order * 4 + 1].Value2 = $"{i+1}";
+ RG.Rows[i + 2].Columns[order * 4 + 2].NumberFormat = "@";
+ RG.Rows[i + 2].Columns[order * 4 + 2].Value2 = string.Join("-", table.Levels[i].Distinct());
+ RG.Rows[i + 2].Columns[order * 4 + 3].Value2 = table.ToString(i);
+ }
+ }
+
+ public static void DisplayTable(List table)
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox($"Куда вставить таблицы испликаторов:", Type: 8);
+ for (int i = 0; i < table.Count; i++)
+ {
+
+ DisplayTable(table[i], RG, i);
+ }
+ }
+
+ public static void DisplayTable(IntersectionTable table)
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox($"Куда вставить таблицы испликаторов:", Type: 8);
+ RG.Rows[1].Columns[1].Value2 = "Простые импликанты";
+ RG.Rows[1].Columns[2].Value2 = "Члены СДНФ";
+ for (int i = 0; i < table.CDNFAmount; i++)
+ RG.Rows[2].Columns[2 + i].Value2 = i + 1;
+ for (int i = 0; i < table.Implicants.Count; i++)
+ {
+ RG.Rows[3 + i].Columns[1].Value2 = ToString(table.Implicants[i]);
+ for (int j = 0; j < table.CDNFAmount; j++)
+ RG.Rows[3 + i].Columns[2 + j].Value2 = table.Bools[i][j] ? "X" : "";
+ }
+ }
+
+ private static string ToString(List items)
+ {
+ string res = "";
+ for (int j = 0; j < items.Count; j++)
+ {
+ res += $"{items[j].Symbol}{(items[j].Inverse ? "\u0305" : "")}{Common.SubScripts[items[j].Number]}";
+ }
+ return res;
+ }
+
+ public static void DisplayList(List ints, string msg = "Куда вставить список:")
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox(msg, Type: 8);
+ for (int i = 0; i < ints.Count; i++)
+ {
+ RG.Columns[1].Rows[i+1].Value2 = ints[i];
+ }
+ }
+
+ public static void DisplayList(List> ints, string msg = "Куда вставить список:")
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox(msg, Type: 8);
+ for (int i = 0; i < ints.Count; i++)
+ {
+ RG.Columns[1].Rows[i + 1].Value2 = string.Join(", ", ints[i]);
+ }
+ }
+
+ public static void DisplayList(List>> ints, char ch, string msg = null)
+ {
+ if (msg == null) msg = $"Куда вставить {ch} разбиения:";
+
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox(msg, Type: 8);
+ for (int i = 0; i < ints.Count; i++)
+ {
+ RG.Columns[1].Rows[i + 1].Value2 = ch.ToString() + SubScripts[i + 1].ToString();
+ for (int j = 0; j < ints[i].Count; j++)
+ {
+ for (int k = 0; k < ints[i][j].Count; k++) ints[i][j][k]++;
+ RG.Columns[j + 2].Rows[i + 1].Value2 = string.Join("", ints[i][j]);
+ for (int k = 0; k < ints[i][j].Count; k++) ints[i][j][k]--;
+ }
+ }
+ }
+
+ public static void DisplayList(List list)
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox("Куда вставить функции возбуждения:", Type: 8);
+ for (int i = 0; i < list.Count; i++)
+ {
+ RG.Columns[1].Rows[i + 1].Value2 = list[i].ToString();
+ }
+ }
+
+ public static void DisplayList(List list)
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox("Куда вставить таблицы Квайна:", Type: 8);
+ for (int i = 0; i < list.Count; i++)
+ {
+ RG.Columns[1].Rows[i + 1].Value2 = list[i].ToString();
+ }
+ }
+
+ public static void DisplayList(List list)
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox("Куда вставить упрощенные функции возбуждения:", Type: 8);
+ for (int i = 0; i < list.Count; i++)
+ {
+ RG.Columns[1].Rows[i + 1].Value2 = list[i].ToString();
+ }
+ }
+ }
+}
diff --git a/Automata theory/Form1.Designer.cs b/Automata theory/Form1.Designer.cs
new file mode 100644
index 0000000..89d4f3e
--- /dev/null
+++ b/Automata theory/Form1.Designer.cs
@@ -0,0 +1,94 @@
+namespace Automata_theory
+{
+ partial class Laba6Pi
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.dataGridView1 = new System.Windows.Forms.DataGridView();
+ this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.button1 = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
+ this.SuspendLayout();
+ //
+ // dataGridView1
+ //
+ this.dataGridView1.AllowUserToAddRows = false;
+ this.dataGridView1.AllowUserToDeleteRows = false;
+ this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.Column1,
+ this.Column2});
+ this.dataGridView1.Location = new System.Drawing.Point(12, 12);
+ this.dataGridView1.Name = "dataGridView1";
+ this.dataGridView1.Size = new System.Drawing.Size(244, 150);
+ this.dataGridView1.TabIndex = 1;
+ this.dataGridView1.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellEndEdit);
+ //
+ // Column1
+ //
+ this.Column1.HeaderText = "1";
+ this.Column1.Name = "Column1";
+ //
+ // Column2
+ //
+ this.Column2.HeaderText = "2";
+ this.Column2.Name = "Column2";
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(12, 168);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(75, 23);
+ this.button1.TabIndex = 2;
+ this.button1.Text = "button1";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.button1_Click);
+ //
+ // Laba6Img
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(271, 199);
+ this.Controls.Add(this.button1);
+ this.Controls.Add(this.dataGridView1);
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
+ this.Name = "Laba6Img";
+ this.Text = "Лаба 6";
+ this.Load += new System.EventHandler(this.Laba6Img_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+ private System.Windows.Forms.DataGridView dataGridView1;
+ private System.Windows.Forms.DataGridViewTextBoxColumn Column1;
+ private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
+ private System.Windows.Forms.Button button1;
+ }
+}
\ No newline at end of file
diff --git a/Automata theory/Form1.cs b/Automata theory/Form1.cs
new file mode 100644
index 0000000..48c97c1
--- /dev/null
+++ b/Automata theory/Form1.cs
@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace Automata_theory
+{
+ public partial class Laba6Pi : Form
+ {
+ public Laba6Pi()
+ {
+ InitializeComponent();
+ }
+
+ private void Laba6Img_Load(object sender, EventArgs e)
+ {
+ for (int i = 0; i < 3; i++)
+ {
+ dataGridView1.Rows.Add();
+ }
+ }
+
+ private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
+ {
+
+ }
+
+ private bool CheckCells()
+ {
+ List>> result = new List>>();
+ try
+ {
+ for (int i = 0; i < 3; i++)
+ {
+ List> list = new List>();
+ for (int j = 0; j < 2; j++)
+ {
+ string value = dataGridView1.Rows[i].Cells[j].Value.ToString();
+ List ints = new List();
+ for (int k = 0; k < value.Length; k++)
+ {
+ ints.Add(int.Parse($"{value[k]}") - 1);
+ }
+ list.Add(ints);
+ }
+ result.Add(list);
+ }
+ }
+ catch { return false; }
+ Ribbon1.ExternalPi = result;
+ Ribbon1.IsPiEnteredExternally = true;
+ return true;
+ }
+
+ private void button1_Click(object sender, EventArgs e)
+ {
+ if (CheckCells())
+ this.Close();
+ }
+ }
+}
diff --git a/Automata theory/Form1.resx b/Automata theory/Form1.resx
new file mode 100644
index 0000000..c9977e7
--- /dev/null
+++ b/Automata theory/Form1.resx
@@ -0,0 +1,132 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
\ No newline at end of file
diff --git a/Automata theory/Laba4.cs b/Automata theory/Laba4.cs
new file mode 100644
index 0000000..486ba06
--- /dev/null
+++ b/Automata theory/Laba4.cs
@@ -0,0 +1,338 @@
+using Microsoft.Office.Interop.Excel;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+
+// this is all good, no need to touch anything here
+namespace Automata_theory
+{
+ public partial class Laba4
+ {
+ public static AutomataTableBase CurrentTable { get; set; }
+ public static AngerPoll CurrentAngerPoll { get; set; }
+ public static AutomataTableBase NewTable { get; set; }
+
+ public static AngerPoll CalculateAngerPoll(AutomataTableBase table)
+ {
+ AngerPoll angerPoll = new AngerPoll(table);
+ return angerPoll;
+ }
+
+ public static void DisplayAngerPoll(AutomataTableBase table, AngerPoll angerPoll)
+ {
+ Range RG = (Range)Globals.ThisAddIn.Application.InputBox($"Куда вставить треугольную таблицу:", Type: 8);
+ for (int i = 2; i < table.States.Length + 1; i++)
+ {
+ RG.Columns[1].Rows[i - 1].Value2 = "s" + Common.SubScripts[i];
+ //RG.Columns[1].Rows[i - 1].Value2 = "s" + i;
+ for (int j = i; j < table.States.Length + 1; j++)
+ {
+
+ RG.Columns[i].Rows[j - 1].Value2 =
+ angerPoll.States1[i - 2, j - 1] == -1 ? ("X " + angerPoll.States2[i - 2, j - 1]).TrimEnd() :
+ angerPoll.States[i - 2, j - 1] == 1 ? "V" : (angerPoll.States[i - 2, j - 1] == -1 ? "X\n" + angerPoll.States2[i - 2, j - 1] : angerPoll.States[i - 2, j - 1].ToString());
+
+ if (angerPoll.States[i - 2, j - 1] == 1) RG.Columns[i].Rows[j - 1].Interior.Color = Color.FromArgb(198, 239, 206);
+ else if (angerPoll.States[i - 2, j - 1] == -1) RG.Columns[i].Rows[j - 1].Interior.Color = Color.FromArgb(255, 199, 206);
+ else RG.Columns[i].Rows[j - 1].Interior.Color = Color.FromArgb(255, 235, 156);
+ }
+ }
+ for (int i = 1; i < table.States.Length; i++)
+ RG.Columns[i + 1].Rows[table.States.Length] = "s" + Common.SubScripts[i];
+ }
+
+ public static AutomataTableBase CalculateNew(AngerPoll angerPoll, AutomataTableBase table)
+ {
+ AutomataTableBase newTable = new AutomataTableBase(angerPoll.Sets.Count, table.States[0].Cells.Length);
+ for (int i = 0; i < newTable.States.Length; i++)
+ {
+ AutomataStateBase automataState = new AutomataStateBase(table.States[0].Cells.Length, i);
+ for (int j = 0; j < newTable.States[i].Cells.Length; j++)
+ {
+ int forState = 0, forOutput = 0;
+ AutomataCellBase automataCell =
+ new AutomataCellBase(ReverseState(angerPoll.Sets,
+ table.States[angerPoll.Sets[i][forState]].Cells[j].State),
+ table.States[angerPoll.Sets[i][forOutput]].Cells[j].Output);
+
+ for (; forState < angerPoll.Sets[i].Count && automataCell.State == -1 && angerPoll.Sets[i].Count > 1; forState++)
+ {
+ automataCell =
+ new AutomataCellBase(ReverseState(angerPoll.Sets,
+ table.States[angerPoll.Sets[i][forState]].Cells[j].State),
+ table.States[angerPoll.Sets[i][forOutput]].Cells[j].Output);
+ }
+ for (; forOutput < angerPoll.Sets[i].Count && automataCell.Output == -1 && angerPoll.Sets[i].Count > 1; forOutput++)
+ {
+ automataCell =
+ new AutomataCellBase(ReverseState(angerPoll.Sets,
+ table.States[angerPoll.Sets[i][forState]].Cells[j].State),
+ table.States[angerPoll.Sets[i][forOutput]].Cells[j].Output);
+ }
+ automataState.Cells[j] = automataCell;
+ }
+ newTable.States[i] = automataState;
+ }
+ newTable.Outputs = table.Outputs;
+ return newTable;
+ }
+
+ public static int ReverseState(List> states, int inputState)
+ {
+ if (inputState == -1) return -1;
+ for (int i = 0; i < states.Count; i++)
+ for (int j = 0; j < states[i].Count; j++)
+ if (states[i][j] == inputState)
+ return i;
+ throw new Exception();
+ }
+ }
+
+ public class AngerPoll
+ {
+ public AngerPoll(AutomataTableBase table)
+ {
+ InitTable(table.States.Length);
+ CheckConflict(table);
+ CheckSimilarity(table);
+ CheckConditional(table);
+ CalculateSets();
+ }
+
+ private void InitTable(int size)
+ {
+ _states = new int[size, size];
+ for (int i = 0; i < size; i++)
+ for (int j = 0; j < size; j++)
+ _states[i, j] = -2;
+ }
+
+ private void CheckConflict(AutomataTableBase table)
+ {
+ for (int i = 0; i < _states.GetLength(0); i++)
+ {
+ for (int j = 0; j < _states.GetLength(1); j++)
+ {
+ bool flag = true;
+ for (int k = 0; k < table.States[0].Cells.Length; k++)
+ {
+ if (!flag) break;
+ if (!(table.States[i].Cells[k].Output ==
+ table.States[j].Cells[k].Output ||
+
+ table.States[i].Cells[k].Output == -1 ||
+ table.States[j].Cells[k].Output == -1))
+ flag = false;
+ }
+ if (!flag) _states[i, j] = -1;
+ }
+ }
+ _1 = _states;
+ }
+
+ private void CheckSimilarity(AutomataTableBase table)
+ {
+ for (int i = 0; i < _states.GetLength(0); i++)
+ {
+ for (int j = 0; j < _states.GetLength(1); j++)
+ {
+ if (_states[i, j] == -1) continue;
+
+ bool flag = true;
+ for (int k = 0; k < table.States[0].Cells.Length; k++)
+ {
+ if (!flag) break;
+ if (!(table.States[i].Cells[k].State ==
+ table.States[j].Cells[k].State ||
+
+ table.States[i].Cells[k].State == -1 ||
+ table.States[j].Cells[k].State == -1))
+ flag = false;
+ }
+ _states[i, j] = flag ? 1 : 0;
+ }
+ }
+ }
+
+ private void CheckConditional(AutomataTableBase table)
+ {
+ _2 = new string[_states.GetLength(0), _states.GetLength(1)];
+ bool isDone = false;
+ int counter = 0;
+ while (!isDone && counter < 100)
+ {
+ isDone = true;
+ for (int i = 0; i < _states.GetLength(0); i++)
+ {
+ for (int j = 0; j < _states.GetLength(1); j++)
+ {
+
+ if (_states[i, j] != 0) continue;
+
+ bool flag = true; int answer = 0;
+ for (int k = 0; k < table.States[0].Cells.Length; k++)
+ {
+ if (counter == 0 && table.States[i].Cells[k].State + 1 != table.States[j].Cells[k].State + 1)
+ {
+ _2[i, j] += $"{table.States[i].Cells[k].State + 1}, {table.States[j].Cells[k].State + 1}\n";
+ }
+
+ if (!flag) break;
+ if (table.States[i].Cells[k].State != -1 &&
+ table.States[j].Cells[k].State != -1 &&
+ _states[table.States[i].Cells[k].State,
+ table.States[j].Cells[k].State] == -1)
+ flag = false;
+ if (table.States[i].Cells[k].State != -1 &&
+ table.States[j].Cells[k].State != -1 &&
+ _states[table.States[i].Cells[k].State,
+ table.States[j].Cells[k].State] == 0)
+ {
+ isDone = false;
+ counter++;
+ answer = Convert.ToInt32($"{table.States[i].Cells[k].State + 1}" +
+ $"{table.States[j].Cells[k].State + 1}");
+ }
+ }
+
+ _states[i, j] = flag ? (counter < 99 ? 0 : (answer == 0 ? 1 : answer)) : -1;
+ }
+ }
+ }
+ }
+
+ private void CalculateSets()
+ {
+ List skipCell = new List();
+ for (int i = 0; i < _states.GetLength(0); i++)
+ {
+ for (int j = _states.GetLength(1) - 1; j > i; j--)
+ {
+ if (Contains(skipCell, new int[] { i, j })) continue;
+ if (_states[i, j] == 1)
+ {
+ int vertical = -1, horizontal = -1;
+ bool hasVertical = false, hasHorizontal = false;
+ for (int k = j - 1; k > i; k--)
+ if (_states[i, k] == 1)
+ {
+ hasVertical = true;
+ vertical = i;
+ break;
+ //skipCell.Add(new int[] { i, k });
+ }
+ for (int k = i + 1; k < j; k++)
+ if (_states[k, j] == 1)
+ {
+ hasHorizontal = true;
+ horizontal = k;
+ break;
+ //skipCell.Add(new int[] { k, j });
+ }
+ if (hasVertical && hasHorizontal)
+ {
+ skipCell.Add(new int[] { horizontal, j });
+ skipCell.Add(new int[] { i, horizontal });
+ _sets.Add(new List { vertical, horizontal, j });
+ _setsDisp.Add(new List { vertical + 1, horizontal + 1, j + 1 });
+ }
+ else
+ {
+ _sets.Add(new List { i, j });
+ _setsDisp.Add(new List { i + 1, j + 1 });
+ }
+ }
+ }
+ }
+ for (int i = 0; i < _states.GetLength(0); i++)
+ {
+ bool skip = false;
+ for (int j = 0; j < _sets.Count; j++)
+ {
+ for (int k = 0; k < _sets[j].Count; k++)
+ if (_sets[j][k] == i)
+ {
+ skip = true;
+ break;
+ }
+ if (skip) break;
+ }
+
+ if (skip) continue;
+ else
+ {
+ _sets.Add(new List { i });
+ _setsDisp.Add(new List { i + 1 });
+ }
+ }
+ }
+
+ private bool Contains(List cells, int[] cell)
+ {
+ for (int i = 0; i < cells.Count; i++)
+ if (cells[i][0] == cell[0] && cells[i][1] == cell[1])
+ return true;
+ return false;
+ }
+
+ private int[,] _states;
+ private int[,] _1;
+ private string[,] _2;
+ private List> _sets = new List>();
+ private List> _setsDisp = new List>();
+
+ public int[,] States { get { return _states; } }
+ public int[,] States1 { get { return _1; } }
+ public string[,] States2 { get { return _2; } }
+ public List> Sets { get { return _sets; } }
+ public List> SetsDisp { get { return _setsDisp; } }
+ }
+
+ public class AutomataTableBase
+ {
+ public AutomataTableBase(int statesAmount, int inputAmount)
+ {
+ _states = new AutomataStateBase[statesAmount];
+ for (int i = 0; i < statesAmount; i++)
+ _states[i] = new AutomataStateBase(inputAmount, i);
+ Inputs = inputAmount;
+ }
+ private AutomataStateBase[] _states;
+
+ public int Outputs;
+ public int Inputs;
+ public AutomataStateBase[] States { get { return _states; } }
+ }
+
+ public class AutomataStateBase
+ {
+ public AutomataStateBase(int inputs, int number)
+ {
+ _cells = new AutomataCellBase[inputs];
+ Number = number;
+ }
+
+ public int Number { get; private set; }
+ private AutomataCellBase[] _cells;
+ public AutomataCellBase[] Cells { get { return _cells; } }
+ }
+
+ public class AutomataCellBase
+ {
+ public AutomataCellBase(int state, int output)
+ {
+ _state = state;
+ _output = output;
+ }
+
+ private int _state = -1;
+ private int _output = -1;
+
+ public int State { get { return _state; } }
+ public int Output { get { return _output; } }
+ }
+}
diff --git a/Automata theory/Laba5.1.cs b/Automata theory/Laba5.1.cs
new file mode 100644
index 0000000..3eeda70
--- /dev/null
+++ b/Automata theory/Laba5.1.cs
@@ -0,0 +1,289 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace Automata_theory
+{
+ partial class Laba5_1
+ {
+ public static AutomataTableBase CurrentTable { get; set; }
+
+ public static SPPartition CurrentPartition { get; set; }
+
+ public static AutomataTableBase CurrentSP1 { get; set; }
+
+ public static AutomataTableSP CurrentSP2 { get; set; }
+ }
+
+ public class SPPartition
+ {
+ public SPPartition(AutomataTableBase table)
+ {
+ if (CalculateBBlocks(table))
+ {
+ CalculateCBlocks();
+ ReadyBlocks();
+ CalculateProduct();
+ CalculateTable();
+ isGood = true;
+ }
+ else
+ {
+ MessageBox.Show("Нет СП разбиений", "Лаба 5.1", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ isGood = false;
+ }
+ }
+
+ private bool CalculateBBlocks(AutomataTableBase table)
+ {
+ for (int i = 0; i < table.States.Length; i++)
+ for (int j = i + 1; j < table.States.Length; j++)
+ {
+ List> blocks = CalculateSuggestion(table, 0, 2);
+ if (blocks.Count > 1)
+ {
+ _bBlocks = blocks;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private List> CalculateSuggestion(AutomataTableBase table, int first, int second)
+ {
+ List> result = new List> { new List { first, second } };
+ List> toSkip = new List> { new List { first, second } };
+ result = CalculateState(result, table);
+ while (!CheckStop(result, table))
+ {
+ for (int i = 0; i < result.Count; i++)
+ {
+ List block = new List(result[i]);
+ if (Contains(toSkip, result[i])) continue;
+ result = CalculateState(result, table, i);
+ toSkip.Add(block);
+ i = 0;
+ if (CheckStop(result, table)) break;
+ }
+ }
+
+ return result;
+ }
+
+ private bool Contains(List> list, List item)
+ {
+ for (int i = 0; i < list.Count; i++)
+ {
+ if (list[i].Count == item.Count)
+ {
+ bool flag = true;
+ for (int j = 0; j < item.Count; j++)
+ if (list[i][j] != item[j])
+ {
+ flag = false;
+ break;
+ }
+ if (flag) return true;
+ }
+ }
+ return false;
+ }
+
+ private List> CalculateState(List> blocks, AutomataTableBase table, int index = 0)
+ {
+ List> result = new List>(blocks);
+ for (int i = 0; i < table.Inputs; i++)
+ {
+ List block = new List { };
+ for (int j = 0; j < blocks[index].Count; j++)
+ if (!block.Contains(table.States[blocks[index][j]].Cells[i].State))
+ block.Add(table.States[blocks[index][j]].Cells[i].State);
+ block.Sort();
+ result.Insert(index + 1, block);
+ }
+
+ result = CleanBlocks(result);
+
+ return result;
+ }
+
+ private List> CleanBlocks(List> blocks)
+ {
+ blocks.Sort((a, b) => a[0].CompareTo(b[0]));
+ for (int i = 0; i < blocks.Count; i++)
+ for (int j = i + 1; j < blocks.Count; j++)
+ for (int k = 0; k < blocks[j].Count; k++)
+ if (blocks[i].Contains(blocks[j][k]))
+ {
+ for (int t = 0; t < blocks[j].Count; t++)
+ if (!blocks[i].Contains(blocks[j][t]))
+ blocks[i].Add(blocks[j][t]);
+ blocks.RemoveAt(j); i = 0; j = 0; break;
+ }
+
+ for (int i = 0; i < blocks.Count; i++)
+ blocks[i].Sort();
+ blocks.Sort((a, b) => a[0].CompareTo(b[0]));
+
+ return blocks;
+ }
+
+ private bool CheckStop(List> blocks, AutomataTableBase table)
+ {
+ List checks = new List();
+ for (int i = 0; i < table.States.Length; i++)
+ checks.Add(i);
+ for (int i = 0; i < blocks.Count; i++)
+ for (int j = 0; j < blocks[i].Count; j++)
+ checks.Remove(blocks[i][j]);
+
+ for (int i = 1; i < blocks.Count; i++)
+ if (blocks[i].Count != blocks[0].Count) return false;
+
+ return checks.Count == 0;
+ }
+
+ private void ReadyBlocks()
+ {
+ for (int i = 0; i < _bBlocks.Count; i++)
+ _bBlocks[i].Sort();
+ _bBlocks.Sort((a, b) => a[0].CompareTo(b[0]));
+
+ _bBlocksDisplay = new List>();
+ for (int i = 0; i < _bBlocks.Count; i++)
+ {
+ List block = new List();
+ for (int j = 0; j < _bBlocks[i].Count; j++)
+ block.Add(i);
+ _bBlocksDisplay.Add(block);
+ }
+
+ for (int i = 0; i < _bBlocks.Count; i++)
+ for (int j = 0; j < _bBlocks[i].Count; j++)
+ _bBlocksDisplay[i][j] = _bBlocks[i][j] + 1;
+
+ for (int i = 0; i < _cBlocks.Count; i++)
+ _cBlocks[i].Sort();
+ _cBlocks.Sort((a, b) => a[0].CompareTo(b[0]));
+
+ _cBlocksDisplay = new List>();
+ for (int i = 0; i < _cBlocks.Count; i++)
+ {
+ List block = new List();
+ for (int j = 0; j < _cBlocks[i].Count; j++)
+ block.Add(i);
+ _cBlocksDisplay.Add(block);
+ }
+ for (int i = 0; i < _cBlocks.Count; i++)
+ for (int j = 0; j < _cBlocks[j].Count; j++)
+ _cBlocksDisplay[i][j] = _cBlocks[i][j] + 1;
+ }
+
+ private void CalculateCBlocks()
+ {
+ for (int i = 0; i < _bBlocks[0].Count; i++)
+ {
+ List block = new List();
+ for (int j = 0; j < _bBlocks.Count; j++)
+ {
+ block.Add(_bBlocks[j][i]);
+ }
+ _cBlocks.Add(block);
+ }
+ }
+
+ private void CalculateProduct()
+ {
+ _states = new int[_bBlocks.Count, _cBlocks.Count];
+
+ for (int i = 0; i < _bBlocks.Count; i++)
+ for (int j = 0; j < _cBlocks.Count; j++)
+ _states[i, j] = GetMutual(_bBlocks[i], _cBlocks[j]);
+ }
+
+ private int GetMutual(List first, List second)
+ {
+ for (int i = 0; i < first.Count; i++)
+ for (int j = 0; j < second.Count; j++)
+ if (first[i] == second[j]) return first[i];
+ throw new Exception();
+ }
+
+ private void CalculateTable()
+ {
+ Laba5_1.CurrentSP1 = new AutomataTableBase(_bBlocks.Count, Laba5_1.CurrentTable.Inputs);
+ for (int i = 0; i < _bBlocks.Count; i++)
+ {
+ for (int j = 0; j < Laba5_1.CurrentSP1.Inputs; j++)
+ {
+ Laba5_1.CurrentSP1.States[i].Cells[j] =
+ new AutomataCellBase(ReverseState(_bBlocks, Laba5_1.CurrentTable.States[_bBlocks[i][0]].Cells[j].State), 0);
+ }
+ }
+
+ Laba5_1.CurrentSP2 = new AutomataTableSP(_cBlocks.Count, Laba5_1.CurrentTable.Inputs * 2);
+ for (int i = 0; i < _cBlocks.Count; i++) // for each c state
+ {
+ for (int j = 0; j < Laba5_1.CurrentTable.Inputs; j++) // for each input
+ {
+ for (int k = 0; k < _bBlocks.Count; k++) // for each b state
+ {
+ if (i == 0) Laba5_1.CurrentSP2.Header.Add(new int[] { j+1, k+1 }); // add title if first pass of c state
+
+ // access (x and b)th input of sp2 and set state and output
+ Laba5_1.CurrentSP2.States[i].Cells[j * 2 + k] =
+ new AutomataCellBase(
+ ReverseState(_cBlocks, Laba5_1.CurrentTable.States[_states[k, i]].Cells[j].State),
+ Laba5_1.CurrentTable.States[_states[k, i]].Cells[j].Output );
+ }
+ }
+ }
+ }
+
+ private int ReverseState(List> states, int state)
+ {
+ for (int i = 0; i < states.Count; i++)
+ {
+ for (int j = 0; j < states[i].Count; j++)
+ {
+ if (states[i][j] == state) return i;
+ }
+ }
+ return -1;
+ }
+
+ private List> _bBlocks = new List>();
+ private List> _bBlocksDisplay;
+ private List> _cBlocks = new List>();
+ private List> _cBlocksDisplay;
+ private int[,] _states;
+ private bool isGood;
+
+ public List> BBlocks { get { return _bBlocks; } }
+ public List> BBlocksDisplay { get { return _bBlocksDisplay; } }
+ public List> CBlocks { get { return _cBlocks; } }
+ public List> CBlocksDisplay { get { return _cBlocksDisplay; } }
+ public int[,] States { get { return _states; } }
+ public bool IsGood { get { return isGood; } }
+ }
+
+ public class AutomataTableSP
+ {
+ public AutomataTableSP(int statesAmount, int inputAmount)
+ {
+ _states = new AutomataStateBase[statesAmount];
+ for (int i = 0; i < statesAmount; i++)
+ _states[i] = new AutomataStateBase(inputAmount, i);
+ Inputs = inputAmount;
+ }
+ private AutomataStateBase[] _states;
+ private List _header = new List();
+
+ public int Inputs;
+ public List Header { get { return _header; } }
+ public AutomataStateBase[] States { get { return _states; } }
+ }
+}
diff --git a/Automata theory/Laba5.cs b/Automata theory/Laba5.cs
new file mode 100644
index 0000000..af3a488
--- /dev/null
+++ b/Automata theory/Laba5.cs
@@ -0,0 +1,183 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using static System.Windows.Forms.AxHost;
+
+namespace Automata_theory
+{
+ public partial class Laba5
+ {
+ public static AutomataTableBase AutomataA { get; set; }
+ public static AutomataTableBase AutomataB { get; set; }
+ public static AutomataTableCombined SeriesTable { get; set; }
+ public static AutomataTableCombined ParallelTable { get; set; }
+ public static OutputTranslation TranslationParallel { get; set; }
+ public static AutomataTableCombined FeedbackTable { get; set; }
+ public static OutputTranslation TranslationFeedback { get; set; }
+
+ public static AutomataTableCombined CombineSeries(AutomataTableBase A, AutomataTableBase B)
+ {
+ AutomataTableCombined combined = new AutomataTableCombined(A.States.Length * B.States.Length, A.Inputs);
+
+ for (int i = 0; i < A.States.Length; i++) // for each A state
+ {
+ for (int j = 0; j < B.States.Length; j++) // for each B state
+ {
+ combined.Titles.Add(new int[] { i, j });
+ AutomataStateCombined state = new AutomataStateCombined(A.Inputs, new int[] { i, j });
+ for (int k = 0; k < A.Inputs; k++) // for each input
+ {
+ state.Cells[k] =
+ new AutomataCellCombined(new int[] { A.States[i].Cells[k].State, B.States[j].Cells[A.States[i].Cells[k].Output - 1].State },
+ B.States[j].Cells[A.States[i].Cells[k].Output - 1].Output);
+ }
+ combined.States[i * B.States.Length + j] = state;
+ }
+ }
+
+ return combined;
+ }
+
+ public static int ReverseState(AutomataTableCombined table, int[] state)
+ {
+ for (int i = 0; i < table.Titles.Count; i++)
+ if (table.Titles[i][0] == state[0] && table.Titles[i][1] == state[1])
+ return i;
+ return -1;
+ }
+
+ public static AutomataTableCombined CombineParallel(AutomataTableBase A, AutomataTableBase B)
+ {
+ AutomataTableCombined combined = new AutomataTableCombined(A.States.Length * B.States.Length, A.Inputs);
+ TranslationParallel = new OutputTranslation(new int[] { A.Outputs, B.Outputs });
+
+ for (int i = 0; i < A.States.Length; i++) // for each A state
+ {
+ for (int j = 0; j < B.States.Length; j++) // for each B state
+ {
+ combined.Titles.Add(new int[] { i, j });
+ AutomataStateCombined state = new AutomataStateCombined(A.Inputs, new int[] { i, j });
+
+ for (int k = 0; k < A.Inputs; k++) // for each input
+ {
+ state.Cells[k] =
+ new AutomataCellCombined(new int[] { A.States[i].Cells[k].State, B.States[j].Cells[k].State },
+ TranslationParallel.Translation[A.States[i].Cells[k].Output - 1, B.States[j].Cells[k].Output - 1]);
+ }
+ combined.States[i * B.States.Length + j] = state;
+ }
+ }
+ return combined;
+ }
+
+ public static AutomataTableCombined CombineFeedback(AutomataTableBase A, AutomataTableBase B, int inputs, int iterations)
+ {
+ AutomataTableCombined combined = new AutomataTableCombined(A.States.Length * B.States.Length, inputs);
+ TranslationFeedback = new OutputTranslation(new int[] { inputs, B.Outputs }, A.Inputs);
+
+ for (int i = 0; i < A.States.Length; i++) // for each A state
+ {
+ for (int j = 0; j < B.States.Length; j++) // for each B state
+ {
+ combined.Titles.Add(new int[] { i, j });
+ AutomataStateCombined state = new AutomataStateCombined(inputs, new int[] { i, j });
+ for (int k = 0; k < inputs; k++) // for each input
+ {
+ state.Cells[k] = CalculateFeedback(A, B, i, j, k, iterations);
+ }
+ combined.States[i * B.States.Length + j] = state;
+ }
+ }
+
+ return combined;
+ }
+
+ private static AutomataCellCombined CalculateFeedback(AutomataTableBase A, AutomataTableBase B, int stateA, int stateB, int input, int iterations)
+ {
+ int finalInput = TranslationFeedback.Translation[input, 0] - 1;
+ int output = A.States[stateA].Cells[finalInput].Output;
+ int newStateA = A.States[stateA].Cells[finalInput].State;
+ int newStateB = B.States[stateB].Cells[ A.States[stateA].Cells[finalInput].Output-1 ].State;
+
+ int finalOutput = output - 1, finalStateA = newStateA, finalStateB = newStateB;
+ for (int i = 0; i < iterations; i++)
+ {
+ finalInput = TranslationFeedback.Translation[input, B.States[finalStateB].Cells[ finalOutput ].Output - 1] - 1;
+ finalOutput = A.States[finalStateA].Cells[finalInput].Output - 1;
+ finalStateB = B.States[finalStateB].Cells[ finalOutput ].State;
+ finalStateA = A.States[finalStateA].Cells[finalInput].State;
+ }
+ //int newFinalInput = TranslationFeedback.Translation[input, B.States[stateB].Cells[ A.States[stateA].Cells[finalInput].Output - 1 ].Output - 1] - 1;
+ //int output = A.States[stateA].Cells[finalInput].Output;
+ //newStateB = B.States[newStateB].Cells[ A.States[newStateA].Cells[newFinalInput].Output - 1 ].State;
+ //newStateA = A.States[newStateA].Cells[newFinalInput].State;
+ return new AutomataCellCombined(new int[] { finalStateA, finalStateB }, finalOutput + 1);
+ }
+ }
+
+ public class OutputTranslation
+ {
+ public OutputTranslation(int[] inputs, int outputs = -1)
+ {
+ _translation = new int[inputs[0], inputs[1]];
+ for (int i = 0; i < inputs[0]; i++)
+ {
+ for (int j = 0; j < inputs[1]; j++)
+ {
+ _translation[i, j] = outputs == -1 ? i + j + 1 : outputs - ((i + j + 1) % outputs);
+ }
+ }
+ }
+
+ private int[,] _translation;
+ public int[,] Translation { get { return _translation; } }
+ }
+
+ public class AutomataTableCombined
+ {
+ public AutomataTableCombined(int statesAmount, int inputAmount)
+ {
+ _states = new AutomataStateCombined[statesAmount];
+ for (int i = 0; i < statesAmount; i++)
+ _states[i] = new AutomataStateCombined(inputAmount, new int[] {i});
+ Inputs = inputAmount;
+ }
+
+ private AutomataStateCombined[] _states;
+ private List _titles = new List();
+
+ public int Inputs;
+ public AutomataStateCombined[] States { get { return _states; } }
+ public List Titles { get { return _titles; } }
+ }
+
+ public class AutomataStateCombined
+ {
+ public AutomataStateCombined(int inputs, int[] number)
+ {
+ _cells = new AutomataCellCombined[inputs];
+ Number = number;
+ }
+
+ public int[] Number { get; private set; }
+ private AutomataCellCombined[] _cells;
+ public AutomataCellCombined[] Cells { get { return _cells; } }
+ }
+
+ public class AutomataCellCombined
+ {
+ public AutomataCellCombined(int[] state, int output)
+ {
+ _state = state;
+ _output = output;
+ }
+
+ private int[] _state = new int[2];
+ private int _output = -1;
+
+ public int[] State { get { return _state; } }
+ public int Output { get { return _output; } }
+ }
+}
diff --git a/Automata theory/Laba6.cs b/Automata theory/Laba6.cs
new file mode 100644
index 0000000..e51856b
--- /dev/null
+++ b/Automata theory/Laba6.cs
@@ -0,0 +1,467 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using static System.Windows.Forms.AxHost;
+
+namespace Automata_theory
+{
+ partial class Laba6
+ {
+ public static Partitions Partitions { get; set; }
+
+ public static int GetPartitionsCount(int statesAmount)
+ {
+ if (statesAmount <= 4)
+ return 2;
+ if (statesAmount <= 8)
+ return 3;
+ else if (statesAmount <= 16)
+ return 4;
+ throw new ArgumentOutOfRangeException();
+ }
+ }
+
+ public class Partitions
+ {
+ public Partitions(AutomataTableBase table, int partitions, bool doPi, List>> P = null)
+ {
+ this.partitions = partitions;
+ do
+ {
+ MakePiPartitions(table, doPi, P);
+ }
+ while (GetIntersectionOfAllSets(pi).Count < table.States.Length);
+ MakeTables(table);
+ MakeTauPartitions(table);
+ MakeEtaPartitions(table);
+ CalculateDependancies();
+ CalculateTranslations(table);
+ CalculateFunctionG(table);
+ }
+
+ private void MakePiPartitions(AutomataTableBase table, bool doPi, List>> P)
+ {
+ if (doPi)
+ {
+ this.pi = P;
+ return;
+ }
+ this.pi = GenerateLists(partitions, table.States.Length);
+ }
+
+ static List>> GenerateLists(int a, int b)
+ {
+ List>> result = new List>>();
+ Random rand = new Random();
+
+ for (int i = 0; i < a; i++)
+ {
+ List> list1 = new List>();
+ List numbers = new List();
+
+ for (int j = 0; j < b; j++)
+ {
+ numbers.Add(j);
+ }
+
+ Shuffle(numbers, rand);
+
+ int midPoint = numbers.Count / 2;
+ List subset1 = numbers.GetRange(0, midPoint);
+ List subset2 = numbers.GetRange(midPoint, b - midPoint);
+
+ list1.Add(subset1);
+ list1.Add(subset2);
+
+ result.Add(list1);
+ }
+
+ return result;
+ }
+
+ static void Shuffle(List list, Random rand)
+ {
+ int n = list.Count;
+ while (n > 1)
+ {
+ n--;
+ int k = rand.Next(n + 1);
+ int value = list[k];
+ list[k] = list[n];
+ list[n] = value;
+ }
+ }
+
+ private List> GetIntersectionOfAllSets(List>> listOfSets)
+ {
+ if (listOfSets == null || listOfSets.Count == 0)
+ {
+ // Handle invalid input, return an empty list or throw an exception as needed
+ return new List>();
+ }
+
+ // Initialize the result with the first set
+ List> result = listOfSets[0];
+
+ // Iterate through the rest of the sets and find the intersection
+ for (int i = 1; i < listOfSets.Count; i++)
+ {
+ result = IntersectSets(result, listOfSets[i]);
+ }
+
+ return result;
+ }
+
+ private List> IntersectSets(List> set1, List> set2)
+ {
+ var intersection = new List>();
+
+ foreach (var subset1 in set1)
+ {
+ foreach (var subset2 in set2)
+ {
+ var commonElements = subset1.Intersect(subset2).ToList();
+ if (commonElements.Count > 0)
+ {
+ intersection.Add(commonElements);
+ }
+ }
+ }
+
+ return intersection;
+ }
+
+ private void MakeTables(AutomataTableBase table)
+ {
+ for (int i = 0; i < partitions; i++) // for each partition
+ {
+ AutomataTableBase newTable = new AutomataTableBase(table.States.Length, table.Inputs);
+ for (int j = 0; j < table.States.Length; j++) // for each state
+ {
+ newTable.States[j] = new AutomataStateBase(table.Inputs, j);
+ for (int k = 0; k < table.Inputs; k++) // for each input
+ {
+ newTable.States[j].Cells[k] = new AutomataCellBase(ReverseState(pi[i], table.States[j].Cells[k].State), -1);
+ }
+ }
+ tables.Add(newTable);
+ }
+ }
+
+ private int ReverseState(List> sets, int state, bool invert = false)
+ {
+ for (int i = 0; i < sets.Count; i++)
+ {
+ for (int j = 0; j < sets[i].Count; j++)
+ {
+ if (sets[i][j] == state) return invert ? Math.Abs(i - 1) : i;
+ }
+ }
+ return -1;
+ }
+
+ private void MakeTauPartitions(AutomataTableBase table)
+ {
+ for (int i = 0; i < partitions; i++) // for each partition
+ {
+ tau.Add(new List>());
+ List skip = new List();
+ for (int j = 0; j < tables[i].States.Length; j++) // for each state
+ {
+ if (skip.Contains(j)) continue;
+ List set = new List() { j };
+ List input = new List();
+
+ for (int k = 0; k < tables[i].Inputs; k++) // for each input
+ {
+ input.Add(tables[i].States[j].Cells[k].State);
+ }
+
+ for (int k = j + 1; k < tables[i].States.Length; k++) // for each state after current
+ {
+ bool flag = true;
+ for (int u = 0; u < tables[i].Inputs; u++) // for each input
+ {
+ if (tables[i].States[k].Cells[u].State != tables[i].States[j].Cells[u].State)
+ { flag = false; break; }
+ }
+ if (flag) { set.Add(k); skip.Add(k); }
+ }
+ tau[i].Add(set);
+ }
+ }
+ }
+
+ private void MakeEtaPartitions(AutomataTableBase table)
+ {
+ for (int i = 0; i < partitions; i++) // for each partition
+ {
+ eta.Add(new List>());
+ List skip = new List();
+ for (int j = 0; j < tables[i].Inputs; j++) // for each state -> input
+ {
+ if (skip.Contains(j)) continue;
+ List set = new List() { j };
+ List input = new List();
+
+ for (int k = 0; k < tables[i].States.Length; k++) // for each input -> state
+ {
+ input.Add(tables[i].States[k].Cells[j].State);
+ }
+
+ for (int k = j + 1; k < tables[i].Inputs; k++) // for each state after current -> input after
+ {
+ bool flag = true;
+ for (int u = 0; u < tables[i].Inputs; u++) // for each input -> state
+ {
+ if (tables[i].States[u].Cells[k].State != tables[i].States[u].Cells[j].State)
+ { flag = false; break; }
+ }
+ if (flag) { set.Add(k); skip.Add(k); }
+ }
+ eta[i].Add(set);
+ }
+ }
+ }
+
+ private void CalculateDependancies()
+ {
+ //for (int i = 0; i < partitions; i++)
+ //{
+ // for (int j = 0; j < partitions; j++)
+ // {
+ // if (j == i) continue;
+ // List> intersections = IntersectSets(pi[i], pi[j]);
+ // if (IsSetOfSetsContained())
+ // }
+ //}
+ // TODO: Make the algorithm properly
+ for (int i = 0; i < partitions; i++)
+ {
+ dependancies.Add(new List());
+ for (int j = 0; j < partitions; j++)
+ {
+ if (i == j) continue;
+ dependancies[i].Add(j);
+ }
+ }
+ }
+
+ private void CalculateTranslations(AutomataTableBase table)
+ {
+ //---
+ Laba7.TriggerFunctions = new List();
+ //---
+ for (int i = 0; i < partitions; i++)
+ {
+ Laba7.TriggerFunctions.Add(new TriggerFunction());
+ relativeTables.Add(new AutomataTableRelative());
+ relativeTables[i].StateCount = 2;
+
+ List ints = new List();
+ for (int j = 0; j < Math.Pow(2, dependancies[i].Count); j++)
+ ints.Add(j);
+
+ for (int j = 0; j < ints.Count; j++) // для каждой комбинации зависимостей
+ {
+ List states = new List(); // состояния пи разбиения (после итерации должно остаться одно)
+ states.AddRange(pi[i][0]); states.AddRange(pi[i][1]);
+
+ int currentState = ints[j];
+ for (int k = 0; k < dependancies[i].Count; k++)
+ {
+ states = states.Intersect(pi[dependancies[i][k]][currentState & 1]).ToList();
+ currentState >>= 1;
+ } // вычислили все состояния (должен быть длины 1)
+
+ for (int k = 0; k < eta[i].Count; k++)
+ {
+ List cells = new List(); // создаем новый ряд для двух состояний
+ for (int u = 0; u < 2; u++) // для каждого (двух) состояний
+ {
+ List newStates = new List(states);
+ newStates = newStates.Intersect(pi[i][u]).ToList();
+
+ if (newStates.Count == 0)
+ cells.Add(new AutomataCellRelative(-2));
+ else
+ {
+ int st = ReverseState(pi[i], table.States[newStates[0]].Cells[eta[i][k][0]].State);
+ cells.Add(new AutomataCellRelative(st));
+ if (st == 0 && u == 1)
+ Laba7.TriggerFunctions[i].AddNewRule($"{Laba7.MakeBinary(k, eta[i].Count)}",
+ $"{ReturnCorrectBinary(Convert.ToString(ints[j], 2).PadLeft(partitions - 1, '0'), $"{u}", i)}");
+ }
+ }
+ relativeTables[i].Rows.Add(
+ new AutomataRowRelative(GenerateUserFriendlyName(dependancies[i].Count, 98 + i, k, ints[j]),
+ $"{Laba7.MakeBinary(ints[j], partitions - 1, true)} {Laba7.MakeBinary(k, eta[i].Count)}", cells));
+ }
+ }
+ }
+ }
+
+ private string ReturnCorrectBinary(string a, string b, int c)
+ {
+ string result = ""; bool flag = false;
+ for (int i = 0; i < a.Length; i++)
+ {
+ if (i == c) { result += b; flag = true; }
+ result += a[i];
+ }
+ if (!flag) result += b;
+ return result;
+ }
+
+ private string GenerateUserFriendlyName(int numOfStates, int skipLetter, int input, int state)
+ {
+ string result = ""; int nextLetter = 98;
+ for (int i = 0; i < numOfStates; i++)
+ {
+ if (nextLetter == skipLetter) nextLetter++;
+ result += $"{(char)(nextLetter)}{Common.SubScripts[Math.Abs((state & 1) + 1)]} * ";
+ nextLetter++; state >>= 1;
+ }
+ result = result.Substring(0, result.Length - 3);
+ result += $", x{input + 1}";
+ return result;
+ }
+
+ private void CalculateFunctionG(AutomataTableBase table)
+ {
+ tableG = new AutomataTableG(table);
+ Laba7.TriggerFunctions.Add(new TriggerFunction());
+ for (int i = 0; i < table.States.Length; i++)
+ {
+ List ints = new List();
+ for (int j = 0; j < pi.Count; j++)
+ {
+ if (pi[j][0].Contains(i)) ints.Add(1);
+ else ints.Add(0);
+ } // foud where is this state number in each pi partition
+ string title = "";
+ for (int j = 0; j < ints.Count; j++)
+ title += $"{(char)(98 + j)}{Common.SubScripts[ints[j] == 0 ? 2 : 1]} * ";
+ title = title.Substring(0, title.Length - 3);
+ tableG.Titles[i] = title;
+ tableG.BinTitles[i] = string.Join(" ", ints.Select(x => Math.Abs(x -1)));
+ for (int j = 0; j < tableG.Inputs; j++)
+ if (table.States[i].Cells[j].Output == 2)
+ Laba7.TriggerFunctions[partitions].AddNewRule(Laba7.MakeBinary(j, tableG.Inputs), tableG.BinTitles[i]);
+ }
+ }
+
+ public static List IntersectSets(List> list)
+ {
+ if (list == null || list.Count == 0)
+ {
+ return new List();
+ }
+
+ List commonNumbers = new List(list[0]);
+
+ foreach (List intList in list)
+ {
+ commonNumbers = commonNumbers.Intersect(intList).ToList();
+ }
+
+ return commonNumbers;
+ }
+
+ private List> dependancies = new List>();
+ private int partitions;
+ private List>> pi = new List>>();
+ private List>> tau = new List>>();
+ private List>> eta = new List>>();
+ private List tables = new List();
+ private List relativeTables = new List();
+ private AutomataTableG tableG;
+
+ public int Count { get { return partitions; } }
+ public List>> Pi { get { return pi; } set { pi = value; } }
+ public List>> Tau { get { return tau; } }
+ public List>> Eta { get { return eta; } }
+ public List Tables { get { return tables; } }
+ public List RelativeTables { get { return relativeTables; } }
+ public AutomataTableG TableG { get { return tableG; } }
+ }
+
+ public class AutomataTableG
+ {
+ public AutomataTableG(AutomataTableBase table)
+ {
+ _states = new AutomataStateBase[table.States.Length];
+ for (int i = 0; i < table.States.Length; i++)
+ {
+ _states[i] = new AutomataStateBase(table.Inputs, i);
+ for (int j = 0; j < table.Inputs; j++)
+ {
+ _states[i].Cells[j] = new AutomataCellBase(table.States[i].Cells[j].State, table.States[i].Cells[j].Output);
+ }
+ }
+ Inputs = table.Inputs;
+ Outputs = table.Outputs;
+ _titles = new string[table.States.Length];
+ _binTitles = new string[table.States.Length];
+ }
+
+ private AutomataStateBase[] _states;
+ private string[] _titles;
+ private string[] _binTitles;
+
+ public int Outputs;
+ public int Inputs;
+ public AutomataStateBase[] States { get { return _states; } }
+ public string[] Titles { get { return _titles; } set { _titles = value; } }
+ public string[] BinTitles { get { return _binTitles; } set { _binTitles = value; } }
+ }
+
+ public class AutomataTableRelative
+ {
+ public AutomataTableRelative()
+ {
+ _rows = new List();
+ }
+ public int StateCount;
+ private List _rows;
+ public List Rows { get { return _rows; } set { _rows = value; } }
+ }
+
+ public class AutomataRowRelative
+ {
+ public AutomataRowRelative(string name)
+ {
+ _name = name;
+ _cells = new List ();
+ }
+
+ public AutomataRowRelative(string name, string binName, List cells)
+ {
+ _name = name;
+ _binName = binName;
+ _cells = cells;
+ }
+
+ private string _name = string.Empty;
+ public string Name { get { return _name; } }
+ private string _binName = string.Empty;
+ public string BinName { get { return _binName; } }
+ private List _cells;
+ public List Cells { get { return _cells; } }
+ }
+
+ public class AutomataCellRelative
+ {
+ public AutomataCellRelative(int state)
+ {
+ _state = state;
+ }
+
+ private int _state = -1;
+
+ public int State { get { return _state; } }
+ }
+}
diff --git a/Automata theory/Laba7.cs b/Automata theory/Laba7.cs
new file mode 100644
index 0000000..0737313
--- /dev/null
+++ b/Automata theory/Laba7.cs
@@ -0,0 +1,144 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Automata_theory
+{
+ public partial class Laba7
+ {
+ public static List TriggerFunctions = new List();
+
+ public static string MakeBinary(int num, int maxnum, bool forStates = false)
+ {
+ if (forStates)
+ {
+ string result = "";
+ for (int i = 0; i < maxnum; i++)
+ {
+ result += $"{num & 1} ";
+ num >>= 1;
+ }
+ return string.Join("", result.Substring(0, result.Length - 1).Reverse());
+ }
+ string mn = Convert.ToString(maxnum-1, 2);
+ int power = (int)Math.Pow(2, mn.Length);
+ string n = Convert.ToString(power - num - 1, 2);
+ int zeros = mn.Length - n.Length;
+ for (int i = 0; i < zeros; i++)
+ n = "0" + n;
+ return n;
+ }
+ }
+
+ public class TriggerFunction
+ {
+ public TriggerFunction()
+ {
+ _items = new List>();
+ }
+
+ public void AddNewRule(string row, string col)
+ {
+ _items.Add(new List());
+ int inc = 1;
+ for (int i = 0; i < row.Length; i++)
+ {
+ if (row[i] == ' ') continue;
+ if (row[i] == '1') AddItem(new TriggerFunctionItem('a', inc, false)); //res += $"a{Common.SubScripts[inc]} \u22c5 ";
+ else AddItem(new TriggerFunctionItem('a', inc, true)); //$"a\u0305{Common.SubScripts[inc]} \u22c5 "; // \u22c5 - ⋅
+ inc++;
+ }
+ inc = 1;
+ for (int i = 0; i < col.Length; i++)
+ {
+ if (col[i] == ' ') continue;
+ if (col[i] == '2') { inc++; continue; }
+ if (col[i] == '1') AddItem(new TriggerFunctionItem('t', inc, false)); //res += $"t{Common.SubScripts[inc]} \u22c5 ";
+ else AddItem(new TriggerFunctionItem('t', inc, true));//res += $"t\u0305{Common.SubScripts[inc]} \u22c5 "; // \u22c5 - ⋅
+ inc++;
+ }
+ }
+
+ private void AddItem(TriggerFunctionItem item)
+ {
+ _items[_items.Count - 1].Add(item);
+ }
+
+ public string ToString(int layer = 0, int num = 0)
+ {
+ if (layer == 0)
+ {
+ string res = "F = ";
+ for (int i = 0; i < _items.Count; i++)
+ {
+ for (int j = 0; j < _items[i].Count; j++)
+ {
+ res += $"{_items[i][j].Symbol}{(_items[i][j].Inverse ? "\u0305" : "")}{Common.SubScripts[_items[i][j].Number]} \u22c5 ";
+ }
+ res = res.Remove(res.Length - 3, 3);
+ res += " \u22c1 ";
+ }
+ res = res.Remove(res.Length - 3, 3);
+ return res;
+ }
+ else if (layer == 1)
+ {
+ string res = "";
+ for (int j = 0; j < _items[num].Count; j++)
+ {
+ res += $"{_items[num][j].Symbol}{(_items[num][j].Inverse ? "\u0305" : "")}{Common.SubScripts[_items[num][j].Number]}";
+ }
+ return res;
+ }
+ else
+ throw new ArgumentOutOfRangeException();
+ }
+
+ private List> _items;
+ private List _names;
+ public List> Items { get { return _items; } }
+ public List Names { get { return _names; } }
+ }
+
+ public class TriggerFunctionItem
+ {
+ public TriggerFunctionItem(char sym, int num, bool inv)
+ {
+ _symbol = sym;
+ _number = num;
+ _inverse = inv;
+ }
+
+ public TriggerFunctionItem(TriggerFunctionItem item)
+ {
+ _symbol = item._symbol;
+ _number = item._number;
+ _inverse = item._inverse;
+ }
+
+ public static bool operator == (TriggerFunctionItem item1, TriggerFunctionItem item2)
+ {
+ if (item1.Inverse == item2.Inverse && item1.Number == item2.Number && item1.Symbol == item2.Symbol)
+ return true;
+ return false;
+ }
+
+ public static bool operator != (TriggerFunctionItem item1, TriggerFunctionItem item2)
+ {
+ if (item1.Inverse == item2.Inverse && item1.Number == item2.Number && item1.Symbol == item2.Symbol)
+ return false;
+ return true;
+ }
+
+ private char _symbol;
+ private int _number;
+ private bool _inverse;
+
+ public char Symbol { get { return _symbol; } }
+ public int Number { get { return _number; } }
+ public bool Inverse { get { return _inverse; } }
+ }
+}
diff --git a/Automata theory/Laba8.cs b/Automata theory/Laba8.cs
new file mode 100644
index 0000000..a31504e
--- /dev/null
+++ b/Automata theory/Laba8.cs
@@ -0,0 +1,324 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Automata_theory
+{
+ public partial class Laba8
+ {
+ public static List> ImplicatorsTables;
+ public static List IntersectionsTables;
+ public static List SimpleTriggersFunctions;
+
+ public static void SimplifyFunctions()
+ {
+ ImplicatorsTables = new List>(Laba7.TriggerFunctions.Count);
+ IntersectionsTables = new List();
+ SimpleTriggersFunctions = new List();
+ CalculateSimplerFunctions();
+ }
+
+ private static void CalculateSimplerFunctions()
+ {
+ for (int i = 0; i < Laba7.TriggerFunctions.Count; i++) // for each function
+ {
+ ImplicatorsTables.Add(new List());
+ ImplicatorsTable currentTable = new ImplicatorsTable();
+ for (int j = 0; j < Laba7.TriggerFunctions[i].Items.Count; j++)
+ {
+ currentTable.AddEntry(Laba7.TriggerFunctions[i].Items[j], new List() { j + 1 }, new List() { j });
+ }
+ ImplicatorsTables[i].Add(currentTable);
+ while (currentTable.Implicants.Count != 0)
+ {
+ currentTable = Iterate(currentTable);
+ ImplicatorsTables[i].Add(currentTable);
+ }
+ ImplicatorsTables[i].RemoveAt(ImplicatorsTables[i].Count - 1);
+ IntersectionTable intersectionTable = new IntersectionTable(ImplicatorsTables[i]);
+ IntersectionsTables.Add(intersectionTable);
+ SimpleTriggersFunctions.Add(new SimpleTriggerFunction(IntersectionsTables[i], ImplicatorsTables[i]));
+ }
+ }
+
+ public static ImplicatorsTable Iterate(ImplicatorsTable table)
+ {
+ ImplicatorsTable result = new ImplicatorsTable();
+ for (int i = 0; i < table.Implicants.Count; i++)
+ {
+ for (int j = i + 1; j < table.Implicants.Count; j++)
+ {
+ List list1 = new List();
+ List list2 = new List();
+ list1.AddRange(table.Implicants[i]);
+ list2.AddRange(table.Implicants[j]);
+ int counter = 0, index = -1;
+ for (int k = 0; k < list1.Count; k++)
+ {
+ if (list1[k].Number == list2[k].Number && list1[k].Symbol == list2[k].Symbol && list1[k].Inverse == !list2[k].Inverse)
+ { counter++; index = k; }
+ if (list1[k].Number != list2[k].Number || list1[k].Symbol != list2[k].Symbol)
+ { counter = -1; break; }
+ }
+ if (counter == 1)
+ {
+ List res = new List();
+ res.AddRange(NewList(table.Implicants[i]));
+ res = RemoveItem(res, list1[index]);
+ List ints = new List();
+ ints.AddRange(NewList(table.Level[i]));
+ ints.AddRange(NewList(table.Level[j]));
+ if (!ContainsEqual(result, res, new List { i + 1, j + 1 }, ints))
+ result.AddEntry(res, new List { i+1, j+1 }, ints);
+
+ }
+ if (result.Implicants.Count > 50) return result;
+ }
+ }
+ return result;
+ }
+
+ public static List RemoveItem(List list, TriggerFunctionItem item)
+ {
+ for (int i = 0; i < list.Count;i++)
+ {
+ if (list[i] == item)
+ {
+ list.RemoveAt(i);
+ }
+ }
+ return list;
+ }
+
+ private static List NewList(List list)
+ {
+ List result = new List();
+ for (int i = 0; i < list.Count;i++)
+ {
+ result.Add(new TriggerFunctionItem(list[i]));
+ }
+ return result;
+ }
+ private static List NewList(List list)
+ {
+ List result = new List();
+ for (int i = 0; i < list.Count; i++)
+ {
+
+ result.Add(list[i]);
+ }
+ return result;
+ }
+
+ private static bool ContainsEqual(ImplicatorsTable list, List item, List levels, List level)
+ {
+ for (int i = 0; i < list.Implicants.Count; i++)
+ {
+ if (Equals(list.Implicants[i], item))
+ {
+ list.Level[i].AddRange(level);
+ list.Levels[i].AddRange(levels);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static bool Equals(List a, List b)
+ {
+ if (a.Count != b.Count) return false;
+ for (int i = 0; i < a.Count; i++)
+ {
+ if (a[i] != b[i]) return false;
+ }
+ return true;
+ }
+ }
+
+ public class ImplicatorsTable
+ {
+ public ImplicatorsTable()
+ {
+ implicants = new List>();
+ levels = new List>();
+ level = new List>();
+ }
+
+ public void AddEntry(List implicant, List levels, List level)
+ {
+ implicants.Add(implicant);
+ this.levels.Add(levels);
+ this.level.Add(level);
+ }
+
+ public string ToString(int index)
+ {
+ string res = "";
+ for (int j = 0; j < implicants[index].Count; j++)
+ {
+ res += $"{implicants[index][j].Symbol}{(implicants[index][j].Inverse ? "\u0305" : "")}{Common.SubScripts[implicants[index][j].Number]}";
+ }
+ return res;
+ }
+
+ private List> implicants;
+ private List> levels;
+ private List> level;
+ public List> Implicants { get { return implicants; } }
+ public List> Levels { get { return levels; } }
+ public List> Level { get { return level; } }
+ }
+
+ public class IntersectionTable
+ {
+ public IntersectionTable(List table)
+ {
+ _implicants = new List>();
+ _bools = new List>();
+ _CDNF = table[0].Implicants.Count;
+ List ignore = new List(), ignoreOld = new List();
+ for (int i = table.Count - 1; i > 0; i--)
+ {
+ ignoreOld = ignore;
+ ignore = new List();
+ for (int j = 0; j < table[i].Implicants.Count; j++)
+ {
+ if (ignoreOld.Contains(j))
+ {
+ List ints = new List();
+ for (int h = 0; h < table[i].Levels[j].Count; h++)
+ ints.Add(table[i].Levels[j][h] - 1);
+ ignore.AddRange(ints);
+ continue;
+ }
+
+ _implicants.Add(table[i].Implicants[j]);
+ List bools = new List();
+ for (int k = 0; k < table[0].Implicants.Count; k++)
+ {
+ if (table[i].Level[j].Contains(k))
+ {
+ bools.Add(true);
+ List ints = new List();
+ for (int h = 0; h < table[i].Levels[j].Count; h++)
+ ints.Add(table[i].Levels[j][h] - 1);
+ ignore.AddRange(ints);
+ }
+ else bools.Add(false);
+ }
+ _bools.Add(bools);
+ }
+ }
+ }
+
+ public int Intersections(int cdnfAddress)
+ {
+ int result = 0;
+ for (int i = 0; i < _bools.Count; i++)
+ {
+ result += Convert.ToInt32(_bools[i][cdnfAddress]);
+ }
+ return result;
+ }
+
+ public override string ToString()
+ {
+ return "";
+ }
+
+ private int _CDNF;
+ public int CDNFAmount { get { return _CDNF; } }
+ private List> _bools; // first - implicants, second - CDNF
+ public List> Bools { get { return _bools; } }
+ private List> _implicants;
+ public List> Implicants { get { return _implicants; } }
+ }
+
+ public class SimpleTriggerFunction
+ {
+ public SimpleTriggerFunction(IntersectionTable table, List implicators)
+ {
+ _items = new List> ();
+ List done = new List ();
+ List items = new List ();
+ for (int i = 0; i < table.CDNFAmount; i++) // for every state in intersections table
+ if (table.Intersections(i) == 1) // if only one intersection in the state
+ for (int j = 0; j < table.Implicants.Count; j++) // for every implicant in table to check for the one intersecting with the state
+ if (table.Bools[j][i]) // if intersection detected, thats the one
+ {
+ items.Add(j); // add to list of implicants to add rules about
+ done.AddRange(ReturnLevelsOfImplicant(implicators, table.Implicants[j]).Select(x => x - 1)); // add to list of states that are covered by implicants
+ }
+
+ for (int i = 0; i < items.Count; i++) // for every item in list of implicant numbers
+ AddNewRule(table.Implicants[items[i]]); // add them to the list of rules
+
+ done = done.Distinct().ToList(); // leave only distinct
+ for (int i = 0; i < table.CDNFAmount; i++) // for every state in intersections table
+ if (done.Contains(i)) continue; // if state is covered by implicant, skip
+ else AddNewRule(implicators[0].Implicants[i]); // if not, add base rule to the list of rules
+ }
+
+ private List ReturnLevelsOfImplicant(List implicators, List item)
+ {
+ for (int i = implicators.Count - 1; i > 0; i--)
+ {
+ for (int j = 0; j < implicators[i].Levels.Count; j++)
+ {
+ if (Laba8.Equals(implicators[i].Implicants[j], item))
+ {
+ return implicators[i].Levels[j];
+ }
+ }
+ }
+ return null;
+ }
+
+ private void AddNewRule(List item)
+ {
+ List n = new List();
+ for (int i = 0; i < item.Count; i++)
+ {
+ n.Add(new TriggerFunctionItem(item[i].Symbol, item[i].Number, item[i].Inverse));
+ }
+ _items.Add(n);
+ }
+
+ public string ToString(int layer = 0, int num = 0)
+ {
+ if (layer == 0)
+ {
+ string res = "F = ";
+ for (int i = 0; i < _items.Count; i++)
+ {
+ for (int j = 0; j < _items[i].Count; j++)
+ {
+ res += $"{_items[i][j].Symbol}{(_items[i][j].Inverse ? "\u0305" : "")}{Common.SubScripts[_items[i][j].Number]} \u22c5 ";
+ }
+ res = res.Remove(res.Length - 3, 3);
+ res += " \u22c1 ";
+ }
+ res = res.Remove(res.Length - 3, 3);
+ return res;
+ }
+ else if (layer == 1)
+ {
+ string res = "";
+ for (int j = 0; j < _items[num].Count; j++)
+ {
+ res += $"{_items[num][j].Symbol}{(_items[num][j].Inverse ? "\u0305" : "")}{Common.SubScripts[_items[num][j].Number]}";
+ }
+ return res;
+ }
+ else
+ throw new ArgumentOutOfRangeException();
+ }
+
+ private List> _items;
+ private List _names;
+ public List> Items { get { return _items; } }
+ public List Names { get { return _names; } }
+ }
+}
\ No newline at end of file
diff --git a/Automata theory/Properties/AssemblyInfo.cs b/Automata theory/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..cd16a61
--- /dev/null
+++ b/Automata theory/Properties/AssemblyInfo.cs
@@ -0,0 +1,38 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Security;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Automata theory")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Automata theory")]
+[assembly: AssemblyCopyright("Copyright © 2023")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("46578950-62cc-4428-865e-e4fd844f2772")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
+
diff --git a/Automata theory/Properties/Resources.Designer.cs b/Automata theory/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..e7d3cc0
--- /dev/null
+++ b/Automata theory/Properties/Resources.Designer.cs
@@ -0,0 +1,62 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace Automata_theory.Properties {
+
+
+ ///
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ ///
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ ///
+ /// Returns the cached ResourceManager instance used by this class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Automata_theory.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+ }
+}
diff --git a/Automata theory/Properties/Resources.resx b/Automata theory/Properties/Resources.resx
new file mode 100644
index 0000000..af7dbeb
--- /dev/null
+++ b/Automata theory/Properties/Resources.resx
@@ -0,0 +1,117 @@
+
+
+
+
+
+