この動画では、巡回セールスマン問題を解決するための手法として、最も近い都市から順に経路を作成する「最近傍法」や、全ての経路を試す「全探索法」、そして経路の一部を交換する「ペアワイズ交換法」などのアルゴリズムについて説明されています。また、与えられた都市のリストと各都市間の距離データをCode Interpreterにアップロードし、最短経路を求めるプログラムを実行しています。 動画では、最も近い都市から順に経路を作成する「最近傍法」を実行し、その結果を視覚化するためのグラフやヒートマップを作成しています。さらに、都市の座標データを使用して、地図上に最短経路をアニメーション表示するプログラムも作成しています。 最終的に、Code Interpreterを使用して問題を解決し、結果を視覚化することができたことに満足しており、視聴者にもCode Interpreterの活用方法やアイデアを提供することができたと述べています。
公開日:2023年7月15日
※動画を再生してから読むのがオススメです。
今日のビデオでは、Codeインタプリタを使って巡回セールスマン問題を解き、クールなビジュアルを作成します。
では、巡回セールスマン問題とは何でしょうか?
ここでは、Wikipediaによれば、都市のリストと各都市間の距離が与えられています。
各都市を一度だけ訪れて出発地の都市に戻る可能な最短経路は何ですか?
これが我々が直面する問題だ。
ここに解答のようなものがある。
ここに最短ルートがあるのがわかると思うが、これは都市の数が多い。
12都市を回る予定なので、そのためのデータを用意しました。
それを見てみましょう。
ここに、私が収集したデータがあります。
私たちは都市を持っています、キロメートルでの距離を持っています、都市を持っています。
これはカイロからローマまでの距離で、21,87キロメートルです。
このように66のポイントがあります。
これをコード・インタープリターにアップロードして、問題を解いてみよう。
コード・インタープリターに向かい、プロンプトを見てみよう。
このタスクのために作成したシステム・プロンプトを見てみよう。
先ほど見たデータをアップロードしたのがわかるだろう。
これまでの指示はすべて無視してください。
これがシステムディレクティブです。
次に、この課題で使用するシステムプロンプトを作成しました。
名前、主な用途、データ・サイエンス、プログラミング支援。
つまり、データサイエンティストのパイソンエキスパートのようなものだ。
Pythonの熟練度、データマイニング、予測モデルの作成能力、シミュレーションの実行、批判的思考、データ分析やコーディングの課題に対する体系的なアプローチの開発など、いくつかのスキルを備えています。
つまり、基本的にはごく標準的なデータサイエンティスト・Pythonエキスパート・システムの役割です。
Tsp問題をどのように解決できるか、いくつか例を挙げたいと思います。
最も近い近隣、それはアルゴリズムです。
ブルートフォースとペアワイズ・エクスチェンジがあります。
同じ結果が得られるかダブルチェックするために、2つのアルゴリズムを実行します。
あなたの仕事は、与えられた巡回セールスマン問題を解くことです。
基本的には、問題に対して指示を与え、ステップ・バイ・ステップで考えて問題を解いていきましょう。
準備はできたようですね。
送信ボタンを押しましょう。
オーケー、ここでまず最近傍アルゴリズムが実行されているのがわかりますね。
それはつまり、力まかせのアルゴリズムは計算量があまりにも多くて、最も近い近隣を選ぶことになるということです。
後で別の実行を試みます。
さて、これで答えが出ました。
さて、カイロ、ローマ、パリ、ロンドン、オスロ、ニューヨークと進みましたね。
そして最終的に54,693kmになりました。
これが最短ルートだ。
では、ペアワイズ・アルゴリズムを試してみよう。
さて、2optアルゴリズムは同じ結果に終わりました。
ということで、これが正しいということにします。
それから、確かな方法はありませんが、私たちはこれに対して高度な計算処理を行いたくありません。
しかし、2人とも同じ結果を得たので、私はこれが正しいと予想している。
何かクールなことができないか、これを視覚化してみましょうか?
というわけで、今からクリエイティブに、この問題に対する解の、とても興味深くクールなビジュアライゼーションを5つ作ります。
距離マトリックスのヒートマップ、ツアー距離プロット、都市間接続ネットワーク、距離ヒストグラム、そして距離バープロットです。
はい、こちらがヒートマップです。
ですから、ここでロンドンは、黄色に行くととても遠いですね、おそらくそれはシドニーですよね?
そして、緑がかった地域があるのがわかると思いますが、これはおそらくリオのようなところでしょう。
クールなヒートマップですね。
2つの距離比較をしてみました。
これは大丈夫でした。
これは最近傍アルゴリズムと2オプトです。
結果はまったく同じですね。
それは興味深かったですね。
こちらは都市間ネットワークのクールな距離ヒストグラムです。
つまり、距離の数、距離によって寄与される総距離の数ですね。
ケープタウンは総距離に最も貢献しており、パリはほとんど貢献していない。
そこで、この解答を地図上で視覚化してみたいと思いました。
そこで、いくつか試してみて、うまくいくかどうかやってみようと思う。
したがって、私が行ったことは、市の座標をアップロードしたことです。
それにはGPTを使った。
それから、ワールド・マップで実行できるPythonのコードを作成し、いくつかのアニメーションを作成した。
このコードをコピーして、メモ帳にコピーして、これからこれを実行して、どう動くかお見せします。
さて、ご覧いただけるでしょうか。
ズームインすることも、周りをパンすることも、地球を回転させることもできます。
ここに再生ボタンがあります。
再生ボタンをクリックすると、最短ルートをアニメーションで見ることができます。
さらにカーソルを合わせると、カイロ、ローマ、ロンドン、オスロ、ニューヨーク、トロント、リオと表示できます。
要点をつかめばいい。
とてもクールでしょう?
これはすべてコード・インタープリターの中で作られたものだ。
この結果にはとても満足している。
ええ、とてもクールです。
コード・インタープリターの完璧な努力の賜物だ。
結果にとても満足している。
そして、私たちはこれで締めくくりました。
ご視聴ありがとうございました。
これが少し面白かったらいいですね、コードインタプリタで何ができるかについていくつかのインスピレーションを与えたかもしれません。
コード・インタープリターを使ってどんなことができるか、少しはひらめいたかな?
それでは、一緒に進めて、素晴らしい1日を過ごしてください。
次回お会いしましょう。