Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C++: Implement the traveling salesperson algorithm on graphs 1 and 2. Both graph files are in the same format as the previous assignment, a

IN C++:

Implement the traveling salesperson algorithm on graphs 1 and 2. Both graph files are in the same format as the previous assignment, a list of nodes with a single node per line, a blank line, and then the list of edges in the form A B X, where X is the edge cost. Both graphs are connected (reminder that means when you read in an edge (A B X) from the file, you must also add edge (B A X)). (Graph 1 was constructed via scripts using to separate each line, so it will come up as a long line of text if opened in regular notepad.) I highly recommend testing your program on the graph contained in graph2.txt first as it is the smaller of the two graphs.

To solve the traveling salesperson problem, you must find the lowest cost simple cycle in the graph which traverses every node. To brute force this problem, that means you must check every each cycle that traverses each node in the graph (reminder that it does not matter which node you start a cycle from, as a cycle can begin with any node contained within it). Extra credit will be given to assignments which do not need to traverse all possible cycles but are still able to arrive at the optimal solution. Your implementation will need to be able to handle graphs of up to 15 nodes (we will test solutions with optimization heuristics on different graphs), and provide output of the shortest cost simple cycle, along with its cost.

If the graph is the one below, the output should be in the following form: The graph has 4 nodes

The shortest cost cycle is: A B C D A

The cost of the above cycle is 4

A B C D A B 1

A C 29

A D 1

B C 1

B D 100

C D 1

graph1.txt

//////////////////start

A B C D E F G H I J K

D F 56 D E 7 E J 31 E K 9 E F 8 D K 27 D J 6 D I 47 D H 73 F G 39 G H 6 G I 82 G J 4 G K 85 F I 2 F H 92 F K 10 F J 62 H K 20 H J 12 H I 7 C J 57 J K 80 A J 91 A K 7 A H 23 A I 28 A B 1 A C 15 A F 35 A G 12 A D 85 C H 40 C I 8 B C 5 C K 50 B E 32 B I 46 B H 88 B K 6 B J 69 C D 88 C E 4 C G 12

/////////////////end

graph2.txt

//////////////////start

A B C D E

A B 1 A C 12 A D 190 A E 1 B C 1 B D 19 B E 40 C D 1 C E 60 D E 1

/////////////////end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

help asp

Answered: 1 week ago