Skip to content

Commit

Permalink
Filter paths with less than 0.1 Circles
Browse files Browse the repository at this point in the history
  • Loading branch information
jaensen committed Oct 24, 2024
1 parent 73fb36e commit d8614bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 14 additions & 1 deletion Circles.Pathfinder/Graphs/FlowGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,14 @@ public void AddCapacityEdge(CapacityGraph capacityGraph, CapacityEdge capacityEd
}
}

public List<List<FlowEdge>> ExtractPathsWithFlow(string sourceNode, string sinkNode)
/// <summary>
/// Searches the graph for liquid paths from the source node to the sink node.
/// </summary>
/// <param name="sourceNode">The source</param>
/// <param name="sinkNode">The sink</param>
/// <param name="threshold">Only consider edges with more or equal flow</param>
/// <returns>A list of paths with flow</returns>
public List<List<FlowEdge>> ExtractPathsWithFlow(string sourceNode, string sinkNode, BigInteger threshold)
{
var resultPaths = new List<List<FlowEdge>>();
var visited = new HashSet<string>();
Expand All @@ -209,6 +216,12 @@ void Dfs(string currentNode, List<FlowEdge> currentPath)
if (edge.Flow > 0 && !visited.Contains(edge.To))
{
currentPath.Add(edge); // Add edge to the current path
if (edge.Flow < threshold)
{
// Filter edges with less flow than the threshold
continue;
}

Dfs(edge.To, currentPath); // Recursively go deeper
currentPath.Remove(edge); // Backtrack
}
Expand Down
4 changes: 3 additions & 1 deletion Circles.Pathfinder/V2Pathfinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public async Task<MaxFlowResponse> ComputeMaxFlow(FlowRequest request)
var maxFlow = flowGraph.ComputeMaxFlowWithPaths(request.Source, request.Sink, targetFlow);

// Extract Paths with Flow
var pathsWithFlow = flowGraph.ExtractPathsWithFlow(request.Source, request.Sink);
// (Don't consider paths smaller than 0.1 Circles)
var pathsWithFlow =
flowGraph.ExtractPathsWithFlow(request.Source, request.Sink, BigInteger.Parse("100000000000000000"));

// Collapse balance nodes to get a collapsed graph
var collapsedGraph = CollapseBalanceNodes(pathsWithFlow);
Expand Down

0 comments on commit d8614bc

Please sign in to comment.