From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Tue, 27 Dec 2022 04:56:50 +0000 (-0500) Subject: brute force desc X-Git-Url: http://git.skullheadx.com/nixos/static/gitweb.js?a=commitdiff_plain;h=48b17cb683ead47ec24e5c4e1c6611589b1bd2b3;p=The-Traveling-Salesman-Problem.git brute force desc --- diff --git a/.gitignore b/.gitignore index 5159ca0..883019e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /workspace.xml .idea/ __pycache__/ +*.txt diff --git a/README.md b/README.md index 357d917..61b3c6b 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,9 @@ My solutions to the Traveling Salesman Problem (TSP) inspired by video presented (https://youtu.be/GiDsjIBOVoA) -------------------------------------------------------------------------------------------------------------- -TSP Problem Definition -If a salesman starts at a town and wants to travel to every other town only once, what is the shortest path he should take? +**TSP Problem Definition** + +_If a salesman starts at a town and wants to travel to every other town only once, what is the shortest path he should take such that he ends up in the town he started in?_ Assuming that: 1. Each town is connected by a direct edge @@ -13,3 +14,6 @@ Assuming that: 3. The direct path to a town is always the shortest, i.e. going directly from town A to town C is faster than going from town A to town B and then town C -------------------------------------------------------------------------------------------------------------- +**Method 1: Brute Force** + +By checking every single possibility and calculating the distance of each route, the shortest path can be determined. However, this strategy does not work for a large number of towns because as **n**, the number of towns, increases, on the first turn, (starting at any town) there are n-1 towns to choose from, then on the second turn there are n-2 choices and so on until there is only one option left which is to return to the starting town. This means that there are `(n - 1)! / 2` total possibilities accounting for duplicates.