diff --git a/BellmanFordShortestPathPlugin/BellmanFordShortestPathPlugin.cs b/BellmanFordShortestPathPlugin/BellmanFordShortestPathPlugin.cs new file mode 100644 index 000000000..ce719cbef --- /dev/null +++ b/BellmanFordShortestPathPlugin/BellmanFordShortestPathPlugin.cs @@ -0,0 +1,225 @@ +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using System.Windows.Forms.Integration; +using System.Windows.Media; +using Common; +using Mono.Addins; +using QuickGraph; +using QuickGraph.GraphXAdapter; +using System; +using System.ComponentModel; +using MessageBox = System.Windows.Forms.MessageBox; +using Point = System.Drawing.Point; + +[assembly: Addin] +[assembly: AddinDependency("GraphTasks", "1.0")] + +namespace BellmanFordShortestPathPlugin +{ + using QuickGraph.Algorithms.ShortestPath; + using Graph = BidirectionalGraph>; + using GraphArea = BidirectionalGraphArea>; + + [Extension] + public class BellmanFordShortestPathPlugin : IAlgorithm + { + private readonly GraphArea _graphArea; + private readonly GraphXZoomControl _zoomControl; + private bool _hasStarted; + private bool _hasFinished; + private Label listVBoxName; + private Label listEBoxName; + private ListBox algOrderListBox; + private ListBox algEdgesListBox; + private readonly TextBox startVertex; + private Label sLabel; + private BindingList algEdgesList; + private BindingList algOrderList; + private List estates; + private List colors; + private BellmanFordShortestPathAlgorithm> bellman; + private int currState; + private String distances; + + byte a = 0xFF, r = 0xE3, g = 0xE3, b = 0xE3; + + private class EdgeState + { + public EdgeState(GraphXTaggedEdge e, SolidColorBrush c) + { + this.e = e; + this.v = e.Target; + this.c = c; + } + public GraphXTaggedEdge e; + public GraphXVertex v; + public SolidColorBrush c; + } + + + + public BellmanFordShortestPathPlugin() + { + + _graphArea = new GraphArea(); + _zoomControl = new GraphXZoomControl { Content = _graphArea }; + Output.Controls.Add(new ElementHost { Dock = DockStyle.Fill, Child = _zoomControl }); + + sLabel = new Label { Location = new Point(200, 0), Text = "Start vertex:" }; + listVBoxName = new Label { Text = "Vertices:", Location = new Point(10, 0), Width = 50 }; + listEBoxName = new Label { Text = "Edges:", Location = new Point(100, 0), Width = 50 }; + startVertex = new TextBox { Location = new Point(200, 25) }; + algOrderListBox = new ListBox { Location = new Point(10, 25), Width = 50, Height = 80 }; + algEdgesListBox = new ListBox { Location = new Point(100, 25), Width = 50, Height = 80 }; + + algOrderList = new BindingList(); + algEdgesList = new BindingList(); + algOrderListBox.DataSource = algOrderList; + algEdgesListBox.DataSource = algEdgesList; + + Options.Controls.AddRange(new Control[] { algOrderListBox, listVBoxName, algEdgesListBox, listEBoxName, sLabel, startVertex }); + } + + public string Name => "Bellman Ford algorithm Plugin"; + public string Author => "Alisa Meteleva"; + public string Description => "This plugin demonstrates how Bellman Ford alg works.\n"; + + public Panel Options { get; } = new Panel { Dock = DockStyle.Fill }; + public Panel Output { get; } = new Panel { Dock = DockStyle.Fill }; + + public bool CanGoBack => currState != 0 && estates.Count != 0; + public bool CanGoFurther => _hasStarted && !_hasFinished; + + public void Run(string dotSource) + { + + if (startVertex.Text == "") + { + MessageBox.Show("Please specify start vertix first!\n"); + return; + } + + algOrderList.Clear(); + algEdgesList.Clear(); + + var vertexFun = VertexFactory.Name; + var edgeFun = EdgeFactory.Weighted(0); + var graph = Graph.LoadDot(dotSource, vertexFun, edgeFun); + distances = ""; + estates = new List(); + colors = new List { Colors.LightGreen, Colors.Lime, Colors.DarkGreen, Colors.DarkOliveGreen }; + + if (graph.IsVerticesEmpty) + { + MessageBox.Show("Graph is empty."); + return; + } + + + bellman = new BellmanFordShortestPathAlgorithm>(graph, x => x.Tag); + bellman.ExamineEdge += OnExamineEdge; + + + var sVertix = graph.Vertices.Single(x => x.ToString() == startVertex.Text); + bellman.Compute(sVertix); + currState = -1; + + + _graphArea.LogicCore.Graph = graph; + _graphArea.GenerateGraph(); + _zoomControl.ZoomToFill(); + + foreach (var e in _graphArea.EdgesList) + { + e.Value.ShowLabel = true; + } + + _hasStarted = true; + _hasFinished = false; + + foreach (var v in bellman.VisitedGraph.Vertices) + { + distances += "Shortest distance for vertex" + v.ToString() + " equals " + bellman.Distances[v].ToString() + "\n"; + } + + } + + private void HighlightTraversal() + { + if (currState == 0) + { + _graphArea.VertexList[estates[currState].e.Source].Background = new SolidColorBrush(Colors.Cyan); + } + + + var currColorE = estates[currState].c.Color; + var currEdge = estates[currState]; + + var timeEdge = algEdgesList.Count(x => x == EdgeToString(currEdge.e)); + if (timeEdge != 0) + { + estates[currState].c = new SolidColorBrush(colors[timeEdge % colors.Count]); + } + _graphArea.EdgesList[currEdge.e].Foreground = estates[currState].c; + _graphArea.VertexList[currEdge.v].Background = estates[currState].c; + + + + } + + public void NextStep() + { + + currState++; + + var toadd = estates[currState].v.ToString(); + + HighlightTraversal(); + + algOrderList.Insert(currState, toadd); + algEdgesList.Insert(currState, EdgeToString(estates[currState].e)); + + _hasFinished = currState == estates.Count - 1; + if (_hasFinished) + { + MessageBox.Show(distances); + startVertex.Text = ""; + } + + } + + public void PreviousStep() + { + _hasFinished = false; + + algOrderList.RemoveAt(currState); + + var color = Color.FromArgb(a, r, g, b); + var currEdge = estates[currState]; + var timeEdge = algEdgesList.Count(x => x == EdgeToString(currEdge.e)); + + if (!currEdge.c.Color.Equals(Colors.YellowGreen)) + { + color = colors[(timeEdge - 2) % colors.Count]; + } + + _graphArea.EdgesList[currEdge.e].Foreground = new SolidColorBrush(color); + _graphArea.VertexList[currEdge.v].Background = new SolidColorBrush(color); + algEdgesList.RemoveAt(currState); + + currState--; + } + + private void OnExamineEdge(GraphXTaggedEdge edge) + { + estates.Add(new EdgeState(edge, new SolidColorBrush(Colors.YellowGreen))); + } + + private String EdgeToString(GraphXTaggedEdge edge) + { + return edge.Source.ToString() + edge.Target.ToString(); + } + + } +} \ No newline at end of file diff --git a/BellmanFordShortestPathPlugin/BellmanFordShortestPathPlugin.csproj b/BellmanFordShortestPathPlugin/BellmanFordShortestPathPlugin.csproj new file mode 100644 index 000000000..06ceda5db --- /dev/null +++ b/BellmanFordShortestPathPlugin/BellmanFordShortestPathPlugin.csproj @@ -0,0 +1,119 @@ + + + + + + Debug + AnyCPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5} + Library + Properties + WeaklyConnectedComponents + WeaklyConnectedComponents + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + {fa87b6f5-3cf2-4ce6-9c0f-1fbc3c04ab85} + FloydWarshallShortestPathPlugin + + + {8826810a-dc59-46e6-8978-21e273db1236} + DotParser + + + {e383f190-86fe-454c-8568-1762f8820925} + GraphTask.Common + + + {61db192b-ed4f-43f7-bf8e-8d6d1fa05c39} + HelperForKruskalAndPrimVisualisation + + + {d2e33fee-6689-4bb4-a95c-1b5c327a1e8f} + GraphX.WPF.Controls + + + {3644d44b-dec0-4b65-bba0-c68e34821aae} + GraphX.PCL.Common + + + {a30d218b-aaa4-483a-99f7-eaeb1b8b4610} + GraphX.PCL.Logic + + + {960c14d1-edbd-40e5-8ae6-25e311551b87} + QuickGraph.Data + + + {595d6322-637a-4a36-97f1-d53f3f9ecea7} + QuickGraph.Graphviz + + + {646cfbb0-b998-45e7-8809-991a5538ff36} + QuickGraph.GraphXAdapter + + + {a9a5c115-0680-44b3-a87e-5ecf4c93814e} + QuickGraph + + + + + + + + + ..\packages\Mono.Addins\lib\net40\Mono.Addins.dll + True + True + + + + + \ No newline at end of file diff --git a/BellmanFordShortestPathPlugin/Properties/AssemblyInfo.cs b/BellmanFordShortestPathPlugin/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..d9b81ca9d --- /dev/null +++ b/BellmanFordShortestPathPlugin/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 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("WeaklyConnectedComponents")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WeaklyConnectedComponents")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[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("efceb44f-bc83-41d0-8970-ff4ecf897be5")] + +// 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/BellmanFordShortestPathPlugin/paket.references b/BellmanFordShortestPathPlugin/paket.references new file mode 100644 index 000000000..5055be0e4 --- /dev/null +++ b/BellmanFordShortestPathPlugin/paket.references @@ -0,0 +1,2 @@ +Mono.Addins +Microsoft.Net.Compilers \ No newline at end of file diff --git a/DagShortestPathPlugin/DagShortestPathPlugin.cs b/DagShortestPathPlugin/DagShortestPathPlugin.cs new file mode 100644 index 000000000..ecc9ccdcd --- /dev/null +++ b/DagShortestPathPlugin/DagShortestPathPlugin.cs @@ -0,0 +1,193 @@ +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using System.Windows.Forms.Integration; +using System.Windows.Media; +using Common; +using Mono.Addins; +using QuickGraph; +using QuickGraph.GraphXAdapter; +using System; +using System.ComponentModel; +using MessageBox = System.Windows.Forms.MessageBox; +using Point = System.Drawing.Point; + +[assembly: Addin] +[assembly: AddinDependency("GraphTasks", "1.0")] + +namespace DagShortestPathPlugin +{ + using QuickGraph.Algorithms.ShortestPath; + using Graph = BidirectionalGraph>; + using GraphArea = BidirectionalGraphArea>; + + [Extension] + public class DagShortestPathPlugin : IAlgorithm + { + private readonly GraphArea _graphArea; + private readonly GraphXZoomControl _zoomControl; + private bool _hasStarted; + private bool _hasFinished; + private readonly TextBox _startVertex; + private Label listBoxName; + private ListBox algOrderListBox; + private BindingList algOrderList; + private List states; + private DagShortestPathAlgorithm> dag; + private int currState; + private String distances; + + byte a = 0xFF, r = 0xE3, g = 0xE3, b = 0xE3; + + private class State + { + public State(GraphXVertex v, SolidColorBrush c) + { + this.v = v; + this.c = c; + } + public GraphXVertex v; + public SolidColorBrush c; + } + + + public DagShortestPathPlugin() + { + _graphArea = new GraphArea(); + _zoomControl = new GraphXZoomControl { Content = _graphArea }; + _startVertex = new TextBox { Location = new Point(220, 20) }; + + Output.Controls.Add(new ElementHost { Dock = DockStyle.Fill, Child = _zoomControl }); + var sLabel = new Label { Location = new Point(225, 0), Text = "Start vertex:" }; + listBoxName = new Label { Text = "Order of chosen vertices:", Location = new Point(10, 0) }; + algOrderListBox = new ListBox { Location = new Point(10, 20), Width = 160, Height = 80 }; + algOrderList = new BindingList(); + algOrderListBox.DataSource = algOrderList; + Options.Controls.AddRange(new Control[] { _startVertex, sLabel, algOrderListBox, listBoxName }); + + } + + public string Name => "Dag algorithm Plugin"; + public string Author => "Alisa Meteleva"; + public string Description => "This plugin demonstrates how Dag alg works.\n"; + + public Panel Options { get; } = new Panel { Dock = DockStyle.Fill }; + public Panel Output { get; } = new Panel { Dock = DockStyle.Fill }; + + public bool CanGoBack => currState != 0 && states.Count != 0; + public bool CanGoFurther => _hasStarted && !_hasFinished; + + public void Run(string dotSource) + { + + if (_startVertex.Text == "") + { + MessageBox.Show("Please specify start vertix first!\n"); + return; + } + + var vertexFun = VertexFactory.Name; + var edgeFun = EdgeFactory.Weighted(0); + var graph = Graph.LoadDot(dotSource, vertexFun, edgeFun); + var startVertix = graph.Vertices.Single(x => x.ToString() == _startVertex.Text); + states = new List(); + distances = ""; + + + + if (graph.IsVerticesEmpty) + { + MessageBox.Show("Graph is empty."); + return; + } + + + dag = new DagShortestPathAlgorithm>(graph, x => x.Tag); + + dag.DiscoverVertex += OnDiscoverVertex; + dag.FinishVertex += OnStartVertex; + dag.Compute(startVertix); + + currState = -1; + + _graphArea.LogicCore.Graph = graph; + _graphArea.GenerateGraph(); + _zoomControl.ZoomToFill(); + + foreach (var e in _graphArea.EdgesList) + { + e.Value.ShowLabel = true; + } + + _hasStarted = true; + _hasFinished = false; + foreach (var v in dag.VisitedGraph.Vertices) + { + distances += "Shortest distance for vertix" + v.ToString() + " equals " + dag.Distances[v].ToString() + "\n"; + } + } + + private void HighlightTraversal() + { + var currNode = states[currState].v; + _graphArea.VertexList[currNode].Background = states[currState].c; + } + + public void NextStep() + { + currState++; + _hasFinished = currState == states.Count - 1; + var toadd = states[currState].v.ToString(); + var shortDistance = dag.Distances[states[currState].v]; + + HighlightTraversal(); + + if (shortDistance == double.MaxValue) + { + toadd += " Unreachable from start vertex "; + _graphArea.VertexList[states[currState].v].Background = new SolidColorBrush(Colors.DarkSlateBlue); + } + else + if (states[currState].c.Color.Equals(Colors.Magenta)) + { + toadd += " shortest path is " + shortDistance; + } + + algOrderList.Insert(currState, toadd); + if (_hasFinished) + { + MessageBox.Show(distances); + _startVertex.Text = ""; + } + + } + + public void PreviousStep() + { + _hasFinished = false; + var currNode = states[currState]; + + if (currNode.c.Color.Equals(Colors.Magenta)) + { + _graphArea.VertexList[currNode.v].Background = new SolidColorBrush(Colors.YellowGreen); + } + else + { + _graphArea.VertexList[currNode.v].Background = new SolidColorBrush(Color.FromArgb(a, r, g, b)); + } + + algOrderList.RemoveAt(currState); + currState--; + } + + private void OnDiscoverVertex(GraphXVertex vertex) + { + states.Add(new State(vertex, new SolidColorBrush(Colors.YellowGreen))); + } + + private void OnStartVertex(GraphXVertex vertex) + { + states.Add(new State(vertex, new SolidColorBrush(Colors.Magenta))); + } + } +} \ No newline at end of file diff --git a/DagShortestPathPlugin/DagShortestPathPlugin.csproj b/DagShortestPathPlugin/DagShortestPathPlugin.csproj new file mode 100644 index 000000000..fd80e43bf --- /dev/null +++ b/DagShortestPathPlugin/DagShortestPathPlugin.csproj @@ -0,0 +1,119 @@ + + + + + + Debug + AnyCPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954} + Library + Properties + StronglyConnectedComponents + StronglyConnectedComponents + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + {fa87b6f5-3cf2-4ce6-9c0f-1fbc3c04ab85} + FloydWarshallShortestPathPlugin + + + {8826810a-dc59-46e6-8978-21e273db1236} + DotParser + + + {e383f190-86fe-454c-8568-1762f8820925} + GraphTask.Common + + + {61db192b-ed4f-43f7-bf8e-8d6d1fa05c39} + HelperForKruskalAndPrimVisualisation + + + {d2e33fee-6689-4bb4-a95c-1b5c327a1e8f} + GraphX.WPF.Controls + + + {3644d44b-dec0-4b65-bba0-c68e34821aae} + GraphX.PCL.Common + + + {a30d218b-aaa4-483a-99f7-eaeb1b8b4610} + GraphX.PCL.Logic + + + {960c14d1-edbd-40e5-8ae6-25e311551b87} + QuickGraph.Data + + + {595d6322-637a-4a36-97f1-d53f3f9ecea7} + QuickGraph.Graphviz + + + {646cfbb0-b998-45e7-8809-991a5538ff36} + QuickGraph.GraphXAdapter + + + {a9a5c115-0680-44b3-a87e-5ecf4c93814e} + QuickGraph + + + + + + + + + ..\packages\Mono.Addins\lib\net40\Mono.Addins.dll + True + True + + + + + \ No newline at end of file diff --git a/DagShortestPathPlugin/Properties/AssemblyInfo.cs b/DagShortestPathPlugin/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..c69631d6e --- /dev/null +++ b/DagShortestPathPlugin/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 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("StronglyConnectedComponents")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("StronglyConnectedComponents")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[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("cac7bc68-08ad-4a6c-8024-813e29d4f954")] + +// 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/DagShortestPathPlugin/paket.references b/DagShortestPathPlugin/paket.references new file mode 100644 index 000000000..5055be0e4 --- /dev/null +++ b/DagShortestPathPlugin/paket.references @@ -0,0 +1,2 @@ +Mono.Addins +Microsoft.Net.Compilers \ No newline at end of file diff --git a/FloydWarshallShortestPathPlugin/FloydWarshallShortestPathPlugin.cs b/FloydWarshallShortestPathPlugin/FloydWarshallShortestPathPlugin.cs new file mode 100644 index 000000000..cd9341f75 --- /dev/null +++ b/FloydWarshallShortestPathPlugin/FloydWarshallShortestPathPlugin.cs @@ -0,0 +1,162 @@ +using System.Linq; +using System.Windows.Forms; +using System.Windows.Media; +using Common; +using Mono.Addins; +using QuickGraph; +using QuickGraph.GraphXAdapter; +using System; +using MessageBox = System.Windows.Forms.MessageBox; +using Point = System.Drawing.Point; + +[assembly: Addin] +[assembly: AddinDependency("GraphTasks", "1.0")] + +namespace FloydWarshallShortestPathPlugin +{ + using QuickGraph.Algorithms.ShortestPath; + using Graph = BidirectionalGraph>; + using GraphArea = BidirectionalGraphArea>; + + [Extension] + public class FloydWarshallShortestPathPlugin : IAlgorithm + { + + private int dimension; + private bool _hasStarted; + private bool _hasFinished; + private FloydWarshallAllShortestPathAlgorithm> floyd; + private int currState; + + public FloydWarshallShortestPathPlugin() + { + Options.Controls.AddRange(new Control[] { }); + } + + public string Name => "Floyd Warshall algorithm Plugin"; + public string Author => "Alisa Meteleva"; + public string Description => "This plugin demonstrates how Floyd Warshall alg works.\n"; + + public Panel Options { get; } = new Panel { Dock = DockStyle.Fill }; + public Panel Output { get; } = new Panel { Dock = DockStyle.Fill }; + + public bool CanGoBack => currState != 0; + public bool CanGoFurther => _hasStarted && !_hasFinished; + + public void Run(string dotSource) + { + Output.Controls.Clear(); + + var vertexFun = VertexFactory.Name; + var edgeFun = EdgeFactory.Weighted(0); + var graph = Graph.LoadDot(dotSource, vertexFun, edgeFun); + + dimension = graph.Vertices.Count(); + + if (graph.IsVerticesEmpty) + { + MessageBox.Show("Graph is empty."); + return; + } + + //add cells for distances + for (var i = 1; i <= dimension; i++) + { + for (var j = 1; j <= graph.Vertices.Count(); j++) + { + var cell = new TextBox { Text = "0", Location = new Point(j * 60, i * 30), Height = 20, Width = 50 }; + Output.Controls.Add(cell); + } + + } + + floyd = new FloydWarshallAllShortestPathAlgorithm>(graph, x => x.Tag); + + //add labels above cells + var k = 1; + foreach (var v in graph.Vertices) + { + Output.Controls.Add(new Label { Text = v.ToString(), Location = new Point(k * 60, 0), Width = 50 }); + Output.Controls.Add(new Label { Text = v.ToString(), Location = new Point(0, k * 30), Width = 50 }); + k++; + } + + floyd.Compute(); + + currState = -1; + _hasStarted = true; + _hasFinished = false; + + } + + + public void NextStep() + { + + currState++; + var t = 0; + var i = floyd.steps[currState].Source; + var j = floyd.steps[currState].Target; + var dst = floyd.steps[currState].Distance; + var k = floyd.steps[currState].Predecessor; + + var ij = (TextBox)Output.Controls[i * dimension + j]; + ij.Text = dst.ToString(); + ij.BackColor = System.Drawing.Color.LightBlue; + + + + if (k > 0) + { + Random rand = new Random(); + var randomColor = System.Drawing.Color.FromArgb(Colors.AliceBlue.A, rand.Next(255), + rand.Next(255), rand.Next(255)); + + var ik = (TextBox)Output.Controls[i * dimension + k]; + ik.BackColor = randomColor; + + var kj = (TextBox)Output.Controls[k * dimension + j]; + kj.BackColor = randomColor; + } + + + _hasFinished = currState == floyd.steps.Count() - 1; + + + } + + public void PreviousStep() + { + _hasFinished = false; + + + var i = floyd.steps[currState].Source; + var j = floyd.steps[currState].Target; + var dst = floyd.steps[currState].Distance; + var k = floyd.steps[currState].Predecessor; + + var ij = (TextBox)Output.Controls[i * dimension + j]; + + var edgePrevDist = floyd.steps.LastOrDefault(x => (x.Key < currState) && (x.Value.Source == i) && (x.Value.Target == j)).Value.Distance; + ij.Text = edgePrevDist.ToString(); + + if (edgePrevDist == 0) + { + ij.BackColor = System.Drawing.Color.White; + } + + if (k > 0) + { + var ik = (TextBox)Output.Controls[i * dimension + k]; + ik.BackColor = System.Drawing.Color.LightBlue; + + var kj = (TextBox)Output.Controls[k * dimension + j]; + kj.BackColor = System.Drawing.Color.LightBlue; + } + + currState--; + + } + + } +} \ No newline at end of file diff --git a/FloydWarshallShortestPathPlugin/FloydWarshallShortestPathPlugin.csproj b/FloydWarshallShortestPathPlugin/FloydWarshallShortestPathPlugin.csproj new file mode 100644 index 000000000..5bad8b4f3 --- /dev/null +++ b/FloydWarshallShortestPathPlugin/FloydWarshallShortestPathPlugin.csproj @@ -0,0 +1,111 @@ + + + + + + Debug + AnyCPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85} + Library + Properties + ConnectedComponents + ConnectedComponents + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + {8826810a-dc59-46e6-8978-21e273db1236} + DotParser + + + {e383f190-86fe-454c-8568-1762f8820925} + GraphTask.Common + + + {d2e33fee-6689-4bb4-a95c-1b5c327a1e8f} + GraphX.WPF.Controls + + + {3644d44b-dec0-4b65-bba0-c68e34821aae} + GraphX.PCL.Common + + + {a30d218b-aaa4-483a-99f7-eaeb1b8b4610} + GraphX.PCL.Logic + + + {960c14d1-edbd-40e5-8ae6-25e311551b87} + QuickGraph.Data + + + {595d6322-637a-4a36-97f1-d53f3f9ecea7} + QuickGraph.Graphviz + + + {646cfbb0-b998-45e7-8809-991a5538ff36} + QuickGraph.GraphXAdapter + + + {a9a5c115-0680-44b3-a87e-5ecf4c93814e} + QuickGraph + + + + + + + + + ..\packages\Mono.Addins\lib\net40\Mono.Addins.dll + True + True + + + + + \ No newline at end of file diff --git a/FloydWarshallShortestPathPlugin/Properties/AssemblyInfo.cs b/FloydWarshallShortestPathPlugin/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..40aa0458e --- /dev/null +++ b/FloydWarshallShortestPathPlugin/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 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("ConnectedComponents")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ConnectedComponents")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[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("fa87b6f4-3cf2-4ce6-9c0f-1fbc3c04ab85")] + +// 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/FloydWarshallShortestPathPlugin/paket.references b/FloydWarshallShortestPathPlugin/paket.references new file mode 100644 index 000000000..5055be0e4 --- /dev/null +++ b/FloydWarshallShortestPathPlugin/paket.references @@ -0,0 +1,2 @@ +Mono.Addins +Microsoft.Net.Compilers \ No newline at end of file diff --git a/QuickGraph.sln b/QuickGraph.sln index d5bfe9f1c..832c1af1e 100644 --- a/QuickGraph.sln +++ b/QuickGraph.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{FAAD5B1C-1217-48D6-B1EF-7CAC0440D6A4}" ProjectSection(SolutionItems) = preProject @@ -91,7 +91,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginSample", "src\GraphTa EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickGraph.GraphXAdapter", "src\QuickGraph.GraphXAdapter\QuickGraph.GraphXAdapter.csproj", "{646CFBB0-B998-45E7-8809-991A5538FF36}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TopologicalSortPlugin", "src\GraphTask.Plugins\TopologicalSortPlugin\TopologicalSortPlugin.csproj", "{7A3CD47C-DF15-4FC6-A923-DEC16264E79F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AStarPlugin", "src\GraphTask.Plugins\AStarPlugin\AStarPlugin.csproj", "{7A3CD46C-DF15-4FC6-A923-DEC16264E79F}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{0CE1D294-B109-461F-88DC-42AFCA5039E9}" EndProject @@ -123,11 +123,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HungarianAlgorithmVisualisa EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YenVisualisation", "src\YenVisualisation\YenVisualisation.csproj", "{CC103150-DDBF-42D9-9C53-DA5D0915CFD1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectedComponents", "ConnectedComponents\ConnectedComponents.csproj", "{FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FloydWarshallShortestPathPlugin", "FloydWarshallShortestPathPlugin\FloydWarshallShortestPathPlugin.csproj", "{FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyConnectedComponents", "StronglyConnectedComponents\StronglyConnectedComponents.csproj", "{CAC7BC69-08AD-4A6C-8024-813E29D4F954}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DagShortestPathPlugin", "DagShortestPathPlugin\DagShortestPathPlugin.csproj", "{CAC7BC68-08AD-4A6C-8024-813E29D4F954}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WeaklyConnectedComponents", "WeaklyConnectedComponents\WeaklyConnectedComponents.csproj", "{EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BellmanFordShortestPathPlugin", "BellmanFordShortestPathPlugin\BellmanFordShortestPathPlugin.csproj", "{EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -603,26 +603,26 @@ Global {646CFBB0-B998-45E7-8809-991A5538FF36}.ReleaseContractsReferences|Any CPU.Build.0 = Release|Any CPU {646CFBB0-B998-45E7-8809-991A5538FF36}.ReleaseContractsReferences|x86.ActiveCfg = Release|Any CPU {646CFBB0-B998-45E7-8809-991A5538FF36}.ReleaseContractsReferences|x86.Build.0 = Release|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.Debug|x86.ActiveCfg = Debug|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.Debug|x86.Build.0 = Debug|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.DebugContracts|Any CPU.ActiveCfg = Debug|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.DebugContracts|Any CPU.Build.0 = Debug|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.DebugContracts|x86.ActiveCfg = Debug|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.DebugContracts|x86.Build.0 = Debug|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.Release|Any CPU.Build.0 = Release|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.Release|x86.ActiveCfg = Release|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.Release|x86.Build.0 = Release|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.Release20|Any CPU.ActiveCfg = Release|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.Release20|Any CPU.Build.0 = Release|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.Release20|x86.ActiveCfg = Release|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.Release20|x86.Build.0 = Release|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.ReleaseContractsReferences|Any CPU.ActiveCfg = Release|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.ReleaseContractsReferences|Any CPU.Build.0 = Release|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.ReleaseContractsReferences|x86.ActiveCfg = Release|Any CPU - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F}.ReleaseContractsReferences|x86.Build.0 = Release|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.Debug|x86.ActiveCfg = Debug|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.Debug|x86.Build.0 = Debug|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.DebugContracts|Any CPU.ActiveCfg = Debug|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.DebugContracts|Any CPU.Build.0 = Debug|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.DebugContracts|x86.ActiveCfg = Debug|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.DebugContracts|x86.Build.0 = Debug|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.Release|Any CPU.Build.0 = Release|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.Release|x86.ActiveCfg = Release|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.Release|x86.Build.0 = Release|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.Release20|Any CPU.ActiveCfg = Release|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.Release20|Any CPU.Build.0 = Release|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.Release20|x86.ActiveCfg = Release|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.Release20|x86.Build.0 = Release|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.ReleaseContractsReferences|Any CPU.ActiveCfg = Release|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.ReleaseContractsReferences|Any CPU.Build.0 = Release|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.ReleaseContractsReferences|x86.ActiveCfg = Release|Any CPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F}.ReleaseContractsReferences|x86.Build.0 = Release|Any CPU {03BB2368-5892-4378-B397-8826FA3323BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {03BB2368-5892-4378-B397-8826FA3323BB}.Debug|Any CPU.Build.0 = Debug|Any CPU {03BB2368-5892-4378-B397-8826FA3323BB}.Debug|x86.ActiveCfg = Debug|Any CPU @@ -893,66 +893,66 @@ Global {CC103150-DDBF-42D9-9C53-DA5D0915CFD1}.ReleaseContractsReferences|Any CPU.Build.0 = Release|Any CPU {CC103150-DDBF-42D9-9C53-DA5D0915CFD1}.ReleaseContractsReferences|x86.ActiveCfg = Release|Any CPU {CC103150-DDBF-42D9-9C53-DA5D0915CFD1}.ReleaseContractsReferences|x86.Build.0 = Release|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.Debug|x86.ActiveCfg = Debug|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.Debug|x86.Build.0 = Debug|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.DebugContracts|Any CPU.ActiveCfg = Debug|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.DebugContracts|Any CPU.Build.0 = Debug|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.DebugContracts|x86.ActiveCfg = Debug|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.DebugContracts|x86.Build.0 = Debug|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release|Any CPU.Build.0 = Release|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release|x86.ActiveCfg = Release|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release|x86.Build.0 = Release|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release20|Any CPU.ActiveCfg = Release|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release20|Any CPU.Build.0 = Release|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release20|x86.ActiveCfg = Release|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release20|x86.Build.0 = Release|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.ReleaseContractsReferences|Any CPU.ActiveCfg = Release|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.ReleaseContractsReferences|Any CPU.Build.0 = Release|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.ReleaseContractsReferences|x86.ActiveCfg = Release|Any CPU - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85}.ReleaseContractsReferences|x86.Build.0 = Release|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.Debug|x86.ActiveCfg = Debug|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.Debug|x86.Build.0 = Debug|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.DebugContracts|Any CPU.ActiveCfg = Debug|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.DebugContracts|Any CPU.Build.0 = Debug|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.DebugContracts|x86.ActiveCfg = Debug|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.DebugContracts|x86.Build.0 = Debug|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.Release|Any CPU.Build.0 = Release|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.Release|x86.ActiveCfg = Release|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.Release|x86.Build.0 = Release|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.Release20|Any CPU.ActiveCfg = Release|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.Release20|Any CPU.Build.0 = Release|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.Release20|x86.ActiveCfg = Release|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.Release20|x86.Build.0 = Release|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.ReleaseContractsReferences|Any CPU.ActiveCfg = Release|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.ReleaseContractsReferences|Any CPU.Build.0 = Release|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.ReleaseContractsReferences|x86.ActiveCfg = Release|Any CPU - {CAC7BC69-08AD-4A6C-8024-813E29D4F954}.ReleaseContractsReferences|x86.Build.0 = Release|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.Debug|x86.ActiveCfg = Debug|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.Debug|x86.Build.0 = Debug|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.DebugContracts|Any CPU.ActiveCfg = Debug|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.DebugContracts|Any CPU.Build.0 = Debug|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.DebugContracts|x86.ActiveCfg = Debug|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.DebugContracts|x86.Build.0 = Debug|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.Release|Any CPU.Build.0 = Release|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.Release|x86.ActiveCfg = Release|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.Release|x86.Build.0 = Release|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.Release20|Any CPU.ActiveCfg = Release|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.Release20|Any CPU.Build.0 = Release|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.Release20|x86.ActiveCfg = Release|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.Release20|x86.Build.0 = Release|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.ReleaseContractsReferences|Any CPU.ActiveCfg = Release|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.ReleaseContractsReferences|Any CPU.Build.0 = Release|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.ReleaseContractsReferences|x86.ActiveCfg = Release|Any CPU - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5}.ReleaseContractsReferences|x86.Build.0 = Release|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.Debug|x86.ActiveCfg = Debug|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.Debug|x86.Build.0 = Debug|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.DebugContracts|Any CPU.ActiveCfg = Debug|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.DebugContracts|Any CPU.Build.0 = Debug|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.DebugContracts|x86.ActiveCfg = Debug|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.DebugContracts|x86.Build.0 = Debug|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release|Any CPU.Build.0 = Release|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release|x86.ActiveCfg = Release|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release|x86.Build.0 = Release|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release20|Any CPU.ActiveCfg = Release|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release20|Any CPU.Build.0 = Release|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release20|x86.ActiveCfg = Release|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.Release20|x86.Build.0 = Release|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.ReleaseContractsReferences|Any CPU.ActiveCfg = Release|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.ReleaseContractsReferences|Any CPU.Build.0 = Release|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.ReleaseContractsReferences|x86.ActiveCfg = Release|Any CPU + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85}.ReleaseContractsReferences|x86.Build.0 = Release|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.Debug|x86.ActiveCfg = Debug|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.Debug|x86.Build.0 = Debug|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.DebugContracts|Any CPU.ActiveCfg = Debug|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.DebugContracts|Any CPU.Build.0 = Debug|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.DebugContracts|x86.ActiveCfg = Debug|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.DebugContracts|x86.Build.0 = Debug|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.Release|Any CPU.Build.0 = Release|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.Release|x86.ActiveCfg = Release|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.Release|x86.Build.0 = Release|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.Release20|Any CPU.ActiveCfg = Release|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.Release20|Any CPU.Build.0 = Release|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.Release20|x86.ActiveCfg = Release|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.Release20|x86.Build.0 = Release|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.ReleaseContractsReferences|Any CPU.ActiveCfg = Release|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.ReleaseContractsReferences|Any CPU.Build.0 = Release|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.ReleaseContractsReferences|x86.ActiveCfg = Release|Any CPU + {CAC7BC68-08AD-4A6C-8024-813E29D4F954}.ReleaseContractsReferences|x86.Build.0 = Release|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.Debug|x86.ActiveCfg = Debug|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.Debug|x86.Build.0 = Debug|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.DebugContracts|Any CPU.ActiveCfg = Debug|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.DebugContracts|Any CPU.Build.0 = Debug|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.DebugContracts|x86.ActiveCfg = Debug|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.DebugContracts|x86.Build.0 = Debug|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.Release|Any CPU.Build.0 = Release|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.Release|x86.ActiveCfg = Release|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.Release|x86.Build.0 = Release|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.Release20|Any CPU.ActiveCfg = Release|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.Release20|Any CPU.Build.0 = Release|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.Release20|x86.ActiveCfg = Release|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.Release20|x86.Build.0 = Release|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.ReleaseContractsReferences|Any CPU.ActiveCfg = Release|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.ReleaseContractsReferences|Any CPU.Build.0 = Release|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.ReleaseContractsReferences|x86.ActiveCfg = Release|Any CPU + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5}.ReleaseContractsReferences|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -982,7 +982,7 @@ Global {C2F89DE1-B429-4B5D-AF22-3A075D00BAA4} = {278F278F-6F15-4CAE-9665-A068A795A222} {D495C472-6CBB-4B04-A30E-215EE125C08C} = {CBD0EAE9-B336-4359-AC80-E2E0A47FB991} {646CFBB0-B998-45E7-8809-991A5538FF36} = {7A2A3C07-B652-4759-AFC4-49378D764784} - {7A3CD47C-DF15-4FC6-A923-DEC16264E79F} = {CBD0EAE9-B336-4359-AC80-E2E0A47FB991} + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F} = {CBD0EAE9-B336-4359-AC80-E2E0A47FB991} {0CE1D294-B109-461F-88DC-42AFCA5039E9} = {CBD0EAE9-B336-4359-AC80-E2E0A47FB991} {03BB2368-5892-4378-B397-8826FA3323BB} = {0CE1D294-B109-461F-88DC-42AFCA5039E9} {7EBC6156-A93B-48FA-B630-C232E6EA1F8E} = {CBD0EAE9-B336-4359-AC80-E2E0A47FB991} @@ -997,9 +997,9 @@ Global {90B04B29-080C-4132-AD57-E07DE119E3E7} = {CBD0EAE9-B336-4359-AC80-E2E0A47FB991} {E2039A69-CC9D-4DB6-B9D9-3898DBD08AA1} = {CBD0EAE9-B336-4359-AC80-E2E0A47FB991} {CC103150-DDBF-42D9-9C53-DA5D0915CFD1} = {CBD0EAE9-B336-4359-AC80-E2E0A47FB991} - {FA87B6F5-3CF2-4CE6-9C0F-1FBC3C04AB85} = {0CE1D294-B109-461F-88DC-42AFCA5039E9} - {CAC7BC69-08AD-4A6C-8024-813E29D4F954} = {CBD0EAE9-B336-4359-AC80-E2E0A47FB991} - {EFCEB46F-BC83-41D0-8970-FF4ECF897BE5} = {CBD0EAE9-B336-4359-AC80-E2E0A47FB991} + {FA87B6F4-3CF2-4CE6-9C0F-1FBC3C04AB85} = {0CE1D294-B109-461F-88DC-42AFCA5039E9} + {CAC7BC68-08AD-4A6C-8024-813E29D4F954} = {CBD0EAE9-B336-4359-AC80-E2E0A47FB991} + {EFCEB44F-BC83-41D0-8970-FF4ECF897BE5} = {CBD0EAE9-B336-4359-AC80-E2E0A47FB991} EndGlobalSection GlobalSection(TestCaseManagementSettings) = postSolution CategoryFile = QuickGraph1.vsmdi diff --git a/src/GraphTask.MainForm/GraphTask.MainForm.csproj b/src/GraphTask.MainForm/GraphTask.MainForm.csproj index 4706d628a..62f7b5f24 100644 --- a/src/GraphTask.MainForm/GraphTask.MainForm.csproj +++ b/src/GraphTask.MainForm/GraphTask.MainForm.csproj @@ -89,14 +89,6 @@ - - {cac7bc69-08ad-4a6c-8024-813e29d4f954} - StronglyConnectedComponents - - - {efceb46f-bc83-41d0-8970-ff4ecf897be5} - WeaklyConnectedComponents - {e383f190-86fe-454c-8568-1762f8820925} GraphTask.Common diff --git a/src/GraphTask.Plugins/AStarPlugin/AStar.cs b/src/GraphTask.Plugins/AStarPlugin/AStar.cs new file mode 100644 index 000000000..de5a5016c --- /dev/null +++ b/src/GraphTask.Plugins/AStarPlugin/AStar.cs @@ -0,0 +1,192 @@ +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using System.Windows.Forms.Integration; +using System.Windows.Media; +using Common; +using Mono.Addins; +using QuickGraph; +using QuickGraph.GraphXAdapter; +using System; +using System.ComponentModel; +using MessageBox = System.Windows.Forms.MessageBox; +using Point = System.Drawing.Point; + +[assembly: Addin] +[assembly: AddinDependency("GraphTasks", "1.0")] + +namespace AStarShortestPathPlugin +{ + using QuickGraph.Algorithms.ShortestPath; + using Graph = BidirectionalGraph>; + using GraphArea = BidirectionalGraphArea>; + + [Extension] + public class AStarShortestPathPlugin : IAlgorithm + { + private readonly GraphArea _graphArea; + private readonly GraphXZoomControl _zoomControl; + private bool _hasStarted; + private bool _hasFinished; + private readonly TextBox _startVertex; + private Label listBoxName; + private ListBox algOrderListBox; + private BindingList algOrderList; + private List states; + private AStarShortestPathAlgorithm> aStar; + private int currState; + private String distances; + + byte a = 0xFF, r = 0xE3, g = 0xE3, b = 0xE3; + + private class State + { + public State(GraphXVertex v, SolidColorBrush c) + { + this.v = v; + this.c = c; + } + public GraphXVertex v; + public SolidColorBrush c; + } + + + public AStarShortestPathPlugin() + { + _graphArea = new GraphArea(); + _zoomControl = new GraphXZoomControl { Content = _graphArea }; + _startVertex = new TextBox { Location = new Point(220, 20) }; + + Output.Controls.Add(new ElementHost { Dock = DockStyle.Fill, Child = _zoomControl }); + var sLabel = new Label { Location = new Point(225, 0), Text = "Start vertex:" }; + listBoxName = new Label { Text = "Order of chosen vertices:", Location = new Point(10, 0) }; + algOrderListBox = new ListBox { Location = new Point(10, 20), Width = 160, Height = 80 }; + algOrderList = new BindingList(); + algOrderListBox.DataSource = algOrderList; + Options.Controls.AddRange(new Control[] { _startVertex, sLabel, algOrderListBox, listBoxName }); + + } + + public string Name => "A * algorithm Plugin"; + public string Author => "Alisa Meteleva"; + public string Description => "This plugin demonstrates how A* alg works.\n"; + + public Panel Options { get; } = new Panel { Dock = DockStyle.Fill }; + public Panel Output { get; } = new Panel { Dock = DockStyle.Fill }; + + public bool CanGoBack => currState != 0 && states.Count != 0; + public bool CanGoFurther => _hasStarted && !_hasFinished; + + public void Run(string dotSource) + { + + if (_startVertex.Text == "") + { + MessageBox.Show("Please specify start vertix first!\n"); + return; + } + + var vertexFun = VertexFactory.Name; + var edgeFun = EdgeFactory.Weighted(0); + var graph = Graph.LoadDot(dotSource, vertexFun, edgeFun); + var grpah2 = graph.ToArrayAdjacencyGraph(); + var startVertix = graph.Vertices.Single(x => x.ToString() == _startVertex.Text); + states = new List(); + distances = ""; + + + + if (graph.IsVerticesEmpty) + { + MessageBox.Show("Graph is empty."); + return; + } + + aStar = new AStarShortestPathAlgorithm>(graph, e => e.Tag, v => 0); + aStar.DiscoverVertex += OnDiscoverVertex; + aStar.FinishVertex += OnStartVertex; + aStar.Compute(startVertix); + + currState = -1; + + _graphArea.LogicCore.Graph = graph; + _graphArea.GenerateGraph(); + _zoomControl.ZoomToFill(); + + foreach (var e in _graphArea.EdgesList) + { + e.Value.ShowLabel = true; + } + + _hasStarted = true; + _hasFinished = false; + foreach (var v in aStar.VisitedGraph.Vertices) + { + distances += "Shortest distance for vertix" + v.ToString() + " equals " + aStar.Distances[v].ToString() + "\n"; + } + } + + private void HighlightTraversal() + { + var currNode = states[currState].v; + _graphArea.VertexList[currNode].Background = states[currState].c; + } + + public void NextStep() + { + currState++; + _hasFinished = currState == states.Count - 1; + var toadd = states[currState].v.ToString(); + var shortDistance = aStar.Distances[states[currState].v]; + + HighlightTraversal(); + + if (shortDistance == double.MaxValue) + { + toadd += " Unreachable from start vertex "; + _graphArea.VertexList[states[currState].v].Background = new SolidColorBrush(Colors.DarkSlateBlue); + } + else + if (states[currState].c.Color.Equals(Colors.Magenta)) + { + toadd += " shortest path is " + shortDistance; + } + + algOrderList.Insert(currState, toadd); + if (_hasFinished) + { + MessageBox.Show(distances); + _startVertex.Text = ""; + } + + } + + public void PreviousStep() + { + _hasFinished = false; + var currNode = states[currState]; + + if (currNode.c.Color.Equals(Colors.Magenta)) + { + _graphArea.VertexList[currNode.v].Background = new SolidColorBrush(Colors.YellowGreen); + } + else + { + _graphArea.VertexList[currNode.v].Background = new SolidColorBrush(Color.FromArgb(a, r, g, b)); + } + + algOrderList.RemoveAt(currState); + currState--; + } + + private void OnDiscoverVertex(GraphXVertex vertex) + { + states.Add(new State(vertex, new SolidColorBrush(Colors.YellowGreen))); + } + + private void OnStartVertex(GraphXVertex vertex) + { + states.Add(new State(vertex, new SolidColorBrush(Colors.Magenta))); + } + } +} \ No newline at end of file diff --git a/src/GraphTask.Plugins/AStarPlugin/AStarPlugin.csproj b/src/GraphTask.Plugins/AStarPlugin/AStarPlugin.csproj new file mode 100644 index 000000000..5ae2f4d72 --- /dev/null +++ b/src/GraphTask.Plugins/AStarPlugin/AStarPlugin.csproj @@ -0,0 +1,119 @@ + + + + + + Debug + AnyCPU + {7A3CD46C-DF15-4FC6-A923-DEC16264E79F} + Library + Properties + AStarPlugin + AStarPlugin + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + ..\..\..\GraphTaskBin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + ..\..\..\GraphTaskBin\Release\ + TRACE + prompt + 4 + + + + + + + + ..\..\..\packages\Mono.Addins\lib\net40\Mono.Addins.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + {8826810a-dc59-46e6-8978-21e273db1236} + DotParser + + + {e383f190-86fe-454c-8568-1762f8820925} + GraphTask.Common + + + {d2e33fee-6689-4bb4-a95c-1b5c327a1e8f} + GraphX.WPF.Controls + + + {3644d44b-dec0-4b65-bba0-c68e34821aae} + GraphX.PCL.Common + + + {a30d218b-aaa4-483a-99f7-eaeb1b8b4610} + GraphX.PCL.Logic + + + {960c14d1-edbd-40e5-8ae6-25e311551b87} + QuickGraph.Data + + + {595d6322-637a-4a36-97f1-d53f3f9ecea7} + QuickGraph.Graphviz + + + {646cfbb0-b998-45e7-8809-991a5538ff36} + QuickGraph.GraphXAdapter + + + {a9a5c115-0680-44b3-a87e-5ecf4c93814e} + QuickGraph + + + {03bb2368-5892-4378-b397-8826fa3323bb} + PluginsCommon + + + + + \ No newline at end of file diff --git a/src/GraphTask.Plugins/AStarPlugin/App.config b/src/GraphTask.Plugins/AStarPlugin/App.config new file mode 100644 index 000000000..88fa4027b --- /dev/null +++ b/src/GraphTask.Plugins/AStarPlugin/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/GraphTask.Plugins/AStarPlugin/Properties/AssemblyInfo.cs b/src/GraphTask.Plugins/AStarPlugin/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..39aaaed38 --- /dev/null +++ b/src/GraphTask.Plugins/AStarPlugin/Properties/AssemblyInfo.cs @@ -0,0 +1,14 @@ +// +using System.Reflection; + +[assembly: AssemblyTitleAttribute("AStarPlugin")] +[assembly: AssemblyProductAttribute("QuickGraph")] +[assembly: AssemblyDescriptionAttribute("Graph datastructures and algorithms for .NET.")] +[assembly: AssemblyVersionAttribute("0.0.1")] +[assembly: AssemblyFileVersionAttribute("0.0.1")] +namespace System { + internal static class AssemblyVersionInformation { + internal const string Version = "0.0.1"; + internal const string InformationalVersion = "0.0.1"; + } +} diff --git a/src/GraphTask.Plugins/AStarPlugin/packages.config b/src/GraphTask.Plugins/AStarPlugin/packages.config new file mode 100644 index 000000000..ab9c964e9 --- /dev/null +++ b/src/GraphTask.Plugins/AStarPlugin/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/GraphTask.Plugins/AStarPlugin/paket.references b/src/GraphTask.Plugins/AStarPlugin/paket.references new file mode 100644 index 000000000..810b01a6a --- /dev/null +++ b/src/GraphTask.Plugins/AStarPlugin/paket.references @@ -0,0 +1,2 @@ +Microsoft.Net.Compilers +Mono.addins \ No newline at end of file diff --git a/src/QuickGraph/Algorithms/ShortestPath/BellmanFordShortestPathAlgorithm.cs b/src/QuickGraph/Algorithms/ShortestPath/BellmanFordShortestPathAlgorithm.cs index 8e1d6e015..ca5df53ba 100644 --- a/src/QuickGraph/Algorithms/ShortestPath/BellmanFordShortestPathAlgorithm.cs +++ b/src/QuickGraph/Algorithms/ShortestPath/BellmanFordShortestPathAlgorithm.cs @@ -81,7 +81,7 @@ private void OnInitializeVertex(TVertex v) if (eh != null) eh(v); } - + /// /// Invoked on every edge in the graph |V| times. /// @@ -156,6 +156,21 @@ private void OnEdgeNotMinimized(TEdge e) eh(e); } + public event VertexAction StartVertex; + private void OnStartVertex(TVertex v) + { + var eh = this.StartVertex; + if (eh != null) + eh(v); + } + + public event VertexAction FinishVertex; + private void OnFinishVertex(TVertex v) + { + if (FinishVertex != null) + FinishVertex(v); + } + /// /// Constructed predecessor map /// @@ -203,13 +218,12 @@ protected override void InternalCompute() { // getting the number of int N = this.VisitedGraph.VertexCount; - for (int k = 0; k < N; ++k) + foreach(var v in this.VisitedGraph.Vertices) { bool atLeastOneTreeEdge = false; foreach (var e in this.VisitedGraph.Edges) { this.OnExamineEdge(e); - if (Relax(e)) { atLeastOneTreeEdge = true; @@ -240,7 +254,9 @@ protected override void InternalCompute() return; } else + { this.OnEdgeNotMinimized(e); + } } this.foundNegativeCycle = false; } diff --git a/src/QuickGraph/Algorithms/ShortestPath/FloydWarshallAllShortestPathAlgorithm.cs b/src/QuickGraph/Algorithms/ShortestPath/FloydWarshallAllShortestPathAlgorithm.cs index 423f5dd08..fa5a4709d 100644 --- a/src/QuickGraph/Algorithms/ShortestPath/FloydWarshallAllShortestPathAlgorithm.cs +++ b/src/QuickGraph/Algorithms/ShortestPath/FloydWarshallAllShortestPathAlgorithm.cs @@ -20,7 +20,35 @@ public class FloydWarshallAllShortestPathAlgorithm { private readonly Func weights; private readonly IDistanceRelaxer distanceRelaxer; - private readonly Dictionary, VertexData> data; + private readonly Dictionary, VertexData> data; + public readonly Dictionary steps; + private readonly Dictionary matches; + + public struct distancesVertices + { + public readonly double Distance; + public readonly int Source; + public readonly int Target; + public readonly int Predecessor; + + public distancesVertices( int source, int target, double distance) + { + this.Distance = distance; + this.Source = source; + this.Target = target; + this.Predecessor = 0; + } + + public distancesVertices(int source, int target, double distance,int predecessor) + { + this.Distance = distance; + this.Source = source; + this.Target = target; + this.Predecessor = predecessor; + } + + + } struct VertexData { @@ -74,6 +102,7 @@ public override string ToString() } } + public FloydWarshallAllShortestPathAlgorithm( IAlgorithmComponent host, IVertexAndEdgeListGraph visitedGraph, @@ -88,8 +117,10 @@ IDistanceRelaxer distanceRelaxer this.weights = weights; this.distanceRelaxer = distanceRelaxer; this.data = new Dictionary, VertexData>(); + this.steps = new Dictionary(); + this.matches = new Dictionary(); } - + public FloydWarshallAllShortestPathAlgorithm( IVertexAndEdgeListGraph visitedGraph, Func weights, @@ -102,6 +133,9 @@ public FloydWarshallAllShortestPathAlgorithm( this.weights =weights; this.distanceRelaxer = distanceRelaxer; this.data = new Dictionary, VertexData>(); + this.steps = new Dictionary(); + this.matches = new Dictionary(); + } public FloydWarshallAllShortestPathAlgorithm( @@ -194,16 +228,27 @@ public bool TryGetPath( path = edges.ToArray(); return true; } - + private double returnCurrValue(double d) + { + return d; + } protected override void InternalCompute() { var cancelManager = this.Services.CancelManager; // matrix i,j -> path + this.data.Clear(); + this.steps.Clear(); var vertices = this.VisitedGraph.Vertices; var edges = this.VisitedGraph.Edges; - + var step = 0; + var num = 0; + foreach (var v in vertices) + { + matches[v.ToString()] = num; + num++; + } // prepare the matrix with initial costs // walk each edge and add entry in cost dictionary foreach (var edge in edges) @@ -212,16 +257,28 @@ protected override void InternalCompute() var cost = this.weights(edge); VertexData value; if (!data.TryGetValue(ij, out value)) + { + Console.WriteLine(ij.Source.ToString()+ " " + ij.Target.ToString()); data[ij] = new VertexData(cost, edge); + steps[step] = new distancesVertices( matches[ij.Source.ToString()], matches[ij.Target.ToString()], cost); + step++; + + } else if (cost < value.Distance) + { data[ij] = new VertexData(cost, edge); + steps[step] = new distancesVertices(matches[ij.Source.ToString()], matches[ij.Target.ToString()], cost); + step++; + } } if (cancelManager.IsCancelling) return; // walk each vertices and make sure cost self-cost 0 foreach (var v in vertices) + { data[new SEquatableEdge(v, v)] = new VertexData(0, default(TEdge)); + } if (cancelManager.IsCancelling) return; // iterate k, i, j @@ -238,6 +295,7 @@ protected override void InternalCompute() var kj = new SEquatableEdge(vk, vj); VertexData pathkj; + if (data.TryGetValue(kj, out pathkj)) { double combined = this.distanceRelaxer.Combine(pathik.Distance, pathkj.Distance); @@ -246,10 +304,21 @@ protected override void InternalCompute() if (data.TryGetValue(ij, out pathij)) { if (this.distanceRelaxer.Compare(combined, pathij.Distance) < 0) + { data[ij] = new VertexData(combined, vk); + steps[step] = new distancesVertices(matches[ij.Source.ToString()], matches[ij.Target.ToString()], combined, matches[vk.ToString()]); + step++; + + } + } else + { data[ij] = new VertexData(combined, vk); + steps[step] = new distancesVertices(matches[ij.Source.ToString()], matches[ij.Target.ToString()], combined, matches[vk.ToString()]); + step++; + + } } } } @@ -275,6 +344,8 @@ public void Dump(TextWriter writer) kv.Key.Source, kv.Key.Target, kv.Value.ToString()); + } + } }