02:11 < Back Assignment 2.docx Question 2 (15 marks) - Travelling Salesperson The travelling salesperson problem...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
02:11 < Back Assignment 2.docx Question 2 (15 marks) - Travelling Salesperson The travelling salesperson problem (TSP) is as follows; "Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city". The problem was first formulated in 1930 and is one of the most intensively studied problems in optimization. Even though the problem is computationally difficult, a large number of heuristics and algorithms are known, so that some instances with tens of thousands of cities can be solved completely and even problems with millions of cities can be approximated within a small fraction of 1% optimal distance. This question has 3 parts: a) loadTSP(filename) (4 marks). Write this p5.js function that will read a TSP problem from a .tsp file. For this assignment, we will only consider Euclidean distance problems. The information you need to load in includes the problem name, total number of cities, the id of each city, and the co-ordinates of those cities. You could store the city information as 3 parallel arrays (ids, xcords, ycoords) or an array of objects with an id, x and y value. You can find the TSPLIB documentation and the dataset with Euclidean only problems on the course website. Your function should take the name of a .tsp file to load. Hint: Reading the TSPLIB.pdf file can be a little daunting. Have a look at some of the actual .tsp files (berlin52.tsp, a280.tsp). It should make the problem seem a lot easier. b) showLoadedTSP() (4 marks). Write this function that will visualise a loaded problem. You will need to find a way to scale the loaded problem to fit correctly on the canvas. You may choose what shapes/colours to use to visualise the problem. You should make sure you display the problem name and number of cities somewhere on the canvas. c) showSolution(solutionFile) (4 marks). Write this function that will visualise a solution to a loaded problem from a file. You may assume that this function will only be used AFTER showLoadedTSP() has already been run. The first line of a .sol file contains the problem file name (you should check this matches the loaded TSP). The second line contains the tour length, and the rest of the file contains a list of ID's (one on each line) that represents the order that the cities should be connected to form the shortest tour. You should display the solution tour distance on the canvas. Some sample .sol files have been provided on the course website. Challenge (3 marks): Make the program animate the tour. The program should show the salesman starting from the first city and smoothly moving between all the cities leaving the tour as a trail behind them until they reach the last city and return back to the first one. You can loop this animation if you wish. Extra Bonus: (No marks, just kudos). Investigate algorithms to solve tsp problems. You could start with Greedy search, and then move on to something like 2-opt. Try and implement a solver to generate your own solutions to TSP problems. This is advanced work and not part of the course. Do this ATTEN misining everyuning else. 4G 02:11 < Back Assignment 2.docx Question 2 (15 marks) - Travelling Salesperson The travelling salesperson problem (TSP) is as follows; "Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city". The problem was first formulated in 1930 and is one of the most intensively studied problems in optimization. Even though the problem is computationally difficult, a large number of heuristics and algorithms are known, so that some instances with tens of thousands of cities can be solved completely and even problems with millions of cities can be approximated within a small fraction of 1% optimal distance. This question has 3 parts: a) loadTSP(filename) (4 marks). Write this p5.js function that will read a TSP problem from a .tsp file. For this assignment, we will only consider Euclidean distance problems. The information you need to load in includes the problem name, total number of cities, the id of each city, and the co-ordinates of those cities. You could store the city information as 3 parallel arrays (ids, xcords, ycoords) or an array of objects with an id, x and y value. You can find the TSPLIB documentation and the dataset with Euclidean only problems on the course website. Your function should take the name of a .tsp file to load. Hint: Reading the TSPLIB.pdf file can be a little daunting. Have a look at some of the actual .tsp files (berlin52.tsp, a280.tsp). It should make the problem seem a lot easier. b) showLoadedTSP() (4 marks). Write this function that will visualise a loaded problem. You will need to find a way to scale the loaded problem to fit correctly on the canvas. You may choose what shapes/colours to use to visualise the problem. You should make sure you display the problem name and number of cities somewhere on the canvas. c) showSolution(solutionFile) (4 marks). Write this function that will visualise a solution to a loaded problem from a file. You may assume that this function will only be used AFTER showLoadedTSP() has already been run. The first line of a .sol file contains the problem file name (you should check this matches the loaded TSP). The second line contains the tour length, and the rest of the file contains a list of ID's (one on each line) that represents the order that the cities should be connected to form the shortest tour. You should display the solution tour distance on the canvas. Some sample .sol files have been provided on the course website. Challenge (3 marks): Make the program animate the tour. The program should show the salesman starting from the first city and smoothly moving between all the cities leaving the tour as a trail behind them until they reach the last city and return back to the first one. You can loop this animation if you wish. Extra Bonus: (No marks, just kudos). Investigate algorithms to solve tsp problems. You could start with Greedy search, and then move on to something like 2-opt. Try and implement a solver to generate your own solutions to TSP problems. This is advanced work and not part of the course. Do this ATTEN misining everyuning else. 4G
Expert Answer:
Related Book For
Statistics For Business And Economics
ISBN: 9780132745659
8th Edition
Authors: Paul Newbold, William Carlson, Betty Thorne
Posted Date:
Students also viewed these programming questions
-
Need to code in p5.js. Post your code here. step by step explanation please. Thanks The travelling salesperson problem (TSP) is as follows; "Given a list of cities and the distances between each pair...
-
re Regular Languages and Finite Automata (a) Let L be the set of all strings over the alphabet {a, b} that end in a and do not contain the substring bb. Describe a deterministic finite automaton...
-
ABC Corporation earned $300,000 in profit in the current tax year, which is significantly higher than its previous year's earnings. Thus, its shareholders expected large dividends in the current...
-
On December 31, 2016, Rugaboo Corp. issues 6%, 10-year convertible bonds payable with a maturity value of $4,000,000. The semiannual interest dates are June 30 and December 31. The market interest...
-
Financial information for Forever 18 includes the following selected data: ($ in millions except per share amounts) Net income Dividends on preferred stock Average shares outstanding Stock price per...
-
What the general requirements are for all motions?
-
In 2020, Shelden aged 60 was laid off in March 2020 as a result of COVID-19. Shelden is married to Pamela and Pamela stays home to babysit their three grandkids who lives with Shelden's daughter,...
-
Case : Stock A has a beta of .69 and an expected return of 9.27 percent. Stock B has a beta of 1.13 and an expected return of 11.88 percent. Stock C has a beta of 1.48 and an expected return of 15.31...
-
Player Company acquired 60 percent ownership of Scout Companys voting shares on January 1, 20X2. During 20X5, Player purchased inventory for $20,000 and sold the full amount to Scout Company for...
-
Advise Nike company on the 9 strategic staffing decisions - Justify your responses by linking it to the need /type of organization, strategy of the organization and other relevant factors Core or...
-
what is the difference in allocation between two activity cost pools and theee addictty cost pools?
-
How do graphic novels and visual storytelling challenge traditional definitions of literary form? What does the integration of visual and textual elements offer in terms of narrative complexity and...
-
In SQL, Do a project which is a restaurant themed web-app using an sqlite database. Optional video on the setup of the database in the Intro to Mojolicious video:...
-
You agree to sell 3 machines to an Italian printer for 4.6 MM Euros. Your cost for the machinery is $4.5 MM. The exchange rate at the time of the deal (July 30) was 1.4 USD per Euro. The equipment...
-
Examine the influence of ancient epic poetry on contemporary epic fantasy. What thematic elements and narrative devices persist, and how have modern authors adapted these to reflect current cultural...
-
The prices for which of the following goods are included in both the GDP defla- tor and the consumer price index? (a) goods bought by households (b) goods bought by firms (c) good bought by...
-
In exchange for land, the company received a 12-month note on January 1. The face amount of the note is $1,000, and the stated rate of interest is 13%, compounded annually. The 13% rate is equal to...
-
Two years ago the manager of a local supermarket that sells three national brands (brands A, B, and C) and one store brand (brand D) of orange juice found that brands A and C were equally preferred,...
-
As part of a process to build a new automotive portfolio, you have been asked to determine the beta coefficients for AB Volvo and General Motors. Data for this task are contained in the data file...
-
Refer to the data of Exercise 17.4. If a total sample of 100 students is to be taken, determine how many of these should be freshmen and sophomores under each of the following schemes. a....
-
Does the fact that selling is included as part of the promotional mix weaken or strengthen its role as a sub-element of marketing?
-
Discuss the role and function of selling.
-
Comment on why the proposed changes to sales processes are necessary. Also, which changes would you recommend in terms of their: (a) selling activities? (b) sales value proposition?
Study smarter with the SolutionInn App