A perfect solution is impossible or too expensive

Assignment Help C/C++ Programming
Reference no: EM13160391

Optimization is often encountered in engineering problems. More often than not, a perfect solution is impossible or too expensive to find and implement. Therefore, we resort to sub-optimal, yet useful, solutions. This assignment tackles a classical problem in optimization called the Travelling Salesman problem, where this situation arises.

The Travelling Salesman problem involves a salesman who has to visit a number of cities in a single closed tour. The salesman always starts and ends the tour in his home city and visits each other city on the tour exactly once. The problem is to minimise the overall amount of distance travelled. This problem arises in many other situations familiar to engineers. For instance, the design of electrical wiring in a building or in a car, the optimisation of the movement of a read-write head on a disk drive, the planning of airliners movements, the design of bus routes or garbage collection truck routes.

You are required to design and implement a GUI that demonstrates a possible solution to the problem. The optimisation procedure is described in this assignment sheet.

Your task:

Basic Solution :

Write a MATLAB GUI driven program to demonstrate the solution to the TSP. The program must show a graphical display of the 2-dimensional map, with the cities suitably displayed on the map.

Advanced Solution

Find an alternative (preferably better) solution to the problem. The TSP problem is a classical problem and many solutions exist. You must adequately acknowledge the source of your solution and the nature of the material that you obtained (for instance, whether you found a description of the algorithm, source code for MATLAB, and so on).   In addition to incorporating the advanced solution in your program, the basic solution and the alternative solution must be evaluated and compared. This is to be done by running each at least 30 times on the same set of randomly generated set of 50 cities, and comparing the average difference in tour lengths and the standard deviation.

Graphic User Interface Requirements:

1.      The Basic Solution program is driven by a GUI with the following elements:

    • Pull-down menu specifying the numberNof cities (from the set {10,20,30,...,100})
    • Push-button to generate a random set ofNcities on the map
    • Push-button to optimise the tour and produce connected plot of the tour
    • Axes (plot area) to display the map of the journey - cities should be plotted as circles and the tour plotted as a connecting line through the cities.
    • The tour plot should be updated as the tour is optimised; use a suitable pause between plot updates so that the user can view the optimisation process.
    • The tour length should appear in the plot title and get updated as the optimisation progresses.
    • A Push-button to exit the program.

2.      The Advanced Solution has the following extension to the GUI :

    • Additional Push-button to optimise with your turbo charged algorithm. The tour produced by this push button should overlay the existing map and use a different line type (e.g. dash-dot) and different colour, so that it is possible to see the basic tour and the advanced tour on the same plot.
    • There is no requirement to update the tour as optimisation progresses (you may do this nevertheless). The tour length should be updated when advanced optimisation is complete.

Other requirements:

1.      No function can be more than 12 lines long (not counting comment lines)

2.      Use sub-functions to break down the solution into a set of solutions to smaller problems

3.      Only one command per line is allowed

4.      Document your functions clearly with comments

5.      Use meaningful variable and function names

6.      Structure your program so that functions perform small and well-defined tasks.

7.      The user should be able to try and optimise the same set of cities multiple times. The program must therefore seed the random number generator from the system clock each time it is run. Use MATLAB help function to find out more about random numbers and seeding the random number generator.

Useful Subfunctions:

d = distance(a,b) - a function that computes the number of kilometres d between two cities a and b [the distance is computed as sqrt ((x1-x2) 2 + (y1-y2) 2)].

[ tour, tourLength ] = tsp(position) - a function that computes the tour and its length in km.

Note:

position is the matrix of city positions (each city is represented by a row vector of [x,y] coordinates)

 

tour is an array of integers specifying the order of city on the tour.

 

For example, if there are 10 cities on the tour, then the array [ 1, 3, 7, 10, 9, 6, 8, 4, 5, 2 ] specifies the tour 1---> 2 ---> 7 ---> ... ---> 5 ---> 2 ---> 1 where the tour always starts and ends at position 1 (the home city).

Explanation of the basic tour optimisation algorithm

The optimisation problem we are considering is known as the Travelling Salesman Problem (TSP). It is NP-Complete which to us simply means it's not feasible to solve the problem exactly for large numbers of cities. Instead we use a heuristic approach to create a reasonable, though not necessarily optimal solution:

The tour starts with city 1 - the home city. We then add one city at a time to the tour. The tour is always closed - i.e. it starts and ends at the home city. Suppose that we already have N cities on the tour. When we insert the N+1 city it can be inserted at any one of N positions on the closed tour (the home city is always in position 1). We find the insertion point that leads to the shortest tour and insert the city there. We continue until all cities have been added.

For example, if the tour we have is [1 3 2 4] and we are about to insert city 5, then the possible tours are [1 5 3 2 4],   [1 3 5 2 4],   [1 3 2 5 4],   and   [1 3 2 4 5].   One of these will usually be shorter than the other tours, and we will adopt it. We then proceed to insert city 6 using the same approach.   Note that this does not imply that we get a globally minimal tour length, but it is usually quite reasonable approach.

The algorithm can always begin with 3 cities on the tour: the Post Office and two other cities (any two, picked at random)

Having inserted all the cities into the tour we proceed to optimise it. To do so, we attempt to move each of the cities to a better position on the tour. This is done by deleting the city (disconnecting it from its two neighbours, and closing the tour by connecting the neighbours) and then re-inserting the city into the tour in the best position (similar to the original insertion procedure). The process terminates when we cannot find any city that can be moved elsewhere by deletion and re-insertion thereby producing a shorter tour.

Your tsp function can therefore be designed around a loop that inserts one city at a time, in the best possible insertion point. After every insertion it can update the plot of the tour so far, and pause for a brief moment if necessary (for the user viewing the process). When insertion is complete the process continues by deleting each city in turn and re-inserting it. When all cities are re-inserted in the same position from which they were deleted the algorithm terminates (since there is no longer any shortening of the tour length by this process)

Reference no: EM13160391

Questions Cloud

Ending finished-goods inventory cost under variable costing : What is the ending finished-goods inventory cost under absorption costing? What is the ending finished-goods inventory cost under variable costing?
Amount of cash account problem : In addition to the accounts listed above, Truex also had a Cash account. What is the amount of that Cash account as of May 1?
Thermodynamic system with three states in the canonical : A similar question was asked before, but the formatting of the answer made it unreadable. So, I am asking it again. I have a thermodynamic system with three states in the canonical ensemble
What is the effective rate of protection on the product : If Inputs A and B are respectively 20% and 40% of the cost of producing this product, what is the effective rate of protection on the product?
A perfect solution is impossible or too expensive : Optimization is often encountered in engineering problems. More often than not, a perfect solution is impossible or too expensive to find and implement. Therefore, we resort to sub-optimal, yet useful, solutions. This assignment tackles a classical p..
Compute the maximum wavelength of light with sufficient : Calculate the maximum wavelength of light with sufficient energy to dissociate a diatomic chlorine molecule into chlorine radicals.
Record interest using the effective-interest method : Record the two journal entries that should be recorded by McLean Company for the two purchases on January 1, 2011. Record the interest at the end of the first year on both notes using the effective-interest method.
Project operating cash flow for the first year : The company faces a 40% tax rate. What is the project's operating cash flow for the first year (t = 1)?
What is the volume of the balloon at the altitude : A helium-filled weather balloon has a volume of 714 L at 23 oC and 759 mmHg. It is released and rises to an altitude of 4.80 km, where the pressure is 495 mm Hg and the temperature is -9oC. what is the volume of the balloon at this altitude.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Computing value of the return statement

In the following code snippet, what is the value of the return statement for x = 4 and n = 4? int foo(int x, int n)

  Calculates the student * averages and quiz averages based

Calculates the student * averages and quiz averages based upon input from the user. Modify this program to read in the following grade text file, * with a maximum number of students set to 35 and having five quiz scores for each student. The output s..

  Prompts the user to enter an integer

Write the code that prompts the user to enter an integer between 1 and 20 (including 1 and 20), reads the value using cin, and then prints the value that they entered in a statement that begins with "You entered a ". Save this version in a separate l..

  Prepare a program for a retail-mart company

Prepare a program for a company Retail-Mart.

  Use c-strings without using the c-string library

write a program that implementd and test the following functions for use C-strings without using the c-string libaray  ( that is, you re NOT ALLOWED to use #include in this   program):

  Design and write a c++11/fltk game program

The project is to design and write a C++11/FLTK game program with a graphical user interface. The game is based on "pancake sorting," which actually has some mathematical significance.

  Build a traffic light system - microcontroller system

Build the whole system with 3 RAG units and three puffin crossing units and build a team to work on this mini-project, be careful in selecting your team member.

  Program to enter number of values to be processed

Write c++ statements to permit the user to enter n, the number of values to be processed; then assign the anonymous array of n double values, storing its address in doublPtr.

  Program to output value of tenth component of array

Write a C++ statements to perform the following: Set value of fourth component of array alpha to three times  value of eight component minus 57.

  Write a program that inputs a dollar amount to be printed

Write a program that inputs a dollar amount to be printed on a check and then prints the amount in check-protected format with leading asterisks if necessary

  Complete the design and implementation

Complete the design and implementation of the class customerType defined in the Programming Example Video Store. b. Design and implement the class customerListType to create and maintain a list of customers for the video store.

  Write a program that asks the user to enter the names of 3

Write a program that asks the user to enter the names of three salesmen. The program should thenaccept the sales produced for salesman for each quarter of the year. Display the name, and the totalsales amount, of each salesman.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd