Reputation: 105
I'm having trouble coming up with a plan for a project assigned in a C++ Data Structures course. I'm not asking for written code, but a plan of attack. Basically I'm having a hard time thinking this through.
How would you go about constructing a weighted graph from this weighted non-directed map with the intention of being able to find the shortest path from a set vertex (Angel's Stadium) to:
I also have to allow a user to plan their dream vacation by selecting Stadiums they want to visit.
The program only needs to print the number of stadiums visited and the total distance traveled in each case.
My first thought is to have methods for each of the four cases. I'm not even sure how I should go about returning the number of stadiums visited and distance. Is using a struct optimal when you need to return two values?
Let alone which algorithm to use for shortest path. I have an implementation of Dijkstra's from a previous assignment. Some others in my class are using a minimal spanning tree.
It would make more sense to have one function for the shortest path that takes in a list of the stadiums to visit but I don't know how I would structure the adjacency matrix.
I'm making an input file to read in the adjacency matrix formated like so (edge, weight):
0 1 340
0 2 110
Is this the optimal structure for this case? I'm not sure how to differentiate between major league, national, and American. Are separate input files necessary? Or is there a better way of organizing this?
Here's the full assignment if you are interested: [word document]
Upvotes: 0
Views: 696
Reputation: 11
You need to implement different instances of TSP (without the final hop) with the stadiums in the tour chosen according to the criteria specified in the question.
For instance,
minCost = inf
for (stadium in CaliforniaStadiums )
minCost = min(minCost, TSP (stadium, MLStadiums))
Hope that helps.
Rudra
Upvotes: 1