プリンキピア

第12章グラフ理論

12.9 Traveling Salesperson Problem12.9 巡回セールスパーソン問題

Three doors are shown side-by-side.
Figure 12.186図12.186
Each door on the route of a traveling salesperson can be represented as a vertex on a graph. (credit: "Three in a row, Heriot Row" by Jason Mason/Flickr, CC BY 2.1)
英語のヒント
巡回セールスパーソンの経路の上の各ドアは、グラフの頂点として表せる。(出典:Jason Mason の “Three in a row, Heriot Row”/Flickr、CC BY 2.1)

Learning Objectives学習目標

After completing this section, you should be able to:
英語のヒント
この節を終えると、次のことができるようになる。
  1. Distinguish between brute force algorithms and greedy algorithms.
    英語のヒント
    総当たりアルゴリズムと貪欲アルゴリズムを区別する。
  2. List all distinct Hamilton cycles of a complete graph.
    英語のヒント
    完全グラフの異なるハミルトン閉路をすべて挙げる。
  3. Apply brute force method to solve traveling salesperson applications.
    英語のヒント
    総当たり法を当てはめて巡回セールスパーソンの応用問題を解く。
  4. Apply nearest neighbor method to solve traveling salesperson applications.
    英語のヒント
    最近傍法を当てはめて巡回セールスパーソンの応用問題を解く。
We looked at Hamilton cycles and paths in the previous sections Hamilton Cycles and Hamilton Paths. In this section, we will analyze Hamilton cycles in complete weighted graphs to find the shortest route to visit a number of locations and return to the starting point. Besides the many routing applications in which we need the shortest distance, there are also applications in which we search for the route that is least expensive or takes the least time. Here are a few less common applications that you can read about on a website set up by the mathematics department at the University of Waterloo in Ontario, Canada:
英語のヒント
ハミルトン閉路とパスは、前の節のハミルトン閉路とハミルトンパスで見た。この節では、重みつき完全グラフのハミルトン閉路を分析して、いくつかの場所を訪れて出発点に戻る最短の経路を見つける。最短の距離が必要な多くの経路の応用のほかに、いちばん費用の少ない経路や、いちばん時間のかからない経路を探す応用もある。カナダ・オンタリオ州のウォータールー大学数学科が作ったウェブサイトで読める、あまり一般的でない応用をいくつか挙げる:
  • Design of fiber optic networks
    英語のヒント
    光ファイバー網の設計
  • Minimizing fuel expenses for repositioning satellites
    英語のヒント
    衛星の位置を変える燃料費を最小にすること
  • Development of semi-conductors for microchips
    英語のヒント
    マイクロチップの半導体の開発
  • A technique for mapping mammalian chromosomes in genome sequencing
    英語のヒント
    ゲノム配列決定で哺乳類の染色体の地図を作る手法
Before we look at approaches to solving applications like these, let's discuss the two types of algorithms we will use.
英語のヒント
このような応用問題を解く方法を見る前に、私たちが使う2種類のアルゴリズムを論じよう。

Brute Force and Greedy Algorithms総当たりアルゴリズムと貪欲アルゴリズム

An algorithm is a sequence of steps that can be used to solve a particular problem. We have solved many problems in this chapter, and the procedures that we used were different types of algorithms. In this section, we will use two common types of algorithms, a brute force algorithm and a greedy algorithm. A brute force algorithm begins by listing every possible solution and applying each one until the best solution is found. A greedy algorithm approaches a problem in stages, making the apparent best choice at each stage, then linking the choices together into an overall solution which may or may not be the best solution.
英語のヒント
アルゴリズムとは、特定の問題を解くのに使える手順の列である。この章では多くの問題を解いてきたが、使った手順はさまざまな種類のアルゴリズムだった。この節では、2つのよくある種類のアルゴリズム、総当たりアルゴリズムと貪欲アルゴリズムを使う。総当たりアルゴリズムは、ありうるすべての解を挙げることから始め、最良の解が見つかるまで1つずつ当てはめる。貪欲アルゴリズムは、問題に段階を追って取り組み、各段階で見たところ最良の選択をし、それから選択をつないで全体の解にする。その解は最良の解かもしれないし、そうでないかもしれない。
To understand the difference between these two algorithms, consider the tree diagram in Figure 12.187. Suppose we want to find the path from left to right with the largest total sum. For example, branch A in the tree diagram has a sum of 10+2+11+13=36.
英語のヒント
この2つのアルゴリズムの違いを理解するために、図12.187の樹形図を考えよう。左から右へのパスで、合計がいちばん大きいものを見つけたいとする。たとえば、樹形図の枝Aの合計は10+2+11+13=36である。
A graph has 15 vertices. The vertices are labeled 1 to 15. 10 branches into 2 and 7. 2 branches into 11 and 15. 11 branches into 13 and 8. 15 branches into 1 and 6. 7 branches into 3 and 4. 3 branches into 20 and 14. 4 branches into 11 and 5. 13, 8, 1, 6, 20, 14, 11, and 5 are labeled A to H.
Figure 12.187図12.187
Points Along Different Paths
英語のヒント
異なるパスに沿った点
To be certain that you pick the branch with greatest sum, you could list each sum from each of the different branches:
英語のヒント
合計がいちばん大きい枝を確実に選ぶには、異なる枝のそれぞれの合計を挙げればよい:
A: 10+2+11+13=36
B: 10+2+11+8=31
C: 10+2+15+1=28
D: 10+2+15+6=33
E: 10+7+3+20=40
F: 10+7+3+14=34
G: 10+7+4+11=32
H: 10+7+4+5=26
Then we know with certainty that branch E has the greatest sum.
英語のヒント
すると、枝Eの合計がいちばん大きいことが確実にわかる。
A graph has 15 vertices. The vertices are labeled 1 to 15. 10 branches into 2 and 7. 2 branches into 11 and 15. 11 branches into 13 and 8. 15 branches into 1 and 6. 7 branches into 3 and 4. 3 branches into 20 and 14. 4 branches into 11 and 5. 13, 8, 1, 6, 20, 14, 11, and 5 are labeled A to H. The edges 10 to 7, 7 to 3, and 3 to 20 are highlighted. An arrow from E points to 20.
Figure 12.188図12.188
Branch E
英語のヒント
枝E
Now suppose that you wanted to find the branch with the highest value, but you only were shown the tree diagram in phases, one step at a time.
英語のヒント
今度は、値がいちばん大きい枝を見つけたいが、樹形図は段階ごとに、1手順ずつしか見せてもらえないとする。
A graph has 3 vertices. The vertices are labeled 10, 2, and 7. 10 branches into 2 and 7. The edge, 10 to 7 is highlighted.
Figure 12.189図12.189
Tree Diagram Phase 1
英語のヒント
樹形図の段階1
After phase 1, you would have chosen the branch with 10 and 7. So far, you are following the same branch. Let’s look at the next phase.
英語のヒント
段階1のあと、あなたは10と7の枝を選ぶだろう。ここまでは同じ枝をたどっている。次の段階を見よう。
A graph has 5 vertices. The vertices are labeled 10, 2, 7, 3, and 4. 10 branches into 2 and 7. 7 branches into 3 and 4. The edges, 10 to 7 and 7 to 4 are highlighted.
Figure 12.190図12.190
Tree Diagram Phase 2
英語のヒント
樹形図の段階2
After phase 2, based on the information you have, you will choose the branch with 10, 7 and 4. Now, you are following a different branch than before, but it is the best choice based on the information you have. Let’s look at the last phase.
英語のヒント
段階2のあと、持っている情報にもとづいて、10、7、4の枝を選ぶ。今は前と異なる枝をたどっているが、持っている情報にもとづくと最良の選択である。最後の段階を見よう。
A graph has 7 vertices. The vertices are labeled 10, 2, 7, 3, 4, 11, and 15. 10 branches into 2 and 7. 7 branches into 3 and 4. 4 branches into 11 and 5. The edges, 10 to 7, 7 to 4, and 4 to 11 are highlighted. 11 and 5 are labeled G and H.
Figure 12.191図12.191
Tree Diagram Phase 3
英語のヒント
樹形図の段階3
After phase 3, you will choose branch G which has a sum of 32.
英語のヒント
段階3のあと、合計が32の枝Gを選ぶ。
The process of adding the values on each branch and selecting the highest sum is an example of a brute force algorithm because all options were explored in detail. The process of choosing the branch in phases, based on the best choice at each phase is a greedy algorithm. Although a brute force algorithm gives us the ideal solution, it can take a very long time to implement. Imagine a tree diagram with thousands or even millions of branches. It might not be possible to check all the sums. A greedy algorithm, on the other hand, can be completed in a relatively short time, and generally leads to good solutions, but not necessarily the ideal solution.
英語のヒント
各枝の値を足していちばん大きい合計を選ぶ手順は、すべての選択肢をくわしく調べたので総当たりアルゴリズムの例である。各段階の最良の選択にもとづいて段階ごとに枝を選ぶ手順は貪欲アルゴリズムである。総当たりアルゴリズムは理想の解を与えるが、実行するのにとても長い時間がかかることがある。何千、何百万もの枝をもつ樹形図を想像しよう。すべての合計を確かめることはできないかもしれない。一方、貪欲アルゴリズムは比較的短い時間で完了でき、ふつう良い解に導くが、理想の解とはかぎらない。
Example 12.42例題 12.42

Distinguishing between Brute Force and Greedy Algorithms総当たりアルゴリズムと貪欲アルゴリズムを区別する

A cashier rings up a sale for $4.63 cents in U.S. currency. The customer pays with a $5 bill. The cashier would like to give the customer $0.37 in change using the fewest coins possible. The coins that can be used are quarters ($0.25), dimes ($0.10), nickels ($0.05), and pennies ($0.01). The cashier starts by selecting the coin of highest value less than or equal to $0.37, which is a quarter. This leaves $0.37−$0.25=$0.12. The cashier selects the coin of highest value less than or equal to $0.12, which is a dime. This leaves $0.12−$0.10=$0.02. The cashier selects the coin of highest value less than or equal to $0.02, which is a penny. This leaves $0.02−$0.01=$0.01. The cashier selects the coin of highest value less than or equal to $0.01, which is a penny. This leaves no remainder. The cashier used one quarter, one dime, and two pennies, which is four coins. Use this information to answer the following questions.
英語のヒント
レジ係がアメリカの通貨で$4.63の売上を打つ。客は$5札で払う。レジ係は、できるだけ少ない硬貨で$0.37のおつりを客に渡したい。使える硬貨はクォーター($0.25)、ダイム($0.10)、ニッケル($0.05)、ペニー($0.01)である。レジ係はまず、$0.37以下でいちばん価値の高い硬貨、クォーターを選ぶ。残りは$0.37−$0.25=$0.12である。レジ係は$0.12以下でいちばん価値の高い硬貨、ダイムを選ぶ。残りは$0.12−$0.10=$0.02である。レジ係は$0.02以下でいちばん価値の高い硬貨、ペニーを選ぶ。残りは$0.02−$0.01=$0.01である。レジ係は$0.01以下でいちばん価値の高い硬貨、ペニーを選ぶ。これで残りはない。レジ係が使ったのはクォーター1枚、ダイム1枚、ペニー2枚で、硬貨は4枚である。この情報を使って次の問いに答えよ。
  1. Is the cashier’s approach an example of a greedy algorithm or a brute force algorithm? Explain how you know.
    英語のヒント
    レジ係のやり方は貪欲アルゴリズムの例か、総当たりアルゴリズムの例か。どうしてわかるかを説明せよ。
  2. The cashier’s solution is the best solution. In other words, four is the fewest number of coins possible. Is this consistent with the results of an algorithm of this kind? Explain your reasoning.
    英語のヒント
    レジ係の解は最良の解である。言いかえると、4枚がありうるいちばん少ない硬貨の数である。これはこの種類のアルゴリズムの結果と一致するか。理由を説明せよ。
Solution解答
  1. The approach the cashier used is an example of a greedy algorithm, because the problem was approached in phases and the best choice was made at each phase. Also, it is not a brute force algorithm, because the cashier did not attempt to list out all possible combinations of coins to reach this conclusion.
    英語のヒント
    レジ係が使ったやり方は、問題に段階を追って取り組み、各段階で最良の選択をしたので、貪欲アルゴリズムの例である。また、レジ係はこの結論に達するのに硬貨のありうる組み合わせをすべて挙げようとはしなかったので、総当たりアルゴリズムではない。
  2. Yes, it is consistent. A greedy algorithm does not always yield the best result, but sometimes it does.
    英語のヒント
    はい、一致する。貪欲アルゴリズムはいつも最良の結果を出すわけではないが、ときには出す。