Maximum two-point map matching (Hungarian algorithm)

xiaoxiao2021-03-31  218

The nearest team is popular, can't fall, huh, I also see. The two-point graph refers to a picture: all of its vertices are divided into two sets M and N, where the two of the two in M ​​or N are not connected in the same episode. The two-point map matching is a set of edges, where the vertices are in two collections, and the two are not the same vertices, which are called the matching of the two-point map, and the maximum side that can be obtained Number, called maximum match.

Calculate the algorithm of the two-point graphs There is a network stream algorithm and Hungarian algorithm (now you know these two), where the Hungarian algorithm is smart, the specific process is as follows (transfer from combined mathematics):

Let G = (x, *, y) is a two-point diagram, where x = {x1, x2 ...}, y = {Y1, Y2, ....}. Let M make any match in G. 1. All the X of all the vertices associated with the edge of the M sides are ¥, and all the vertices are not scanned. Go to 2. 2. If there is no new tag to X-based vertices on the previous step, stop, otherwise, turn 3 3. When there is an X tag but not scanned, select a vertex that is marked but not scanned, such as XI, with (Xi) tag Y, these vertices are not mdrawal, and the side that has not been marked. Connect to xi. Now the vertex xi is scanned. If there is no vertex that is marked but not scanned, turn 4. 4. If there is no new tag in step 3, stop, otherwise it will turn 5. 5. When the y is labeled but not scanned. A vertex that is marked but not scanned, such as YJ, with (YJ) tag X, which is bound to YJ. Now, the vertex yj is scanned. If there is no vertex that is marked but not scanned, turn 2. Since each vertex is mostly marked once and because each vertex is scanned up to once, this matching algorithm terminates within a limited step.

Code:

BFS process:

#include #include main () {bool map [100] [300]; INT I, I1, I2, Num, Num1, Que [300], Cou, STU, MATCH1 [100 ], Match2 [300], PQUE, P1, NOW, PREV [300], N; Scanf ("% D", & n); for (i = 0; i = 0) {match1 [match2 [prev [now]] = now; match2 [now] = match2 [prev [now]]; now = prev [now];} match2 [now] = i1; Match1 [i1] = now; Num ;} if (num == cou) Printf ("yes / n"); Else Printf ("no / n");}} DFS implementation process:

#include #include #define max 100

Bool Map [MAX] [MAX], Searched [MAX]; int Prev [MAX], M, N;

BOOL DFS (INT DATA) {INT I, TEMP; for (i = 0; I

转载请注明原文地址:https://www.9cbs.com/read-130987.html

New Post(0)