プリンキピア

第12章グラフ理論

The Nearest Neighbor Method最近傍法

When the brute force method is impractical for solving a traveling salesperson problem, an alternative is a greedy algorithm known as the nearest neighbor method, which always visit the closest or least costly place first. This method finds a Hamilton cycle of relatively low weight in a complete graph in which, at each phase, the next vertex is chosen by comparing the edges between the current vertex and the remaining vertices to find the lowest weight. Since the nearest neighbor method is a greedy algorithm, it usually doesn’t give the best solution, but it usually gives a solution that is "good enough." Most importantly, the number of steps will be the number of vertices. That’s right! A problem with 10 vertices requires 10 steps, not 362,880. Let’s look at an example to see how it works.
英語のヒント
総当たり法が巡回セールスパーソン問題を解くのに実用的でないとき、代わりになるのが最近傍法として知られる貪欲アルゴリズムである。これはつねにいちばん近いかいちばん費用の少ない場所を先に訪れる。この方法は、完全グラフで重みが比較的小さいハミルトン閉路を見つける。各段階で、今の頂点と残りの頂点のあいだの辺を比べて重みがいちばん小さいものを見つけ、次の頂点を選ぶ。最近傍法は貪欲アルゴリズムなので、ふつう最良の解は与えないが、ふつう「十分に良い」解を与える。もっとも重要なのは、手順の数が頂点の数になることである。そのとおり!頂点が10個の問題に必要な手順は10で、362,880ではない。例を見てどのように働くかを確かめよう。
Suppose that a candidate for governor wants to hold rallies around the state. They plan to leave their home in city A, visit cities B, C, D, E, and F each once, and return home. The airfare between cities is indicated in the graph in Figure 12.196.
英語のヒント
知事の候補者が州のあちこちで集会を開きたいとする。候補者は都市Aの自宅を出発し、都市B、C、D、E、Fを1回ずつ訪れ、家に戻る計画である。都市のあいだの航空運賃を図12.196のグラフに示す。
A graph represents the airfares between six different cities. The graph has 6 vertices. The vertices are A, B, C, D, E, and F. Edges from A leading to B, C, D, E, and F are labeled 250 dollars, 210 dollars, 300 dollars, 200 dollars, and 100 dollars. Edges from B leading to C, D, E, and F are labeled 220 dollars, 120 dollars, 160 dollars, and 170 dollars. Edges from C to D, E, and F are labeled 310 dollars, 180 dollars, and 330 dollars. Edges from D to E and F 270 dollars and 150 dollars. An edge from E to F is labeled 350 dollars.
Figure 12.196図12.196
Airfares between Cities A, B, C, D, E, and F
英語のヒント
都市A、B、C、D、E、Fのあいだの航空運賃
Let’s help the candidate keep costs of travel down by applying the nearest neighbor method to find a Hamilton cycle that has a reasonably low weight. Begin by marking starting vertex as V1 for "visited 1st." Then to compare the weights of the edges between A and vertices adjacent to A: $250, $210, $300, $200, and $100 as shown in Figure 12.197. The lowest of these is $100, which is the edge between A and F.
英語のヒント
最近傍法を当てはめて重みがそれなりに小さいハミルトン閉路を見つけ、候補者が旅費を抑えるのを手伝おう。まず、出発の頂点に「1番目に訪問」の意味でV1と印をつける。次に、図12.197に示すように、Aとそれに隣接する頂点のあいだの辺の重み$250、$210、$300、$200、$100を比べる。いちばん小さいのは$100で、AとFのあいだの辺である。
A graph represents the airfares between six different cities. The graph has 6 vertices. The vertices are A, B, C, D, E, and F. Edges from A leading to B, C, D, E, and F are labeled 250 dollars, 210 dollars, 300 dollars, 200 dollars, and 100 dollars. Edges from B leading to C, D, E, and F are labeled 220 dollars, 120 dollars, 160 dollars, and 170 dollars. Edges from C to D, E, and F are labeled 310 dollars, 180 dollars, and 330 dollars. Edges from D to E and F 270 dollars and 150 dollars. An edge from E to F is labeled 350 dollars. The edges from A are in dashed lines. A is labeled V 1.
Figure 12.197図12.197
Finding the Second Vertex
英語のヒント
2番目の頂点を見つける
Mark F as V2 for "visited 2nd" then compare the weights of the edges between F and the remaining vertices adjacent to F: $170, $330, $150 and $350 as shown in Figure 12.198. The lowest of these is $150, which is the edge between F and D.
英語のヒント
Fに「2番目に訪問」の意味でV2と印をつけ、図12.198に示すように、Fとそれに隣接する残りの頂点のあいだの辺の重み$170、$330、$150、$350を比べる。いちばん小さいのは$150で、FとDのあいだの辺である。
A graph represents the airfares between six different cities. The graph has 6 vertices. The vertices are A, B, C, D, E, and F. Edges from A leading to B, C, D, E, and F are labeled 250 dollars, 210 dollars, 300 dollars, 200 dollars, and 100 dollars. Edges from B leading to C, D, E, and F are labeled 220 dollars, 120 dollars, 160 dollars, and 170 dollars. Edges from C to D, E, and F are labeled 310 dollars, 180 dollars, and 330 dollars. Edges from D to E and F 270 dollars and 150 dollars. An edge from E to F is labeled 350 dollars. The edges from F are in dashed lines. A is labeled V 1. F is labeled V 2.
Figure 12.198図12.198
Finding the Third Vertex
英語のヒント
3番目の頂点を見つける
Mark D as V3 for "visited 3rd." Next, compare the weights of the edges between D and the remaining vertices adjacent to D: $120, $310, and $270 as shown in Figure 12.199. The lowest of these is $120, which is the edge between D and B.
英語のヒント
Dに「3番目に訪問」の意味でV3と印をつける。次に、図12.199に示すように、Dとそれに隣接する残りの頂点のあいだの辺の重み$120、$310、$270を比べる。いちばん小さいのは$120で、DとBのあいだの辺である。
A graph represents the airfares between six different cities. The graph has 6 vertices. The vertices are A, B, C, D, E, and F. Edges from A leading to B, C, D, E, and F are labeled 250 dollars, 210 dollars, 300 dollars, 200 dollars, and 100 dollars. Edges from B leading to C, D, E, and F are labeled 220 dollars, 120 dollars, 160 dollars, and 170 dollars. Edges from C to D, E, and F are labeled 310 dollars, 180 dollars, and 330 dollars. Edges from D to E and F 270 dollars and 150 dollars. A is labeled V 1. F is labeled V 2. D is labeled V 3. The edges, B D, C D, and D E are in dashed lines.
Figure 12.199図12.199
Finding the Fourth Vertex
英語のヒント
4番目の頂点を見つける
So, mark B as V4 for "visited 4th." Finally, compare the weights of the edges between B and the remaining vertices adjacent to B: $160 and $220 as shown in Figure 12.200. The lower amount is $160, which is the edge between B and E.
英語のヒント
だから、Bに「4番目に訪問」の意味でV4と印をつける。最後に、図12.200に示すように、Bとそれに隣接する残りの頂点のあいだの辺の重み$160と$220を比べる。小さいほうは$160で、BとEのあいだの辺である。
A graph represents the airfares between six different cities. The graph has 6 vertices. The vertices are A, B, C, D, E, and F. Edges from A leading to B, C, D, E, and F are labeled 250 dollars, 210 dollars, 300 dollars, 200 dollars, and 100 dollars. Edges from B leading to C, D, E, and F are labeled 220 dollars, 120 dollars, 160 dollars, and 170 dollars. Edges from C to D, E, and F are labeled 310 dollars, 180 dollars, and 330 dollars. Edges from D to E and F 270 dollars and 150 dollars. A is labeled V 1. F is labeled V 2. D is labeled V 3. B is labeled V 4. The edges, B E and B C are in dashed lines.
Figure 12.200図12.200
Finding the Fifth Vertex
英語のヒント
5番目の頂点を見つける
Now you can mark E as V5 and mark the only remaining vertex, which is C, as V6. This is shown in Figure 12.201. Make a note of the weight of the edge from E to C, which is $180, and from C back to A, which is $210.
英語のヒント
これでEにV5と印をつけ、ただ1つ残った頂点CにV6と印をつけられる。これを図12.201に示す。EからCへの辺の重み$180と、CからAに戻る辺の重み$210を記録する。
A graph represents the airfares between six different cities. The graph has 6 vertices. The vertices are A, B, C, D, E, and F. Edges from A leading to B, C, D, E, and F are labeled 250 dollars, 210 dollars, 300 dollars, 200 dollars, and 100 dollars. Edges from B leading to C, D, E, and F are labeled 220 dollars, 120 dollars, 160 dollars, and 170 dollars. Edges from C to D, E, and F are labeled 310 dollars, 180 dollars, and 330 dollars. Edges from D to E and F 270 dollars and 150 dollars. A is labeled V 1. F is labeled V 2. D is labeled V 3. B is labeled V 4. E is labeled V 5. C is labeled V 6. The edges, A C, and E C are in dashed lines.
Figure 12.201図12.201
Finding the Sixth Vertex
英語のヒント
6番目の頂点を見つける
The Hamilton cycle we found is A → F → D → B → E → C → A. The weight of the circuit is $100+$150+$120+$160+$180+$210=$920. This may or may not be the route with the lowest cost, but there is a good chance it is very close since the weights are most of the lowest weights on the graph and we found it in six steps instead of finding 120 different Hamilton cycles and calculating 60 weights. Let’s summarize the procedure that we used.
英語のヒント
見つけたハミルトン閉路はA → F → D → B → E → C → Aである。この回路の重みは$100+$150+$120+$160+$180+$210=$920である。これは費用がいちばん少ない経路かもしれないし、そうでないかもしれないが、重みの大部分がグラフのいちばん小さい重みなので、かなり近い可能性が高い。そして、120個の異なるハミルトン閉路を見つけて60個の重みを計算する代わりに、6手順で見つけた。使った手順をまとめよう。
Step 1: Select the starting vertex and label V1 for "visited 1st." Identify the edge of lowest weight between V1 and the remaining vertices.
英語のヒント
手順1:出発の頂点を選び、「1番目に訪問」の意味でV1とラベルをつける。V1と残りの頂点のあいだの重みがいちばん小さい辺を見きわめる。
Step 2: Label the vertex at the end of the edge of lowest weight that you found in previous step as Vn where the subscript n indicates the order the vertex is visited. Identify the edge of lowest weight between Vn and the vertices that remain to be visited.
英語のヒント
手順2:前の手順で見つけた重みがいちばん小さい辺の端の頂点にVnとラベルをつける。ここで添字nは頂点を訪れる順を示す。Vnとこれから訪れる頂点のあいだの重みがいちばん小さい辺を見きわめる。
Step 3: If vertices remain that have not been visited, repeat Step 2. Otherwise, a Hamilton cycle of low weight is V1→V2→⋯→Vn→V1.
英語のヒント
手順3:まだ訪れていない頂点が残っているなら、手順2を繰り返す。そうでなければ、重みの小さいハミルトン閉路はV1→V2→⋯→Vn→V1である。
Example 12.45例題 12.45

Using the Nearest Neighbor Method最近傍法を使う

Suppose that the candidate for governor wants to hold rallies around the state but time before the election is very limited. They would like to leave their home in city A, visit cities B, C, D, E, and F each once, and return home. The airfare between cities is not as important as the time of travel, which is indicated in Figure 12.202. Use the nearest neighbor method to find a route with relatively low travel time. What is the total travel time of the route that you found?
英語のヒント
知事の候補者が州のあちこちで集会を開きたいが、選挙までの時間がとても限られているとする。候補者は都市Aの自宅を出発し、都市B、C、D、E、Fを1回ずつ訪れ、家に戻りたい。都市のあいだの航空運賃は移動時間ほど重要ではなく、移動時間を図12.202に示す。最近傍法を使って移動時間が比較的短い経路を見つけよ。見つけた経路の移動時間の合計はいくらか。
A graph represents the airfares between six different cities. The graph has 6 vertices. The vertices are A, B, C, D, E, and F. Edges from A leading to B, C, D, E, and F are labeled 120 minutes, 140 minutes, 85 minutes, 90 minutes, and 180 minutes. Edges from B leading to C, D, E, and F are labeled 100 minutes, 80 minutes, 95 minutes, and 110 minutes. Edges from C to D, E, and F are labeled 220 minutes, 200 minutes, and 75 minutes. Edges from D to E and F are labeled 130 minutes and 70 minutes. An edge from E to F is labeled 210 minutes.
Figure 12.202図12.202
Travel Times between Cities A, B, C, D, E and F
英語のヒント
都市A、B、C、D、E、Fのあいだの移動時間
Solution解答
Step 1: Label vertex A as V1. The edge of lowest weight between A and the remaining vertices is 85 min between A and D.
英語のヒント
手順1:頂点AにV1とラベルをつける。Aと残りの頂点のあいだの重みがいちばん小さい辺は、AとDのあいだの85分である。
Step 2: Label vertex D as V2. The edge of lowest weight between D and the vertices that remain to be visited, B, C, E, and F, is 70 min between D and F.
英語のヒント
手順2:頂点DにV2とラベルをつける。Dとこれから訪れる頂点B、C、E、Fのあいだの重みがいちばん小さい辺は、DとFのあいだの70分である。
Repeat Step 2: Label vertex F as V3. The edge of lowest weight between F and the vertices that remain to be visited, B, C, and E, is 75 min between F and C.
英語のヒント
手順2を繰り返す:頂点FにV3とラベルをつける。Fとこれから訪れる頂点B、C、Eのあいだの重みがいちばん小さい辺は、FとCのあいだの75分である。
Repeat Step 2: Label vertex C as V4. The edge of lowest weight between C and the vertices that remain to be visited, B and E, is 100 min between C and B.
英語のヒント
手順2を繰り返す:頂点CにV4とラベルをつける。Cとこれから訪れる頂点B、Eのあいだの重みがいちばん小さい辺は、CとBのあいだの100分である。
Repeat Step 2: Label vertex B as V5. The only vertex that remains to be visited is E. The weight of the edge between B and E is 95 min.
英語のヒント
手順2を繰り返す:頂点BにV5とラベルをつける。これから訪れる頂点はEだけである。BとEのあいだの辺の重みは95分である。
Step 3: A Hamilton cycle of low weight is A → D → F → C → B → E → A. So, a route of relatively low travel time is A to D to F to C to B to E and back to A. The total travel time of this route is: 85min+70min+75min+100min+95min+90min=515minor8hrs35min
英語のヒント
手順3:重みの小さいハミルトン閉路はA → D → F → C → B → E → Aである。だから、移動時間が比較的短い経路はAからD、F、C、B、Eへ行ってAに戻るものである。この経路の移動時間の合計は85min+70min+75min+100min+95min+90min=515minor8hrs35minである。