A Go library for solving maximum flow problems in directed networks using Dinic's algorithm.
go get github.com/oursimon/flowmopackage main
import (
"fmt"
"github.com/oursimon/flowmo"
)
func main() {
// Create a new flow network
f := flowmo.New()
// Add directed edges with capacities
f.AddEdge("source", "a", 10)
f.AddEdge("source", "b", 5)
f.AddEdge("a", "sink", 7)
f.AddEdge("b", "sink", 8)
f.AddEdge("a", "b", 3)
// Compute maximum flow
maxFlow, err := f.MaxFlow("source", "sink")
if err != nil {
panic(err)
}
fmt.Printf("Maximum flow: %d\n", maxFlow)
// Query node flow
flow, _ := f.FlowByNode("a")
fmt.Printf("Outgoing flow from a: %d\n", flow)
}Creates a new flow network instance.
Adds a directed edge from from to to with the specified capacity. Nodes are created automatically if they don't exist.
Computes the maximum flow from the source node to the sink node using Dinic's algorithm.
Returns the total outgoing flow (used capacity) from the specified node. This method should be called after MaxFlow has been computed.
This project is licensed under the MIT License. See the LICENSE file for details.