The Haversine equation listed above can be found at https://en.wikipedia.org/wiki/Haversine_formula Here is the text...

90.2K

Verified Solution

Question

Accounting

imageimageimage

imageimageimageimageimage

The Haversine equation listed above can be found at https://en.wikipedia.org/wiki/Haversine_formula

Here is the text file:

10 New York,40.7127837,-74.0059413 Los Angeles,34.0522342,-118.2436849 Chicago,41.8781136,-87.6297982 Houston,29.7604267,-95.3698028 Philadelphia,39.9525839,-75.1652215 Phoenix,33.4483771,-112.0740373 San Antonio,29.4241219,-98.4936282 San Diego,32.715738,-117.1610838 Dallas,32.7766642,-96.7969879 San Jose,37.3382082,-121.8863286

I tried uploading this problem yesterday and the expert said there wasn't enough information although this is the complete question. I've been struggling with this for days so it would be amazing if I could get help writing this code.

Thank you so much!

In this assignment you will compute a tour, using a prescribe algorithm, that visits each city in a given set of cities and drawing the result. Introduction and Background Suppose you have a set of cities that you would like to visit starting and ending at your home city. This is known as a tour. For example, if you would start at River Falls, and visit Minneapolis, Chicago. One tour would be River Falls-Minneapolis-Chicago-River Falls. An obvious question one would ask is "What is shortest tour (distance-wise) that is possible?" This problem is known as the Traveling Salesperson Problem (TSP). As the cities increasing to hundreds and thousands, this becomes a very difficult optimization problem and has a wide application in science and engineering. In this assignment question, you will find a tour that visits a set of cities using a greedy algorithm. Although the tour that this algorithm finds will, in general, not be a shortest tour, it is often a very good tour. Formally, the traveling salesperson problem consists of a set of n cities, say cities 0, 1, ..., n-1 and a distance function d that specifies the distance between any two cities x, y, which is denoted by d(x, y). For any two cities x, y, we assume for simplicity there is a direct route between cities x and y with distance given by d(x, y). A tour of the cities 0, 1, ... , n-1 is a visitation of these cities such that 1. The tour can start at any city. 2. The tour visits each city exactly once. 3. Once every city has been visited, the tour finished by returning to the city it started from. A tour can be thought of as a single cycle that contains all the cities. n-2 Suppose the cities visited by a tour is XO + Xo ---Xn-1 + Xo (which can be represented by the list of [Xo, Xp,..., Xn-1, xo]). Then the length of this tour is 2 d(xy, Xi+a)) + d({n-1, xo), i=0 which is the sum of the distances of going from one city to the next in the tour. For more information about the traveling salesperson problem see here. Your task in this assignment is to read in a data file which consists of a set of cities and their locations (given by latitude and longitude values and find a tour T of these cities using a specified greedy algorithm. Then you will plot the cities and draw the tour T. What to do Step 1 - creating a Python class called Tsp This class will contain the following instance variables: . A 1-dimensional numpy array called longitudes to store the longitudes of each city. A 1-dimensional numpy array called latitudes to store the latitudes of each city. A list called cityNames to store the names of each city. A 2-dimensional numpy array called distances to store the distances between cities, where the element in index [i,j] will contain the distance between cities i andj. o This array will be filled by the instance method computeDistances using the Haversin formula (see below). A 1-dimensional numpy array called tour to contain a tour of minimum cost. The data type should be integer. You can do this by adding dtype=int as an argument to the array call during creation. The entry at subscript 0 and numCities should be the city number of the starting city. o The entry at subscript i where 1siSan Diego(7)-->Phoenix(5) -->San Jose(9) -- >Dallas(8) -->Houston(3)-- >San Antonio(6)-->Chicago(2)-->Philadelphia(4) -->New York(@)-->Los Angeles(1) Distances Array: 0.00 3926.95 1141.74 2276.24 129.33 3436.01 2539.33 3898.43 2200.80 4892.69 3926.95 0.00 2797.70 2201.33 3834.85 572.98 1929.44 179.01 1987.53 490.45 1141.74 2797.70 0.00 1512.41 1065.61 2331.12 1690.50 2780.43 1292.06 2950.96 2276.24 2201.33 1512.41 0.00 2151.44 1628.52 303.66 2089.17 360.96 2581.60 129.33 3834.85 1965.61 2151.44 0.00 3336.59 2417.01 3802.03 2083.31 4012.51 3436.01 572.98 2331.12 1628.52 3336.59 0.00 1359.56 479.78 1420.35 986.11 2539.33 1929.44 1690.50 303.66 2417.01 1359.56 0.00 1808.60 405.35 2330.32 3898.43 179.01 2780.43 2089.17 3802.03 479.78 1808.60 0.00 1897.32 668.60 2200.80 1987.53 1292.06 360.96 2083.31 1420.35 405.35 1897.32 0.80 2326.69 4092.69 490.45 2950.96 2581.60 4012.51 986.11 2330.32 668.60 2326.69 0.00 length of tour = 11448.59 km Chiengot27 New York Philadega(4) 40 38 San Jose 9) 36 latitude 34 Los Angeles Phoenix(5) San Diego Dallas 32 30 Houston (3) San Antonio -120 -110 -90 -80 -100 longitude In this assignment you will compute a tour, using a prescribe algorithm, that visits each city in a given set of cities and drawing the result. Introduction and Background Suppose you have a set of cities that you would like to visit starting and ending at your home city. This is known as a tour. For example, if you would start at River Falls, and visit Minneapolis, Chicago. One tour would be River Falls-Minneapolis-Chicago-River Falls. An obvious question one would ask is "What is shortest tour (distance-wise) that is possible?" This problem is known as the Traveling Salesperson Problem (TSP). As the cities increasing to hundreds and thousands, this becomes a very difficult optimization problem and has a wide application in science and engineering. In this assignment question, you will find a tour that visits a set of cities using a greedy algorithm. Although the tour that this algorithm finds will, in general, not be a shortest tour, it is often a very good tour. Formally, the traveling salesperson problem consists of a set of n cities, say cities 0, 1, ..., n-1 and a distance function d that specifies the distance between any two cities x, y, which is denoted by d(x, y). For any two cities x, y, we assume for simplicity there is a direct route between cities x and y with distance given by d(x, y). A tour of the cities 0, 1, ... , n-1 is a visitation of these cities such that 1. The tour can start at any city. 2. The tour visits each city exactly once. 3. Once every city has been visited, the tour finished by returning to the city it started from. A tour can be thought of as a single cycle that contains all the cities. n-2 Suppose the cities visited by a tour is XO + Xo ---Xn-1 + Xo (which can be represented by the list of [Xo, Xp,..., Xn-1, xo]). Then the length of this tour is 2 d(xy, Xi+a)) + d({n-1, xo), i=0 which is the sum of the distances of going from one city to the next in the tour. For more information about the traveling salesperson problem see here. Your task in this assignment is to read in a data file which consists of a set of cities and their locations (given by latitude and longitude values and find a tour T of these cities using a specified greedy algorithm. Then you will plot the cities and draw the tour T. What to do Step 1 - creating a Python class called Tsp This class will contain the following instance variables: . A 1-dimensional numpy array called longitudes to store the longitudes of each city. A 1-dimensional numpy array called latitudes to store the latitudes of each city. A list called cityNames to store the names of each city. A 2-dimensional numpy array called distances to store the distances between cities, where the element in index [i,j] will contain the distance between cities i andj. o This array will be filled by the instance method computeDistances using the Haversin formula (see below). A 1-dimensional numpy array called tour to contain a tour of minimum cost. The data type should be integer. You can do this by adding dtype=int as an argument to the array call during creation. The entry at subscript 0 and numCities should be the city number of the starting city. o The entry at subscript i where 1siSan Diego(7)-->Phoenix(5) -->San Jose(9) -- >Dallas(8) -->Houston(3)-- >San Antonio(6)-->Chicago(2)-->Philadelphia(4) -->New York(@)-->Los Angeles(1) Distances Array: 0.00 3926.95 1141.74 2276.24 129.33 3436.01 2539.33 3898.43 2200.80 4892.69 3926.95 0.00 2797.70 2201.33 3834.85 572.98 1929.44 179.01 1987.53 490.45 1141.74 2797.70 0.00 1512.41 1065.61 2331.12 1690.50 2780.43 1292.06 2950.96 2276.24 2201.33 1512.41 0.00 2151.44 1628.52 303.66 2089.17 360.96 2581.60 129.33 3834.85 1965.61 2151.44 0.00 3336.59 2417.01 3802.03 2083.31 4012.51 3436.01 572.98 2331.12 1628.52 3336.59 0.00 1359.56 479.78 1420.35 986.11 2539.33 1929.44 1690.50 303.66 2417.01 1359.56 0.00 1808.60 405.35 2330.32 3898.43 179.01 2780.43 2089.17 3802.03 479.78 1808.60 0.00 1897.32 668.60 2200.80 1987.53 1292.06 360.96 2083.31 1420.35 405.35 1897.32 0.80 2326.69 4092.69 490.45 2950.96 2581.60 4012.51 986.11 2330.32 668.60 2326.69 0.00 length of tour = 11448.59 km Chiengot27 New York Philadega(4) 40 38 San Jose 9) 36 latitude 34 Los Angeles Phoenix(5) San Diego Dallas 32 30 Houston (3) San Antonio -120 -110 -90 -80 -100 longitude

Answer & Explanation Solved by verified expert
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students