Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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)

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M9450515

Have any Question?


Related Questions in C/C++

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As