-
Notifications
You must be signed in to change notification settings - Fork 0
Routers #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Palezehvat
wants to merge
11
commits into
master
Choose a base branch
from
Routers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Routers #11
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cdb5125
Структура графа + начало алгоритма Флойда
palorel ffbc5bf
Изменение структуры и выбора алгоритма
palorel a675cc4
+Комментарии, остались тесты
palorel 5380bb2
+Тесты
palorel 6a2e6f1
Изменение добавления
palorel 8d8fb0e
+Общение с пользователем
palorel e826eb1
Actions похоже не видит часть файлов
palorel 7987e13
Merge branch 'master' into Routers
palorel de435d6
Ревью
palorel 4b2f55c
Доревью
palorel 2458990
Доревью2
palorel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 17 | ||
| VisualStudioVersion = 17.4.33403.182 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Routers", "Routers\Routers.csproj", "{EB4BA75B-C03B-4E71-B21F-37AFE12F12FA}" | ||
| EndProject | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestsForRouters", "TestsForRouters\TestsForRouters.csproj", "{FB3AE590-F3E6-4FBF-A49E-C733744BAC40}" | ||
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsForTwoLists", "TestsForTwoLists\TestsForTwoLists.csproj", "{9C296729-ADA4-4900-8155-A9BE6FB52711}" | ||
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsForGraph", "TestsForGraph\TestsForGraph.csproj", "{E8F69361-637E-4930-B8F3-30A9506B0843}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {EB4BA75B-C03B-4E71-B21F-37AFE12F12FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {EB4BA75B-C03B-4E71-B21F-37AFE12F12FA}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {EB4BA75B-C03B-4E71-B21F-37AFE12F12FA}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {EB4BA75B-C03B-4E71-B21F-37AFE12F12FA}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {FB3AE590-F3E6-4FBF-A49E-C733744BAC40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {FB3AE590-F3E6-4FBF-A49E-C733744BAC40}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {FB3AE590-F3E6-4FBF-A49E-C733744BAC40}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {FB3AE590-F3E6-4FBF-A49E-C733744BAC40}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {9C296729-ADA4-4900-8155-A9BE6FB52711}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {9C296729-ADA4-4900-8155-A9BE6FB52711}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {9C296729-ADA4-4900-8155-A9BE6FB52711}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {9C296729-ADA4-4900-8155-A9BE6FB52711}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {E8F69361-637E-4930-B8F3-30A9506B0843}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {E8F69361-637E-4930-B8F3-30A9506B0843}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {E8F69361-637E-4930-B8F3-30A9506B0843}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {E8F69361-637E-4930-B8F3-30A9506B0843}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {18B17EA7-5909-4E96-B776-65626F45E146} | ||
| EndGlobalSection | ||
| EndGlobal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| namespace RoutersByGraph; | ||
|
|
||
| /// <summary> | ||
| /// A container consisting of two lists List Arcs, ListVertexes and its own size | ||
| /// </summary> | ||
| public class Graph | ||
| { | ||
| /// <summary> | ||
| /// Returns graph size | ||
| /// </summary> | ||
| /// <returns>Graph size</returns> | ||
| /// <exception cref="NullPointerException">If the graph is empty throw exception</exception> | ||
| public int Size() => sizeGraph; | ||
|
|
||
| /// <summary> | ||
| /// It is used as a wrapper for writing a graph to a file | ||
| /// </summary> | ||
| /// <param name="filePath">Location of the original file</param> | ||
| /// <exception cref="NullPointerException">An empty or unfilled graph throws an exception</exception> | ||
| public void WriteToFile(string filePath, string fileAfter) | ||
| { | ||
| if (edges == null || vertexes == null) | ||
| { | ||
| throw new NullGraphOrGraphComponentsException(); | ||
| } | ||
| edges.WirteToFile(filePath); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Function to return ListArcs | ||
| /// </summary> | ||
| /// <returns>ListArcs in Graph</returns> | ||
| public ListEdges? ReturnListArcs() => edges; | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Function to return ListVertexes | ||
| /// </summary> | ||
| /// <returns>ListVertexes</returns> | ||
| public ListVertexes? ReturnListVertexes() => vertexes; | ||
|
|
||
| /// <summary> | ||
| /// Checks that the graph and its components are filled | ||
| /// </summary> | ||
| /// <returns>Returns true if the graph or its components are filled otherwise false</returns> | ||
| public bool IsEmpty() | ||
| { | ||
| return edges == null || vertexes == null; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds paths from one vertex to another to the graph | ||
| /// </summary> | ||
| /// <param name="fromVertex">The vertex from which the path exits</param> | ||
| /// <param name="toVertex">The vertex that the path is included in</param> | ||
| /// <param name="sizeWay">Path Size</param> | ||
| public void AddArcs(int fromVertex, int toVertex, int sizeWay) | ||
| { | ||
|
|
||
| if (edges == null) | ||
| { | ||
| edges = new ListEdges(); | ||
| } | ||
| edges.AddElement(fromVertex, toVertex, sizeWay); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes the list of vertices in the graph | ||
| /// </summary> | ||
| /// <param name="size">The size of the future graph</param> | ||
| public void AddVertexes(int size) | ||
| { | ||
| if (vertexes == null) | ||
| { | ||
| vertexes = new ListVertexes(); | ||
| } | ||
| sizeGraph = size; | ||
| for(int i = 1; i <= sizeGraph; i++) | ||
| { | ||
| vertexes.AddElement(i); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The shell of the Kraskala algorithm | ||
| /// </summary> | ||
| /// <param name="graph">Accepts the graph for which the algorithm will be applied</param> | ||
| /// <returns>Returns true if the graph is connected and false otherwise</returns> | ||
| /// <exception cref="NullPointerException">Throws an exception if the graph or its components are empty</exception> | ||
| public bool KraskalAlgorithm(Graph graph) | ||
| { | ||
| if (edges == null) | ||
| { | ||
| throw new NullGraphOrGraphComponentsException(); | ||
| } | ||
| return edges.KraskalAlgorithm(graph); | ||
| } | ||
|
|
||
| private ListVertexes? vertexes { get; set; } | ||
|
|
||
| private ListEdges? edges { get; set; } | ||
|
|
||
| private int sizeGraph { get; set; } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace RoutersByGraph; | ||
|
|
||
| /// <summary> | ||
| /// Exception if there is a problem with the path to the file or there is an incorrect sequence inside the file | ||
| /// </summary> | ||
| public class InvalidFileException : Exception {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| namespace RoutersByGraph; | ||
|
|
||
| /// <summary> | ||
| /// A list of arcs consisting of a pair of vertices and arcs between them | ||
| /// </summary> | ||
| public class ListEdges | ||
| { | ||
| private ListElement? head; | ||
| private ListElement? tail; | ||
|
|
||
| private bool SortByVertexOrArcs(bool sortByVertex, ListElement firstListElement, ListElement secondListElement) | ||
| { | ||
| return sortByVertex ? firstListElement.FromVertex > secondListElement.FromVertex : firstListElement.SizeWay < secondListElement.SizeWay; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sorting by the list bubble method | ||
| /// </summary> | ||
| /// <param name="sortByVertex">The parameter for selecting a comparison in the subsequent sorting is true if by vertices and false if by arcs</param> | ||
| /// <exception cref="NullPointerException">Throws an exception if the list is empty</exception> | ||
| public void SortListArcs(bool sortByVertex) | ||
| { | ||
| if (head == null) | ||
| { | ||
| throw new NullGraphOrGraphComponentsException(); | ||
| } | ||
| int size = head.SizeListArcs; | ||
| for(int i = 0; i < size; ++i) | ||
| { | ||
| var walker = head; | ||
| for(int j = 0; j < size; ++j) | ||
| { | ||
| if (walker.Next != null && SortByVertexOrArcs(sortByVertex, walker, walker.Next)) | ||
| { | ||
| var item = new ListElement(walker.FromVertex, walker.ToVertex, walker.SizeWay); | ||
| walker.SizeWay = walker.Next.SizeWay; | ||
| walker.FromVertex = walker.Next.FromVertex; | ||
| walker.ToVertex = walker.Next.ToVertex; | ||
| walker.Next.SizeWay = item.SizeWay; | ||
| walker.Next.ToVertex = item.ToVertex; | ||
| walker.Next.FromVertex = item.FromVertex; | ||
| } | ||
| walker = walker.Next; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Removes arcs from the list | ||
| /// </summary> | ||
| /// <param name="fromVertex">The vertex from which the arc goes</param> | ||
| /// <param name="toVertex">The vertex to which the arc goes</param> | ||
| /// <exception cref="NullPointerException">Throws an exception if the list is empty</exception> | ||
| private void DeleteArc(int fromVertex, int toVertex) | ||
| { | ||
| if (head == null) | ||
| { | ||
| throw new NullGraphOrGraphComponentsException(); | ||
| } | ||
| var walker = head; | ||
| if (walker.FromVertex == fromVertex && walker.ToVertex == toVertex) | ||
| { | ||
| head = head.Next; | ||
| return; | ||
| } | ||
| while (walker.Next != null) | ||
| { | ||
| if (walker.Next.FromVertex == fromVertex && walker.Next.ToVertex == toVertex) | ||
| { | ||
| walker.Next = walker.Next.Next; | ||
| return; | ||
| } | ||
| walker = walker.Next; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Kraskal's algorithm for a minimal spanning tree | ||
| /// </summary> | ||
| /// <param name="graph">The graph in which everything is stored</param> | ||
| /// <returns>Returns false if the tree is not connected</returns> | ||
| /// <exception cref="NullPointerException">Throws an exception if the graph and its components are empty</exception> | ||
| public bool KraskalAlgorithm(Graph graph) | ||
| { | ||
| if (graph == null || graph.IsEmpty()) | ||
| { | ||
| throw new NullGraphOrGraphComponentsException(); | ||
| } | ||
| var listArcs = graph.ReturnListArcs(); | ||
| var listVertexes = graph.ReturnListVertexes(); | ||
| if (listArcs == null || listVertexes == null || head == null) | ||
| { | ||
| throw new NullReferenceException(); | ||
| } | ||
| listArcs.SortListArcs(false); | ||
| var walker = listArcs.head; | ||
| int set = 1; | ||
| int anotherSet = 0; | ||
| while (walker != null) | ||
| { | ||
| if (walker.ToVertex != walker.FromVertex) | ||
| { | ||
| int returnedNumberPlentyFirstVertex = listVertexes.SearchForASuitableSet(walker.FromVertex); | ||
| int returnedNumberPlentySecondVertex = listVertexes.SearchForASuitableSet(walker.ToVertex); | ||
|
|
||
| if (returnedNumberPlentyFirstVertex != returnedNumberPlentySecondVertex) | ||
| { | ||
| if (returnedNumberPlentyFirstVertex == 0 && returnedNumberPlentySecondVertex != 0) | ||
| { | ||
| listVertexes.ChangeOneVertexSet(walker.FromVertex, returnedNumberPlentySecondVertex); | ||
| --anotherSet; | ||
| } | ||
| else if (returnedNumberPlentyFirstVertex != 0 && returnedNumberPlentySecondVertex == 0) | ||
| { | ||
| listVertexes.ChangeOneVertexSet(walker.ToVertex, returnedNumberPlentyFirstVertex); | ||
| --anotherSet; | ||
| } | ||
| else | ||
| { | ||
| listVertexes.ChangeNumbersSet(returnedNumberPlentyFirstVertex, returnedNumberPlentySecondVertex); | ||
| --anotherSet; | ||
| } | ||
| } | ||
| else if (returnedNumberPlentyFirstVertex == 0) | ||
| { | ||
| listVertexes.ChangeOneVertexSet(walker.FromVertex, set); | ||
| listVertexes.ChangeOneVertexSet(walker.ToVertex, set); | ||
| ++set; | ||
| ++anotherSet; | ||
| } | ||
| else | ||
| { | ||
| DeleteArc(walker.FromVertex, walker.ToVertex); | ||
| --head.SizeListArcs; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| DeleteArc(walker.FromVertex, walker.ToVertex); | ||
| --head.SizeListArcs; | ||
| } | ||
| walker = walker.Next; | ||
| } | ||
| SortListArcs(true); | ||
| return !(walker == null && anotherSet != 1 && anotherSet != 0); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds a new item to the list | ||
| /// </summary> | ||
| /// <param name="fromVertex">The vertex from which the arc originates</param> | ||
| /// <param name="toVertex">The vertex that the arc enters</param> | ||
| /// <param name="sizeWay">Arc Size</param> | ||
| public void AddElement(int fromVertex, int toVertex, int sizeWay) | ||
| { | ||
| var item = new ListElement(fromVertex, toVertex, sizeWay); | ||
| if (head == null) | ||
| { | ||
| head = item; | ||
| } | ||
| else | ||
| { | ||
| tail.Next = item; | ||
| } | ||
| tail = item; | ||
| ++head.SizeListArcs; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Writing to the arc list file | ||
| /// </summary> | ||
| /// <param name="filePath">The path to the file</param> | ||
| public void WirteToFile(string fileAfter) | ||
| { | ||
| var file = new StreamWriter(fileAfter); | ||
| var walker = head; | ||
| int previousMainVertex = 0; | ||
| bool isFirst = true; | ||
| while (walker != null) | ||
| { | ||
| if (walker.FromVertex != previousMainVertex) | ||
| { | ||
| if (!isFirst) | ||
| { | ||
| file.WriteLine(); | ||
| } | ||
| file.Write(walker.FromVertex); | ||
| file.Write(": "); | ||
| previousMainVertex = walker.FromVertex; | ||
| isFirst = false; | ||
| } | ||
| else | ||
| { | ||
| file.Write(", "); | ||
| } | ||
| file.Write(walker.ToVertex); | ||
| file.Write(" ("); | ||
| file.Write(walker.SizeWay); | ||
| file.Write(")"); | ||
| walker = walker.Next; | ||
| } | ||
| file.Close(); | ||
| } | ||
|
|
||
| private class ListElement | ||
| { | ||
| public ListElement(int fromVertex, int toVertex, int sizeWay) | ||
| { | ||
| FromVertex = fromVertex; | ||
| ToVertex = toVertex; | ||
| SizeWay = sizeWay; | ||
| } | ||
|
|
||
| public int FromVertex { get; set; } | ||
|
|
||
| public int ToVertex { get; set; } | ||
| public ListElement? Next { get; set; } | ||
|
|
||
| public int SizeWay { get; set; } | ||
|
|
||
| public int SizeListArcs { get; set; } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А зачем этот класс вообще, если всё, что он делает, это передаёт все вызовы в GraphElement?