Question: #include Project 2 _ Travelling Salesperson Problem.h #include #include #include #include #include using namespace std; / / this Define the graph with connected edges

#include "Project2_Travelling Salesperson Problem.h"
#include
#include
#include
#include
#include
using namespace std;
//this Define the graph with connected edges
vector> graph ={
{},// City 1
{2},// City 2
{3},// City 3
{4,5},// City 4
{6,7},// City 5
{8},// City 6
{9,10},// City 7
{9,10,11},// City 8
{},// City 9
{},// City 10
{}// City 11
};
// This Define city coordinates
struct Vertex {
int id;
double city1;
double city2;
};
// Euclidean distance between two cities
double calculateDistance(Vertex city1, Vertex city2){
return sqrt(pow(city1.firstcity2.first, 2)+pow(city1.second - city2.second, 2));
}
int main(){
//std::vector> cityCoordinates =
vectorveritces={
{1,5.681818,63.860370},
{2,11.850649,83.983573},
{3,13.798701,65.092402},
{4,16.883117,40.451745},
{5,23.782468,56.262834},
{6,25.000000,31.211499},
{7,29.951299,41.683778},
{8,31.331169,25.256674},
{9,37.175325,37.577002},
{10,39.935065,19.096509},
{11,46.834416,29.979466}
};
//Breadth First Search algorithm
void BFS(int start, int goal){
queue q;
vector visited(graph.size(), false);
q.push(start);
visited[start]= true;
while(!q.empty()){
int current = q.front();
q.pop();
if (current == goal){
cout << "Goal city" << goal << "found using BFS!"<< endl;
return;
}
for (int neighbor : graph[current]){
if (!visited[neighbor]){
q.push(neighbor);
visited[neighbor]= true;
}
}
}
cout << "Goal city" << goal << "not found using BFS"<< endl;
}
//Depth First Search algorithm
void DFS(int start, int goal){
stack s;
vector visited(graph.size(), false);
s.push(start);
visited[start]= true;
while (!s.empty()){
int current = s.top();
s.pop();
if (current == goal){
cout <<"Goal city" <

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!