@@ -291,7 +291,7 @@ gap> EdgeWeightedDigraphShortestPath(d, 1, 3);
291291[ [ 1, 2, 3 ], [ 1, 1 ] ]
292292
293293#############################################################################
294- # 5. Maximum Flow
294+ # 5. Maximum Flow and Minimum Cut
295295#############################################################################
296296
297297# Maximum flow: empty digraphs
@@ -368,6 +368,110 @@ gap> gr := EdgeWeightedDigraph([[2], [3, 6], [4], [1, 6], [1, 3], []],
368368gap> DigraphMaximumFlow(gr, 5, 6);
369369[ [ 10 ], [ 3, 7 ], [ 7 ], [ 0, 7 ], [ 10, 4 ], [ ] ]
370370
371+ # Minimum cut: empty digraphs
372+ gap> d := EdgeWeightedDigraph([], []);
373+ <immutable empty edge-weighted digraph with 0 vertices>
374+ gap> DigraphMinimumCut(d, 1, 1);
375+ Error, <s> must be a vertex of <D>,
376+
377+ # Minimum cut: single vertex (also empty digraphs)
378+ gap> d := EdgeWeightedDigraph([[]], [[]]);
379+ <immutable empty edge-weighted digraph with 1 vertex>
380+ gap> DigraphMinimumCut(d, 1, 1);
381+ Error, <s> and <t> must be distinct
382+
383+ # Minimum cut: source = dest
384+ gap> d := EdgeWeightedDigraph([[2], []], [[5], []]);
385+ <immutable edge-weighted digraph with 2 vertices, 1 edge>
386+ gap> DigraphMinimumCut(d, 1, 1);
387+ Error, <s> and <t> must be distinct
388+
389+ # Minimum cut: has loop
390+ gap> d := EdgeWeightedDigraph([[1, 2], []], [[5, 10], []]);
391+ <immutable edge-weighted digraph with 2 vertices, 2 edges>
392+ gap> DigraphMinimumCut(d, 1, 2);
393+ [ [ 1 ], [ 2 ] ]
394+
395+ # Minimum cut: invalid source
396+ gap> d := EdgeWeightedDigraph([[1, 2], []], [[5, 10], []]);
397+ <immutable edge-weighted digraph with 2 vertices, 2 edges>
398+ gap> DigraphMinimumCut(d, 5, 2);
399+ Error, <s> must be a vertex of <D>,
400+
401+ # Minimum cut: invalid sink
402+ gap> d := EdgeWeightedDigraph([[1, 2], []], [[5, 10], []]);
403+ <immutable edge-weighted digraph with 2 vertices, 2 edges>
404+ gap> DigraphMinimumCut(d, 1, 5);
405+ Error, <t> must be a vertex of <D>,
406+
407+ # Minimum cut: sink not reachable
408+ gap> d := EdgeWeightedDigraph([[1], []], [[5], []]);
409+ <immutable edge-weighted digraph with 2 vertices, 1 edge>
410+ gap> DigraphMinimumCut(d, 1, 2);
411+ [ [ 1 ], [ 2 ] ]
412+
413+ # Minimum cut: source has in neighbours
414+ gap> d := EdgeWeightedDigraph([[2], [3], []], [[5], [10], []]);
415+ <immutable edge-weighted digraph with 3 vertices, 2 edges>
416+ gap> DigraphMinimumCut(d, 2, 3);
417+ [ [ 2 ], [ 1, 3 ] ]
418+
419+ # Minimum cut: sink has out-neighbours
420+ gap> d := EdgeWeightedDigraph([[2], [3], [2]], [[5], [10], [7]]);
421+ <immutable edge-weighted digraph with 3 vertices, 3 edges>
422+ gap> DigraphMinimumCut(d, 2, 3);
423+ [ [ 2 ], [ 1, 3 ] ]
424+
425+ # Minimum cut: cycle
426+ gap> d := EdgeWeightedDigraph([[2], [3], [1]], [[5], [10], [7]]);
427+ <immutable edge-weighted digraph with 3 vertices, 3 edges>
428+ gap> DigraphMinimumCut(d, 1, 3);
429+ [ [ 1 ], [ 2, 3 ] ]
430+
431+ # Minimum cut: example from Wikipedia
432+ gap> gr := EdgeWeightedDigraph([[3, 4], [], [2, 4], [2]],
433+ > [[10, 5], [], [5, 15], [10]]);;
434+ gap> DigraphMinimumCut(gr, 1, 2);
435+ [ [ 1 ], [ 2, 3, 4 ] ]
436+ gap> DigraphMinimumCut(gr, 3, 2);
437+ [ [ 3, 4 ], [ 1, 2 ] ]
438+
439+ # Minimum cut: example from Wikipedia article on Push-label maximum flow
440+ gap> gr := EdgeWeightedDigraph([[2], [3, 6], [4], [1, 6], [1, 3], []],
441+ > [[12], [3, 7], [10], [5, 10], [15, 4], []]);;
442+ gap> DigraphMinimumCut(gr, 5, 6);
443+ [ [ 5, 1, 2 ], [ 3, 4, 6 ] ]
444+
445+ # Minimum cut set: empty digraphs
446+ gap> d := EdgeWeightedDigraph([], []);
447+ <immutable empty edge-weighted digraph with 0 vertices>
448+ gap> DigraphMinimumCutSet(d, 1, 1);
449+ Error, <s> must be a vertex of <D>,
450+
451+ # Minimum cut set: source has in neighbours
452+ gap> d := EdgeWeightedDigraph([[2], [3], []], [[5], [10], []]);
453+ <immutable edge-weighted digraph with 3 vertices, 2 edges>
454+ gap> DigraphMinimumCutSet(d, 2, 3);
455+ [ [ 2, 3 ] ]
456+
457+ # Minimum cut set: cycle
458+ gap> d := EdgeWeightedDigraph([[2], [3], [1]], [[5], [10], [7]]);
459+ <immutable edge-weighted digraph with 3 vertices, 3 edges>
460+ gap> DigraphMinimumCutSet(d, 1, 3);
461+ [ [ 1, 2 ] ]
462+
463+ # Minimum cut set: invalid sink
464+ gap> d := EdgeWeightedDigraph([[1, 2], []], [[5, 10], []]);
465+ <immutable edge-weighted digraph with 2 vertices, 2 edges>
466+ gap> DigraphMinimumCutSet(d, 1, 5);
467+ Error, <t> must be a vertex of <D>,
468+
469+ # Minimum cut set: source = dest
470+ gap> d := EdgeWeightedDigraph([[2], []], [[5], []]);
471+ <immutable edge-weighted digraph with 2 vertices, 1 edge>
472+ gap> DigraphMinimumCutSet(d, 1, 1);
473+ Error, <s> and <t> must be distinct
474+
371475#############################################################################
372476# 6. Random edge-weighted digraphs
373477#############################################################################
0 commit comments