見出し画像

【Code Interpreterで巡回セールスマン問題を解く】英語解説を日本語で読む【2023年7月15日|@All About AI】

この動画では、巡回セールスマン問題を解決するための手法として、最も近い都市から順に経路を作成する「最近傍法」や、全ての経路を試す「全探索法」、そして経路の一部を交換する「ペアワイズ交換法」などのアルゴリズムについて説明されています。また、与えられた都市のリストと各都市間の距離データをCode Interpreterにアップロードし、最短経路を求めるプログラムを実行しています。 動画では、最も近い都市から順に経路を作成する「最近傍法」を実行し、その結果を視覚化するためのグラフやヒートマップを作成しています。さらに、都市の座標データを使用して、地図上に最短経路をアニメーション表示するプログラムも作成しています。 最終的に、Code Interpreterを使用して問題を解決し、結果を視覚化することができたことに満足しており、視聴者にもCode Interpreterの活用方法やアイデアを提供することができたと述べています。
公開日:2023年7月15日
※動画を再生してから読むのがオススメです。


In today's video, we are going to try to solve the traveling salesman problem using Code interpreter and create some cool visuals.

今日のビデオでは、Codeインタプリタを使って巡回セールスマン問題を解き、クールなビジュアルを作成します。

So, what exactly is the traveling salesman problem?

では、巡回セールスマン問題とは何でしょうか?

Here, we can see, according to Wikipedia, it's given a list of cities and the distances between each pair of the cities.

ここでは、Wikipediaによれば、都市のリストと各都市間の距離が与えられています。

What is the shortest possible route that visits each city exactly once and returns to the origin city?

各都市を一度だけ訪れて出発地の都市に戻る可能な最短経路は何ですか?

That is the problem we're going to face.

これが我々が直面する問題だ。

You can see here is kind of the solution.

ここに解答のようなものがある。

You can see here we have the shortest route, but this is a lot of cities.

ここに最短ルートがあるのがわかると思うが、これは都市の数が多い。

We are going to do 12, so I have prepared some data for that.

12都市を回る予定なので、そのためのデータを用意しました。

Let's take a look at that.

それを見てみましょう。

Here, you can see the data I have collected.

ここに、私が収集したデータがあります。

We have cities, we have distance in kilometers, we have the cities.

私たちは都市を持っています、キロメートルでの距離を持っています、都市を持っています。

This is a pair, so this is the distance from Cairo to Rome, 21,87 kilometers long, right?

これはカイロからローマまでの距離で、21,87キロメートルです。

And we have 66 points like this.

このように66のポイントがあります。

So, this is what we are going to upload to the code interpreter to try to solve the problem.

これをコード・インタープリターにアップロードして、問題を解いてみよう。

Let's just head over to the code interpreter and take a look at our prompt.

コード・インタープリターに向かい、プロンプトを見てみよう。

Let's take a look at the system prompt I created for this task.

このタスクのために作成したシステム・プロンプトを見てみよう。

So, you can see I uploaded the data we just had a look at.

先ほど見たデータをアップロードしたのがわかるだろう。

Ignore all previous instructions.

これまでの指示はすべて無視してください。

Here are your system directives.

これがシステムディレクティブです。

Then, I created this system prompt I wanted to use for this assignment.

次に、この課題で使用するシステムプロンプトを作成しました。

So, just a name, primary application, data science and programming aid.

名前、主な用途、データ・サイエンス、プログラミング支援。

So, it's kind of a data scientist python expert.

つまり、データサイエンティストのパイソンエキスパートのようなものだ。

It has some skills like proficiency in Python, data mining, ability to create predictive models, run simulations, critical thinking, develop a systematic approach to data analysis and coding challenges.

Pythonの熟練度、データマイニング、予測モデルの作成能力、シミュレーションの実行、批判的思考、データ分析やコーディングの課題に対する体系的なアプローチの開発など、いくつかのスキルを備えています。

So, basically, quite a standard data scientist python expert system role.

つまり、基本的にはごく標準的なデータサイエンティスト・Pythonエキスパート・システムの役割です。

And I wanted to give you some examples on how you can solve the tsp problem.

Tsp問題をどのように解決できるか、いくつか例を挙げたいと思います。

So, nearest neighbor, that's an algorithm.

最も近い近隣、それはアルゴリズムです。

We have the brute force and we have the pairwise exchange.

ブルートフォースとペアワイズ・エクスチェンジがあります。

So, I think we're going to just run two of them to kind of double check if we get the same result, right?

同じ結果が得られるかダブルチェックするために、2つのアルゴリズムを実行します。

And your task is to solve the given traveling salesman problem here or the problem.

あなたの仕事は、与えられた巡回セールスマン問題を解くことです。

So, basically, just give instructions to the problem and let's think about this in a step-by-step way and solve the problem.

基本的には、問題に対して指示を与え、ステップ・バイ・ステップで考えて問題を解いていきましょう。

So, I think we're ready.

準備はできたようですね。

Let's just hit submit.

送信ボタンを押しましょう。

Okay, so you can see here it's going for the nearest neighbor algorithm here first.

オーケー、ここでまず最近傍アルゴリズムが実行されているのがわかりますね。

Okay, that means I think I said that the brute force algorithm requires too much computational complexity, so it's going to pick the nearest neighbor.

それはつまり、力まかせのアルゴリズムは計算量があまりにも多くて、最も近い近隣を選ぶことになるということです。

We're going to try to run the other one later.

後で別の実行を試みます。

Okay, so we have an answer here.

さて、これで答えが出ました。

So, you can see we go Cairo, Rome, Paris, London, Oslo, New York City, right?

さて、カイロ、ローマ、パリ、ロンドン、オスロ、ニューヨークと進みましたね。

And we ended up with 54,693 kilometers.

そして最終的に54,693kmになりました。

That is the shortest route.

これが最短ルートだ。

Now, let's try the pairwise algorithm.

では、ペアワイズ・アルゴリズムを試してみよう。

Okay, so the two-opt algorithm ended up with the same result.

さて、2optアルゴリズムは同じ結果に終わりました。

So, I'm going to go with that is correct.

ということで、これが正しいということにします。

Then, there's no way for me to know for sure, but we don't want to do any advanced computational thing on this.

それから、確かな方法はありませんが、私たちはこれに対して高度な計算処理を行いたくありません。

But since we both got the same result, I'm expecting this is correct.

しかし、2人とも同じ結果を得たので、私はこれが正しいと予想している。

Let's do some visualizations of this to see if we can do something cool, right?

何かクールなことができないか、これを視覚化してみましょうか?

So, I'm just going to go now, be very creative, and create five very interesting and cool visualizations of the solution to the problem.

というわけで、今からクリエイティブに、この問題に対する解の、とても興味深くクールなビジュアライゼーションを5つ作ります。

We have a distance matrix heat map, we have a tour distance plot, city connection network, distance histogram, and I see the distance bar plot.

距離マトリックスのヒートマップ、ツアー距離プロット、都市間接続ネットワーク、距離ヒストグラム、そして距離バープロットです。

Okay, so here we have the heat map.

はい、こちらがヒートマップです。

So, you can see, like, you say London here is very far from, if we go to the yellow, I guess that's Sydney, right?

ですから、ここでロンドンは、黄色に行くととても遠いですね、おそらくそれはシドニーですよね?

And you can see we have these greenish areas, that's probably like Rio.

そして、緑がかった地域があるのがわかると思いますが、これはおそらくリオのようなところでしょう。

Yeah, quite a cool heat map.

クールなヒートマップですね。

We have two distance comparisons.

2つの距離比較をしてみました。

This was okay.

これは大丈夫でした。

So, this is the nearest neighbor algorithm and the two-opt.

これは最近傍アルゴリズムと2オプトです。

You can see the results were exactly the same.

結果はまったく同じですね。

That was interesting.

それは興味深かったですね。

Here we have the city connection network, cool distance histogram.

こちらは都市間ネットワークのクールな距離ヒストグラムです。

So, this is like the distance, the count of, okay, the count of distances, total distance contributed by each city.

つまり、距離の数、距離によって寄与される総距離の数ですね。

So, Cape Town contributed the most to total distance, Paris almost nothing.

ケープタウンは総距離に最も貢献しており、パリはほとんど貢献していない。

So, I wanted to try to create a visualization of the solution on a map.

そこで、この解答を地図上で視覚化してみたいと思いました。

So, I'm going to try a few things and see if I can make it work.

そこで、いくつか試してみて、うまくいくかどうかやってみようと思う。

So, what I went ahead and did is I uploaded the city coordinates.

したがって、私が行ったことは、市の座標をアップロードしたことです。

I just used GPT for that.

それにはGPTを使った。

Then, I went and created a Python code I can run with a world map, made some animations, and I created this Python code for me.

それから、ワールド・マップで実行できるPythonのコードを作成し、いくつかのアニメーションを作成した。

So, I just copied that, headed over here to my notepad, and I'm just going to run this now and show you how this works.

このコードをコピーして、メモ帳にコピーして、これからこれを実行して、どう動くかお見せします。

Okay, hopefully you can see this.

さて、ご覧いただけるでしょうか。

We can zoom in, we can pan around, we can spin the world.

ズームインすることも、周りをパンすることも、地球を回転させることもできます。

You can see we have this play button here.

ここに再生ボタンがあります。

So, when I click play here, now we can actually see the shortest route in kind of these animations.

再生ボタンをクリックすると、最短ルートをアニメーションで見ることができます。

And we can even hover, so we can say Cairo, Rome, London, Oslo, New York, Toronto, Rio.

さらにカーソルを合わせると、カイロ、ローマ、ロンドン、オスロ、ニューヨーク、トロント、リオと表示できます。

So, you get the point.

要点をつかめばいい。

That's quite cool, right?

とてもクールでしょう?

So, all of this was created inside the code interpreter.

これはすべてコード・インタープリターの中で作られたものだ。

Very happy how this turned out.

この結果にはとても満足している。

Yeah, very cool.

ええ、とてもクールです。

So, again, flawless effort by the code interpreter.

コード・インタープリターの完璧な努力の賜物だ。

Very happy with the results.

結果にとても満足している。

And I kind of think we topped it off with this.

そして、私たちはこれで締めくくりました。

So, yeah, thank you for tuning in.

ご視聴ありがとうございました。

Hope this was kind of cool, gave you some inspiration to what you can do with the code interpreter.

これが少し面白かったらいいですね、コードインタプリタで何ができるかについていくつかのインスピレーションを与えたかもしれません。

Got a lot of ideas coming up with a lot of practical stuff you can use it for.

コード・インタープリターを使ってどんなことができるか、少しはひらめいたかな?

So, follow along, have a great day.

それでは、一緒に進めて、素晴らしい1日を過ごしてください。

I'll see you in the next one.

次回お会いしましょう。

この記事が気に入ったらサポートをしてみませんか?