Skip to content
Snippets Groups Projects
Commit 38806453 authored by Timon Römer's avatar Timon Römer
Browse files

Fixes Sorting for DFS

parent ac4df9fb
No related branches found
No related tags found
No related merge requests found
...@@ -2,10 +2,12 @@ ...@@ -2,10 +2,12 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArrowheads_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Ff33d684d28eda96ce8ff511fd89719957527f5a249bf0c427bba5f237d27d_003FArrowheads_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArrowheads_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Ff33d684d28eda96ce8ff511fd89719957527f5a249bf0c427bba5f237d27d_003FArrowheads_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABidirectionalGraph_002Ecs_002Fl_003AC_0021_003FUsers_003Fmp455017_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fa8e81c4118651b5932b855cf99986877c2c24685d864158c9053e4f62e213fce_003FBidirectionalGraph_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABidirectionalGraph_002Ecs_002Fl_003AC_0021_003FUsers_003Fmp455017_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fa8e81c4118651b5932b855cf99986877c2c24685d864158c9053e4f62e213fce_003FBidirectionalGraph_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEdge_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fc6dec8134d4e5115e30fcbbde23a657edc52dc4585c5673fe87fae89530f2_003FEdge_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEdge_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fc6dec8134d4e5115e30fcbbde23a657edc52dc4585c5673fe87fae89530f2_003FEdge_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEdge_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003Fmp455017_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Ff38111ee4ab22cf4c871f13fa7e04fc14b977348d8eae2e69713c39d27b66_003FEdge_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGeometryGraph_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fec51c2d7ba4c960a9dae3716ddab555d654bcbe75d697cc141c3b2c8f247f_003FGeometryGraph_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGeometryGraph_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fec51c2d7ba4c960a9dae3716ddab555d654bcbe75d697cc141c3b2c8f247f_003FGeometryGraph_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIDictionary_00602_002Ecs_002Fl_003AC_0021_003FUsers_003Fmp455017_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb756d57b94fb4ab9aa95a9b2a97fce1fa24ea0_003Fa1_003F8276683c_003FIDictionary_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIDictionary_00602_002Ecs_002Fl_003AC_0021_003FUsers_003Fmp455017_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb756d57b94fb4ab9aa95a9b2a97fce1fa24ea0_003Fa1_003F8276683c_003FIDictionary_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ALayoutHelpers_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fd0dd8419a9cbd7bcef7ea0c031796cd8197cb3c658c80b7c71ec2da3918b3_003FLayoutHelpers_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ALayoutHelpers_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fd0dd8419a9cbd7bcef7ea0c031796cd8197cb3c658c80b7c71ec2da3918b3_003FLayoutHelpers_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F362e998b40631a36346249d25c3c8c712372e68c65f251adc18f8931b4a77a32_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F362e998b40631a36346249d25c3c8c712372e68c65f251adc18f8931b4a77a32_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F50b63217dc36f9d6edcabbd75adb3a7f68f1ebd3b4645b30614b43a9eda189_003FNode_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F50b63217dc36f9d6edcabbd75adb3a7f68f1ebd3b4645b30614b43a9eda189_003FNode_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASplineRouter_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fb2961a4f945481bf9a55f7d27e451184c68497a74672874e415414929e5d53a_003FSplineRouter_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASplineRouter_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fb2961a4f945481bf9a55f7d27e451184c68497a74672874e415414929e5d53a_003FSplineRouter_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASugiyamaLayoutSettings_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fe49262ac60bbccd8c34311e852def374298e4cf859347b2c83e6a6079f4e7e_003FSugiyamaLayoutSettings_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASugiyamaLayoutSettings_002Ecs_002Fl_003AC_0021_003FUsers_003Ftimon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fe49262ac60bbccd8c34311e852def374298e4cf859347b2c83e6a6079f4e7e_003FSugiyamaLayoutSettings_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
\ No newline at end of file <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASugiyamaLayoutSettings_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003Fmp455017_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fe49262ac60bbccd8c34311e852def374298e4cf859347b2c83e6a6079f4e7e_003FSugiyamaLayoutSettings_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
\ No newline at end of file
...@@ -43,11 +43,7 @@ public class FordFulkersonAlgorithm ...@@ -43,11 +43,7 @@ public class FordFulkersonAlgorithm
// execute as long as there is an augmenting path // execute as long as there is an augmenting path
while (FindAugmentingPath(source, target, pathFlow, strategy)) while (FindAugmentingPath(source, target, pathFlow, strategy))
{ {
Console.WriteLine("Augmenting Path found:"); PrintOrderedPath(pathFlow);
foreach (var edge in pathFlow.Keys)
{
Console.WriteLine($"{edge.Source.Id} -> {edge.Target.Id}, Residual Capacity: {pathFlow[edge]}");
}
// calculate bottleneck in augmenting path // calculate bottleneck in augmenting path
double pathMinFlow = double.MaxValue; double pathMinFlow = double.MaxValue;
...@@ -126,9 +122,18 @@ public class FordFulkersonAlgorithm ...@@ -126,9 +122,18 @@ public class FordFulkersonAlgorithm
{ {
var current = strategy == SearchStrategy.BreadthFirstSearch ? ((Queue<FlowNode>)nodesToVisit).Dequeue() : ((Stack<FlowNode>)nodesToVisit).Pop(); var current = strategy == SearchStrategy.BreadthFirstSearch ? ((Queue<FlowNode>)nodesToVisit).Dequeue() : ((Stack<FlowNode>)nodesToVisit).Pop();
Console.WriteLine("Current: " + current);
var outEdges = _flowGraph.Graph.OutEdges(current).ToList(); var outEdges = _flowGraph.Graph.OutEdges(current).ToList();
var sortedOutEdges = outEdges.OrderBy(edge => edge.Target.Id); List<FlowEdge> sortedOutEdges;
if (strategy == SearchStrategy.BreadthFirstSearch)
{
sortedOutEdges = outEdges.OrderBy(edge => int.Parse(edge.Target.Id)).ToList();
}
else
{
sortedOutEdges = outEdges.OrderByDescending(edge => int.Parse(edge.Target.Id)).ToList();
}
// go through all outgoing edges // go through all outgoing edges
foreach (FlowEdge currentEdge in sortedOutEdges) foreach (FlowEdge currentEdge in sortedOutEdges)
...@@ -172,4 +177,30 @@ public class FordFulkersonAlgorithm ...@@ -172,4 +177,30 @@ public class FordFulkersonAlgorithm
currentNode = pathEdge.Source; currentNode = pathEdge.Source;
} }
} }
public static void PrintOrderedPath(Dictionary<FlowEdge, double> pathFlow)
{
Console.WriteLine("Augmenting Path found:");
// Step 1: Find the starting edge
FlowEdge startEdge = pathFlow.Keys
.First(edge => !pathFlow.Keys.Any(e => e.Target.Id == edge.Source.Id));
// Step 2: Follow the path from start to end
List<FlowEdge> orderedPath = new List<FlowEdge> { startEdge };
while (true)
{
var currentEdge = orderedPath.Last();
var nextEdge = pathFlow.Keys.FirstOrDefault(edge => edge.Source.Id == currentEdge.Target.Id);
if (nextEdge == null) break; // End of path reached
orderedPath.Add(nextEdge);
}
// Step 3: Output the ordered path
foreach (var edge in orderedPath)
{
Console.WriteLine($"{edge.Source.Id} -> {edge.Target.Id}, Residual Capacity: {pathFlow[edge]}");
}
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment