You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Chapters/Chapter1/chapter1.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
Graphs are everywhere and there is well-known algorithms to get the best out of them.
4
4
In this booklet the most common graph algorithms will be explained along with some case studies where these algorithms can be applied. These algorithms are available in the _Pharo AI__graph-algorithms_ library available at: [https://github.com/pharo-ai/graph-algorithms](https://github.com/pharo-ai/graph-algorithms).
5
5
6
-
This booklet will describe and implement thess algorithms.
6
+
This booklet will describe and implement these algorithms.
Copy file name to clipboardExpand all lines: Chapters/Chapter10/chapter10.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
## Maximum Flow
2
2
3
+
@cha:maxflow
4
+
3
5
The Maximum Flow problem is about finding the maximum flow through a directed graph, from one node in the graph to another.
4
6
5
7
The problem can be used to model a wide variety of real-world situations, such as transportation systems, communication networks, and resource allocation.
Copy file name to clipboardExpand all lines: Chapters/Chapter9/chapter9.md
+19-2Lines changed: 19 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,8 +25,8 @@ Similarly, a **minimum-weight** matching has the smallest sum of weights.
25
25
26
26
### A greedy algorithm for matching
27
27
28
-
The algorithm for graph matching implemented in this library is a simple greedy algorithm with time complexity of $O(E * log(V))$.
29
-
The class ```AIGraphMatchingAlgorithm``` can be instantiated to find an **approximation** either of the maximum-weight, the minimum-weight or the maximum-cardinality matching.
28
+
There is a simple greedy algorithm for graph matching implemented in this library.
29
+
The class ```AIGraphMatchingAlgorithm``` can be instantiated to find an **approximation** either of the maximum-weight, the minimum-weight or the maximum-cardinality matching with time complexity of $O(E * log(V))$.
30
30
31
31
For instance, the pseudocode to greedily find a matching of large weight is the following one:
32
32
@@ -53,6 +53,22 @@ To see that the result is not always optimal, consider the two matching versions
53
53
54
54
The greedy algorithm for maximum-weight would first take weight $1+ \epsilon$ and then stop (top matching in Figure *@epsilon@*), missing the optimal weight sum $1+1$ (bottom matching in Figure *@epsilon@*) .
55
55
56
+
### Hopcroft-Karp algorithm
57
+
58
+
The Hopcroft-Karp algorithm computes a matching of maximum-cardinality in an unweighted **bipartite** graph that may contain cycles. The algorithm runs in $O(E * \sqrt{V})$ time.
59
+
60
+
The Hopcroft-Karp algorithm uses the concept of augmenting paths and a level graph to improve the efficiency of finding the maximum matching. It alternates between two main steps:
61
+
62
+
1. BFS (Breadth-First Search): This step constructs a level graph and finds the shortest augmenting paths from unmatched vertices in one set of the bipartite graph to unmatched vertices in the other set.
63
+
64
+
2. DFS (Depth-First Search): This step finds augmenting paths that alternate between unmatched and matched edges, starting from an unmatched vertex in the first set. Once an augmenting path is found, the matching is updated.
65
+
66
+
These steps are repeated until no more augmenting paths can be found, at which point the algorithm terminates with the maximum matching.
67
+
68
+
`AIHopcroftKarp>>run` answers the matching cardinality. `AIHopcroftKarp>>matchingEdgeTuples` answers the concrete matching edges (as tuples) after the run.
69
+
70
+
The Hopcroft-Karp algorithm is basically a special *optimization* of Dinic's algorithm for bipartite unweighted graphs. You find the description of Dinic's algorithm including the augmenting path and level graph concepts in Chapter *@cha:maxflow@*.
71
+
56
72
### Stable matchings
57
73
58
74
Maximality and minimality are not the only interesting optimal matching problems.
@@ -92,3 +108,4 @@ Depending on the context, approximation algorithms may be a suitable alternative
92
108
From the practical and theoretical points of view, envisaging the special case of bipartite graphs is very common and fructiferous, notably for matching problems.
93
109
94
110
Both the greedy and the stable matching algorithm presented here are further examples of using a working list until emptied, like discussed for the topological sorting in this book.
0 commit comments