diff docs/algorithm-ford-fulkerson.pseudocode @ 107:1c1985532139

A couple of real pseudocode examples. Examples are from the Wikipedia.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 04 May 2026 16:57:17 +0200
parents
children 6cebd3e7bc97
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/algorithm-ford-fulkerson.pseudocode	Mon May 04 16:57:17 2026 +0200
@@ -0,0 +1,19 @@
+// -*- coding: utf-8; indent-tabs-mode: nil -*-
+\ALGORITHM{Ford–Fulkerson} \WITH
+  \INPUTS{Given a network \expr{G = (V, E)} with flow capacity \expr{c}, a source node \expr{s}, and a sink node \expr{t}}
+  \OUTPUT{Compute a flow \expr{f} from \expr{s} to \expr{t} of maximum value}
+\IS
+  \TEXT{1. \expr{f(u, v) <- 0} for all edges \expr{(u, v)}
+
+  2. While there is a path \expr{p} from \expr{s} to \expr{t} in \expr{G_f},
+     such that \expr{c_f(u, v) > 0} for all edges \expr{(u, v) ∈ p}:
+
+     1. Find \expr{c_f(p) = min{c_f(u, v): (u, v) ∈ p\}}
+
+     2. For each edge \expr{(u, v) ∈ p}
+
+        1. \expr{f(u, v) <- f(u, v) + c_f(p)}   \expr{\rem Send flow along the path
+
+}	2. \expr{f(v, u) <- f(v, u) - c_f(p)}   \expr{\rem The flow might be "returned" later
+}}
+\END ALGORITHM {Ford–Fulkerson}