|
288 | 288 | "\n",
|
289 | 289 | "#### Complete bipartite graph\n",
|
290 | 290 | "The algorithm can equivalently be described by formulating the problem using a complete bipartite graph. We recall that a bipartite graph, or a biclique is a special kind of bipartite graph where every vertex of the first set is connected to every vertex of the second set. More formally, a complete bipartite graph is a graph whose vertices can be partitioned into two subsets $V_1$ and $V_2$ such that no edge has both endpoints in the same subset, and every possible edge that could connect vertices in different subsets is part of the graph. That is, it is a bipartite graph $(V_1, V_2, E)$ such that for every pair of vertices $v_1 \\in V_1$ and $v_2 \\in V_2,ドル $v_1 v_2$ is an edge in $E$. A complete bipartite graph with partitions of size $\\|V1\\| = m$ and $\\|V2\\| = n,ドル is denoted $K_{m,n}$ every two graphs with the same notation are isomorphic.\n",
|
| 291 | + "##### Illustration\n", |
| 292 | + "Here is an illustration of a complete bipartite graph with m = 5 and n = 3\n", |
| 293 | + "\n", |
291 | 294 | "\n",
|
292 | 295 | "#### Perfect matching\n",
|
293 | 296 | "In graph theory, a perfect matching in a graph is a matching that covers every vertex of the graph. More formally, given a graph $G = (V, E),ドル a perfect matching in $G$ is a subset $M$ of edge set $E,ドル such that every vertex in the vertex set $V$ is adjacent to exactly one edge in $M$.\n",
|
294 | 297 | "\n",
|
295 | | - "### Example\n", |
296 | | - "https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linear_sum_assignment.html" |
| 298 | + "### Numerical example\n", |
| 299 | + "The next example comes from [scipy documentation](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linear_sum_assignment.html)" |
| 300 | + ] |
| 301 | + }, |
| 302 | + { |
| 303 | + "cell_type": "code", |
| 304 | + "execution_count": 10, |
| 305 | + "metadata": {}, |
| 306 | + "outputs": [ |
| 307 | + { |
| 308 | + "name": "stdout", |
| 309 | + "output_type": "stream", |
| 310 | + "text": [ |
| 311 | + "[1 0 2]\n", |
| 312 | + "5\n" |
| 313 | + ] |
| 314 | + } |
| 315 | + ], |
| 316 | + "source": [ |
| 317 | + "import numpy as np\n", |
| 318 | + "cost = np.array([[4, 1, 3], [2, 0, 5], [3, 2, 2]])\n", |
| 319 | + "from scipy.optimize import linear_sum_assignment\n", |
| 320 | + "row_ind, col_ind = linear_sum_assignment(cost)\n", |
| 321 | + "print(col_ind)\n", |
| 322 | + "print(cost[row_ind, col_ind].sum())" |
297 | 323 | ]
|
298 | 324 | },
|
299 | 325 | {
|
|
0 commit comments