From 522f268e1b3d5eea750a2cc4920d5843b8769027 Mon Sep 17 00:00:00 2001 From: Ivan Kalivan Date: Wed, 22 May 2024 21:49:42 +0300 Subject: [PATCH] Maby baby --- .../Algoritm/Realizer.cs | 223 ++++++++++++++++++ .../Algoritm/StartParametres.cs | 36 +++ .../InsertParametresForm.cs | 28 +-- .../MainForm.Designer.cs | 4 - .../MainForm.cs | 77 ------ .../Manager.cs | 24 -- .../Menegment/Manager.cs | 44 ++++ .../Menegment/Visualizer.cs | 11 + .../Realizer.cs | 109 --------- .../StartParametres.cs | 21 -- .../Storage/State.cs | 107 +++++++-- .../Storage/StateStorage.cs | 25 +- .../Visualizer.cs | 110 --------- 13 files changed, 417 insertions(+), 402 deletions(-) create mode 100644 ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Algoritm/Realizer.cs create mode 100644 ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Algoritm/StartParametres.cs delete mode 100644 ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Manager.cs create mode 100644 ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Menegment/Manager.cs create mode 100644 ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Menegment/Visualizer.cs delete mode 100644 ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Realizer.cs delete mode 100644 ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/StartParametres.cs delete mode 100644 ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Visualizer.cs diff --git a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Algoritm/Realizer.cs b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Algoritm/Realizer.cs new file mode 100644 index 0000000..5df5260 --- /dev/null +++ b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Algoritm/Realizer.cs @@ -0,0 +1,223 @@ +using ISEbd_11_CoursePaper_Dmitriev_Andrey.Storage; + +namespace ISEbd_11_CoursePaper_Dmitriev_Andrey.Algoritm; + +/// +/// Реализатор (Алгоритм Дейкстры) +/// +public class Realizer +{ + /// + /// Бесконечность константа + /// (макс. знач. типа int) + /// + const int INF = int.MaxValue; + + /// + /// Состояние + /// + public State state; + + /// + /// Матрица смежности + /// + private List> _abjacencyMatrix; + + /// + /// Список вершин + /// + private List _vertex; + + /// + /// Число вершин + /// + private int _countVertex; + + /// + /// Список минимально возможных растояний до вершин + /// 0 - начальная точка + /// + private List _coust; + + /// + /// Список вершин в которых были: + /// true - были + /// falsr - небыли + /// + private List _known; + + /// + /// Список вершин из которых пришли в вершину индекса + /// -1 - начальная вершина или ещё не известно + /// + private List _path; + + /// + /// Стек для прохода по графу + /// + private Stack _visitedStack; + + /// + /// Текущий шаг цикла алгоритма + /// + private int _currentStep; + + /// + /// Текущая вершина + /// + private int _currentVertex; + + /// + /// Список текущих смежных вершин + /// + private List _currentEdges; + + /// + /// Индекс текущей смежной вершины + /// + private int _currentIndEdge; + + /// + /// Конструктор + /// + /// Параметры + public Realizer(StartParameters parameters) + { + _abjacencyMatrix = parameters.abjacencyMatrix; + _vertex = parameters.vertex; + _countVertex = _vertex.Count; + _coust = parameters.coust; + _known = new List(Enumerable.Repeat(false, _countVertex)); // Заполняем весь список false-ами + _path = new List(Enumerable.Repeat(-1, _countVertex)); // Заполняем весь список -1-ами + _visitedStack = new Stack(); + _currentStep = 1; + _currentVertex = -1; + } + + /// + /// Шаг Алгоритма + /// + public void StepAlg() + { + switch (_currentStep) + { + case 1: + _countVertex = FindNextVertex(); // Получение текущей вершины + + if (_countVertex == -1) _countVertex = _visitedStack.Pop(); // Если не нашли вершину то откатываемся назад по стеку + else _visitedStack.Push(_countVertex); // Если нашли - кладём в стек + + _currentEdges = FindEdge(); // определяем смежные вершины к текущей + _currentIndEdge = 0; + + _currentStep++; + break; + case 2: + if (!_known[_countVertex]) _known[_countVertex] = true; // Отображаем что мы были в этой вершине если в ней не были + else _currentStep = 1; // Возвращаемся к 1 шагу если мы уже были в этой вершие + + _currentStep++; + break; + case 3: + // Проходимся по всем смежным вершинам и устанавливаем им соответсвующие значения + if (_currentIndEdge < _currentEdges.Count) + { + _path[_currentEdges[_currentIndEdge]] = _currentVertex; + _coust[_currentEdges[_currentIndEdge]] = _coust[_currentVertex] + _abjacencyMatrix[_currentVertex][_currentIndEdge]; + _currentIndEdge++; + break; + } + + // После прохода по вершинам возвращаемся к 1 шагу + _currentStep = 1; + break; + } + } + + /// + /// Сохранение состояния + /// + public void SaveState() + { + // TODO Объявлять как новые списки все списки + state = new State(_abjacencyMatrix, _vertex, _coust, _known, _path, _visitedStack, _currentStep, _currentVertex, _currentEdges, _currentIndEdge); + } + + /// + /// Загрузка состояния + /// + /// Статус + public void LoadState(State state) + { + // TODO Объявлять как новые списки все списки + this.state = state; + _abjacencyMatrix = state.abjacencyMatrix; + _vertex = state.vertex; + _coust = state.coust; + _known = state.known; + _path = state.path; + _visitedStack = state.visitedStack; + _currentStep = state.currentStep; + _currentVertex = state.currentVertex; + _currentEdges = state.currentEdges; + _currentIndEdge = state.currentIndEdge; + } + + /// + /// Поиск следующей вершины + /// + /// Следующую вершину с наименьшей длинной + private int FindNextVertex() + { + int ind = -1; + int value = INF; + // Поиск последующих элементов + if (_currentVertex != -1) + { + List indsEdge = FindEdge(); + List weightEdge = _abjacencyMatrix[_currentVertex]; + + foreach (int i in indsEdge) + { + if (!_known[i] && weightEdge[i] < value) + { + ind = i; + value = _coust[i]; + } + } + } + // Поиск начального элемента + else + { + for (int i = 0; i < _countVertex; i++) + { + if (value > _coust[i]) + { + return i; + } + } + } + + return ind; + } + + /// + /// Поиск наименований смежных с текущей вершиной вершин + /// + /// Список смежных вершин + private List FindEdge() + { + List indsEdge = new List(); + + List edge = _abjacencyMatrix[_currentVertex]; + + for (int i = 0; i < _countVertex; i++) + { + if (edge[i] >= 0) + { + indsEdge.Add(i); + } + } + return indsEdge; + } +} \ No newline at end of file diff --git a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Algoritm/StartParametres.cs b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Algoritm/StartParametres.cs new file mode 100644 index 0000000..2b10a43 --- /dev/null +++ b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Algoritm/StartParametres.cs @@ -0,0 +1,36 @@ + +namespace ISEbd_11_CoursePaper_Dmitriev_Andrey.Algoritm; + +/// +/// Стартовые параметры +/// +public class StartParameters +{ + /// + /// Матрица смежности + /// + public List> abjacencyMatrix; + + /// + /// Список вершин + /// + public List vertex; + + /// + /// Список минимально возможных растояний до вершин + /// + public List coust; + + /// + /// Конструктор + /// + /// Матрица смежности + /// Список вершинparam> + /// Список минимально возможных растояний до вершин + public StartParameters(List> abjacencyMatrix, List vertex, List coust) + { + this.abjacencyMatrix = abjacencyMatrix; + this.vertex = vertex; + this.coust = coust; + } +} \ No newline at end of file diff --git a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/InsertParametresForm.cs b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/InsertParametresForm.cs index e777ac9..2df9e9d 100644 --- a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/InsertParametresForm.cs +++ b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/InsertParametresForm.cs @@ -54,7 +54,7 @@ public partial class InsertParametresForm : Form } else if (i * j > i * i) { - int k = random.Next(-1, 10); + int k = random.Next(-1, 3); textBox.Text = (k == 0 ? -1 : k).ToString(); //textBox.Text = "1"; } @@ -84,31 +84,7 @@ public partial class InsertParametresForm : Form } private void buttonAccept_Click(object sender, EventArgs e) { - int[][] arrayExp = new int[8][]; - for (int i = 0; i < 8; i++) - { - arrayExp[i] = new int[8]; - - } - for (int i = 1; i < 9; i++) - { - for (int j=i; j < 9; j++) - { - arrayExp[i-1][j-1] = int.Parse(textBoxes[i, j].Text); - arrayExp[j-1][i-1] = int.Parse(textBoxes[i, j ].Text); - } - } - int[] ar = new int[8] - { - INF,INF, INF, INF, INF, INF,INF, INF - }; - ar[(int)numericUpDownStV.Value - 1] = 0; - bool[] b = new bool[8] - { - false,false,false,false,false,false,false,false - }; - - delgateStpr.Invoke(new State(arrayExp , ar, b, (int)numericUpDownStV.Value - 1)); + delgateStpr.Invoke(new State()); Close(); } diff --git a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/MainForm.Designer.cs b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/MainForm.Designer.cs index f7802d1..36e1297 100644 --- a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/MainForm.Designer.cs +++ b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/MainForm.Designer.cs @@ -65,7 +65,6 @@ buttonBack.Size = new Size(57, 59); buttonBack.TabIndex = 10; buttonBack.UseVisualStyleBackColor = false; - buttonBack.Click += buttonBack_Click; // // buttonNext // @@ -77,7 +76,6 @@ buttonNext.Size = new Size(62, 59); buttonNext.TabIndex = 11; buttonNext.UseVisualStyleBackColor = false; - buttonNext.Click += buttonNext_Click; // // buttonStart // @@ -91,7 +89,6 @@ buttonStart.TabIndex = 12; buttonStart.Text = "Старт"; buttonStart.UseVisualStyleBackColor = false; - buttonStart.Click += buttonStart_Click; // // buttonFullBack // @@ -152,7 +149,6 @@ ToolStripMenuItemInfo.Name = "ToolStripMenuItemInfo"; ToolStripMenuItemInfo.Size = new Size(355, 32); ToolStripMenuItemInfo.Text = "Информация об Алгоритме"; - ToolStripMenuItemInfo.Click += ToolStripMenuItemInfo_Click; // // menuStrip // diff --git a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/MainForm.cs b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/MainForm.cs index 72073f3..f3777cc 100644 --- a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/MainForm.cs +++ b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/MainForm.cs @@ -7,85 +7,8 @@ namespace ISEbd_11_CoursePaper_Dmitriev_Andrey; public partial class MainForm : Form { - private Visualizer Visualizer; - private State state; - private StateStorage statestorage; - private Manager manager; - private TextBox[] textBoxsWay; - private TextBox[] textBoxsWeight; public MainForm() { InitializeComponent(); - textBoxsWay = new TextBox[9]; - textBoxsWeight = new TextBox[8]; - Visualizer = new(pictureBoxDeiktsra); - - } - - private void CreateTable(int startInd, int[] Ways, int[] Weight) - { - tableLayoutPanelMinInf.Controls.Clear(); - TextBox id = new TextBox(); - id.Text = "id"; - textBoxsWay[0] = new TextBox(); - textBoxsWay[0].Text = (startInd+1).ToString(); - TextBox w = new TextBox(); - w.Text = "Weight"; - tableLayoutPanelMinInf.Controls.Add(id, 0, 0); - tableLayoutPanelMinInf.Controls.Add(textBoxsWay[0], 1, 0); - tableLayoutPanelMinInf.Controls.Add(w, 2, 0); - for (int i = 1; i < 9; i++) - { - id = new TextBox(); - id.Text = i.ToString(); - textBoxsWay[i] = new TextBox(); - textBoxsWay[i].Text = Ways[i - 1].ToString(); - textBoxsWeight[i-1] = new TextBox(); - textBoxsWeight[i-1].Text = Weight[i-1].ToString(); - tableLayoutPanelMinInf.Controls.Add(id, 0, i); - tableLayoutPanelMinInf.Controls.Add(textBoxsWay[i], 1, i); - tableLayoutPanelMinInf.Controls.Add(textBoxsWeight[i - 1], 2, i); - } - } - private void SetStat(State state) - { - this.state = state; - Bitmap bitmap = new Bitmap(Width, Height); - Graphics g = Graphics.FromImage(bitmap); - - Visualizer.DrawState(state, g); - CreateTable(state.id, state.Veretex[state.id], state.Weight); - pictureBoxDeiktsra.Image = bitmap; - statestorage = new StateStorage(); - manager = new Manager(new StartParameters(state.Veretex, state.Weight, state.Visited, state.id)); - } - - private void buttonStart_Click(object sender, EventArgs e) - { - InsertParametresForm insertParametersForm = new InsertParametresForm(); - insertParametersForm.AddEvent(SetStat); - insertParametersForm.Show(); - } - - private void ToolStripMenuItemInfo_Click(object sender, EventArgs e) - { - InformationForm inf = new InformationForm(); - inf.ShowDialog(); - } - - private void buttonBack_Click(object sender, EventArgs e) - { - } - - private void buttonNext_Click(object sender, EventArgs e) - { - statestorage = manager.MakeStep(); - state = statestorage.GetStatus(); - Bitmap bitmap = new Bitmap(Width, Height); - Graphics g = Graphics.FromImage(bitmap); - Visualizer.DrawState(state, g); - CreateTable(state.id, state.Veretex[state.id], state.Weight); - pictureBoxDeiktsra.Image = bitmap; - } } diff --git a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Manager.cs b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Manager.cs deleted file mode 100644 index e2b3564..0000000 --- a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Manager.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Data.SqlTypes; -using System.Reflection.Metadata; -using System.Windows.Forms; -using ISEbd_11_CoursePaper_Dmitriev_Andrey.Storage; - -namespace ISEbd_11_CoursePaper_Dmitriev_Andrey; -public class Manager -{ - Realizer Realizer; - StateStorage Storage = new StateStorage(); - - public Manager(StartParameters startparametres) - { - Realizer = new(startparametres); - } - public StateStorage MakeStep() - { - Realizer.Step(); - Realizer.SetState(); - Storage.AddState(Realizer.state); - return Storage; - } -} \ No newline at end of file diff --git a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Menegment/Manager.cs b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Menegment/Manager.cs new file mode 100644 index 0000000..4c37611 --- /dev/null +++ b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Menegment/Manager.cs @@ -0,0 +1,44 @@ + +using ISEbd_11_CoursePaper_Dmitriev_Andrey.Algoritm; +using ISEbd_11_CoursePaper_Dmitriev_Andrey.Storage; + +namespace ISEbd_11_CoursePaper_Dmitriev_Andrey.Menegment; + +/// +/// Менеджер +/// +public class Manager +{ + /// + /// Список состояний + /// + private StateStorage _storage = new(); + + /// + /// Реализатор + /// + private Realizer _dijkstra; + + /// + /// Конструктор + /// + /// Параметры + public Manager(StartParameters parameters) + { + _dijkstra = new Realizer(parameters); + _dijkstra.SaveState(); + _storage.AddState(_dijkstra.state); + } + + /// + /// Логика шага и записи состояния в список + /// + /// Хранилище состояний + public StateStorage MakeStep() + { + _dijkstra.StepAlg(); + _dijkstra.SaveState(); + _storage.AddState(_dijkstra.state); + return _storage; + } +} \ No newline at end of file diff --git a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Menegment/Visualizer.cs b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Menegment/Visualizer.cs new file mode 100644 index 0000000..25c32b5 --- /dev/null +++ b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Menegment/Visualizer.cs @@ -0,0 +1,11 @@ + +namespace ISEbd_11_CoursePaper_Dmitriev_Andrey.Menegment; + +public class Visualizer +{ + //int radius = 50; + //int centerX = pictureBox.Width / 2; + //int centerY = pictureBox.Height / 2; + //int x1 = centerX + 3 * (int)(Math.Cos(2 * Math.PI * j / state.Veretex.Length) * radius); + //int y1 = centerY + 3 * (int)(Math.Sin(2 * Math.PI * j / state.Veretex.Length) * radius); +} \ No newline at end of file diff --git a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Realizer.cs b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Realizer.cs deleted file mode 100644 index 6f8b6ac..0000000 --- a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Realizer.cs +++ /dev/null @@ -1,109 +0,0 @@ -using ISEbd_11_CoursePaper_Dmitriev_Andrey.Storage; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.IO; -using System.Text.Json; -using System.Windows.Forms; - -namespace ISEbd_11_CoursePaper_Dmitriev_Andrey; - -public class Realizer -{ - public State state; - - int[][] Veretex; - /// - /// Known - /// - bool[] Visited; - /// - /// Cost - /// - int[] Weight; - - int id; - - //public Realizer(int[][] vertex, int[] mass) - //{ - // Veretex = vertex; - // state = state; - //} - - public Realizer(StartParameters parametres) - { - Veretex = parametres.Vertex; - Weight = parametres.ints; - Visited = parametres.bools; - id = parametres.id; - - } - - public void SetState() - { - state = new State(Veretex, Weight, Visited, id); - } - - - public void ReturnState(State state) - { - this.state = state; - Veretex = state.Veretex; - Visited = state.Visited; - Weight = state.Weight; - } - - public void Step() - { - int ind = FideIndMin(GetArrayDontVisited(Weight, Visited)); - Visited[id] = true; - int[] way = Veretex[id]; - for (int i = 0 ; i < way.Length; i++) - { - if (way[i] > 0) - { - if (Weight[id] + way[i] < Weight[i] && !Visited[i]) - { - Weight[i] = way[i] + Weight[id]; - } - } - } - id = ind; - } - private int FideIndMin(int[] list) - { - int id = 0; - int min = list[0]; - for (int i = 0; i < list.Length; i++) - { - if (list[i] < min) - { - min = list[i]; - id = i; - } - } - return id; - } - - private int[] GetArrayDontVisited(int[] list, bool[] visit) - { - int[] ajens = Veretex[id]; - - int[] array = new int[list.Length]; - - for(int i = 0;i < list.Length;i++) - { - - if (visit[i] || ajens[i] == -1) - { - array[i] = int.MaxValue; - - } - else - { - array[i] = list[i]; - } - } - return array; - } -} \ No newline at end of file diff --git a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/StartParametres.cs b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/StartParametres.cs deleted file mode 100644 index 85c76ba..0000000 --- a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/StartParametres.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace ISEbd_11_CoursePaper_Dmitriev_Andrey; - -public class StartParameters -{ - - public int[][] Vertex; - - public int[] ints; - public bool[] bools; - public int id; - public StartParameters(int[][] Vertex, int[] ints, bool[] bools, int id) - { - this.Vertex = Vertex; - this.ints = ints; - this.bools = bools; - this.id = id; - } -} \ No newline at end of file diff --git a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Storage/State.cs b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Storage/State.cs index fdc7cba..3e933e8 100644 --- a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Storage/State.cs +++ b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Storage/State.cs @@ -1,32 +1,95 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - + namespace ISEbd_11_CoursePaper_Dmitriev_Andrey.Storage; +/// +/// Состояние работы алгоритма +/// public class State { - - public int id { get; set; } - public int[][] Veretex { get; set; } /// - /// Known + /// Матрица смежности /// - public bool[] Visited { get; set; } - /// - /// Cost - /// - public int[] Weight { get; set; } + public List> abjacencyMatrix; - public State(int[][] veretex, int[] Weight, bool[] Visited, int id) + /// + /// Список вершин + /// + public List vertex; + + /// + /// Число вершин + /// + public int countVertex; + + /// + /// Список минимально возможных растояний до вершин + /// 0 - начальная точка + /// + public List coust; + + /// + /// Список вершин в которых были: + /// true - были + /// falsr - небыли + /// + public List known; + + /// + /// Список вершин из которых пришли в вершину индекса + /// -1 - начальная вершина или ещё не известно + /// + public List path; + + /// + /// Стек для прохода по графу + /// + public Stack visitedStack; + + /// + /// Текущий шаг цикла алгоритма + /// + public int currentStep; + + /// + /// Текущая вершина + /// + public int currentVertex; + + /// + /// Список текущих смежных вершин + /// + public List currentEdges; + + /// + /// Индекс текущей смежной вершины + /// + public int currentIndEdge; + + /// + /// Конструктор + /// + /// Матрица смежности + /// Список вершин + /// Список минимально возможных растояний до вершин + /// Список вершин в которых были + /// Список вершин из которых пришли в вершину индекса + /// Стек для прохода по графу + /// Текущий шаг цикла алгоритма + /// Текущая вершина + /// Список текущих смежных вершин + /// Индекс текущей смежной вершины + public State(List> abjacencyMatrix, List vertex, List coust, List known, List path, Stack visitedStack, int currentStep, int currentVertex, List currentEdges, int currentIndEdge) { - this.Veretex = veretex; - this.Weight = Weight; - this.Visited = Visited; - this.id = id; + this.abjacencyMatrix = abjacencyMatrix; + this.vertex = vertex; + this.countVertex = vertex.Count; + this.coust = coust; + this.known = known; + this.path = path; + this.visitedStack = visitedStack; + this.currentStep = currentStep; + this.currentVertex = currentVertex; + this.currentEdges = currentEdges; + this.currentIndEdge = currentIndEdge; } - - } diff --git a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Storage/StateStorage.cs b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Storage/StateStorage.cs index b53ea03..81341d2 100644 --- a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Storage/StateStorage.cs +++ b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Storage/StateStorage.cs @@ -1,20 +1,28 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text.Json; - + namespace ISEbd_11_CoursePaper_Dmitriev_Andrey.Storage; +/// +/// Хранилище состояний +/// public class StateStorage { - private List states = new List(); + /// + /// Список состояний + /// + List states = new List(); + /// + /// Индекс текущего состояния + /// private int _currentStatus = -1; + /// + /// Добавление состояния в список + /// + /// Состояние public void AddState(State state) { states.Add(state); - _currentStatus++; } /// @@ -47,6 +55,7 @@ public class StateStorage /// /// Получить установленный статус /// + /// Текущее состояние public State GetStatus() { return states[_currentStatus]; @@ -71,6 +80,4 @@ public class StateStorage { // TODO Сделать загрузку } - - } diff --git a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Visualizer.cs b/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Visualizer.cs deleted file mode 100644 index 2ddd44d..0000000 --- a/ISEbd-11_CoursePaper_Dmitriev_Andrey/ISEbd-11_CoursePaper_Dmitriev_Andrey/Visualizer.cs +++ /dev/null @@ -1,110 +0,0 @@ -using ISEbd_11_CoursePaper_Dmitriev_Andrey.Storage; -using System; -using System.Drawing; -using System.Windows.Forms; - - -namespace ISEbd_11_CoursePaper_Dmitriev_Andrey; - -public class Visualizer -{ - private Pen pen = new Pen(Color.White, 2); - private Pen penV = new Pen(Color.Red, 11); - private PictureBox pictureBox; - private List lines = new List(); - - public Visualizer(PictureBox pictureBox) - { - this.pictureBox = pictureBox; - this.pictureBox.Paint += PictureBox_Paint; - } - - private void PictureBox_Paint(object sender, PaintEventArgs e) - { - if (pictureBox.Tag is State state) - { - DrawState(state, e.Graphics); - } - } - - public void DrawState(State state, Graphics g) - { - lines.Add(state.id); - // Очищаем предыдущее изображение - g.Clear(pictureBox.BackColor); - - - // Параметры отрисовки - Brush brush = new SolidBrush(Color.White); - Font font = new Font("Arial", 15); - - // Рассчитываем радиус и центр для кругов - int radius = 50; - int centerX = pictureBox.Width / 2; - int centerY = pictureBox.Height / 2; - - // Отрисовываем круги в соответствии с текущим состоянием - for (int i = 0; i < state.Veretex.Length; i++) - { - int[] eges = state.Veretex[i]; - // Вычисляем позицию для каждого круга - int x = centerX + 3* (int)(Math.Cos(2*Math.PI * i / state.Veretex.Length) * radius); - int y = centerY + 3* (int)(Math.Sin(2*Math.PI * i / state.Veretex.Length) * radius); - for (int j = 0; j < state.Veretex.Length; j++) - { - if (eges[j] != -1) - { - int x1 = centerX + 3 * (int)(Math.Cos(2 * Math.PI * j / state.Veretex.Length) * radius); - int y1 = centerY + 3 * (int)(Math.Sin(2 * Math.PI * j / state.Veretex.Length) * radius); - g.DrawLine(pen,x,y,x1,y1); - - } - - } - if(lines.Contains(i)) - { - g.DrawEllipse(penV, x - radius / 2, y - radius / 2, radius, radius); - - } - // Рисуем круг - g.FillEllipse(brush, x - radius / 2, y - radius / 2, radius, radius); - g.DrawEllipse(pen, x - radius / 2, y - radius / 2, radius, radius); - - // Рисуем текст - string text = (i + 1).ToString(); - SizeF textSize = g.MeasureString(text, font); - g.DrawString(text, font, Brushes.Black, x - textSize.Width / 2, y - textSize.Height / 2); - } - } - - //public void DrawTable(int startInd, int[] Ways, int[] Weight, TextBox[] textBoxsWay, TextBox[] textBoxsWeight, TableLayoutPanel tableLayoutPanelMinInf) - //{ - // TextBox id = new TextBox(); - // id.Text = "id"; - // textBoxsWay[0] = new TextBox(); - // textBoxsWay[0].Text = (startInd + 1).ToString(); - // TextBox w = new TextBox(); - // w.Text = "Weight"; - // tableLayoutPanelMinInf.Controls.Add(id, 0, 0); - // tableLayoutPanelMinInf.Controls.Add(textBoxsWay[0], 1, 0); - // tableLayoutPanelMinInf.Controls.Add(w, 2, 0); - // for (int i = 1; i < 9; i++) - // { - // id = new TextBox(); - // id.Text = i.ToString(); - // textBoxsWay[i] = new TextBox(); - // textBoxsWay[i].Text = Ways[i - 1].ToString(); - // textBoxsWeight[i - 1] = new TextBox(); - // textBoxsWeight[i - 1].Text = Weight[i - 1].ToString(); - // tableLayoutPanelMinInf.Controls.Add(id, 0, i); - // tableLayoutPanelMinInf.Controls.Add(textBoxsWay[i], 1, i); - // tableLayoutPanelMinInf.Controls.Add(textBoxsWeight[i - 1], 2, i); - // } - //} - - public void UpdateVisualization(State state) - { - pictureBox.Tag = state; - pictureBox.Invalidate(); // Заставляем PictureBox перерисоваться - } -} \ No newline at end of file