Question: #include Project 2 _ Travelling Salesperson Problem.h #include #include #include #include #include using namespace std; / / this Define the graph with connected edges
#include "ProjectTravelling Salesperson Problem.h
#include
#include
#include
#include
#include
using namespace std;
this Define the graph with connected edges
vector graph
City
City
City
City
City
City
City
City
City
City
City
;
This Define city coordinates
struct Vertex
int id;
double city;
double city;
;
Euclidean distance between two cities
double calculateDistanceVertex city Vertex city
return sqrtpowcityfirstcityfirst, powcitysecond citysecond, ;
int main
std::vector cityCoordinates
vectorveritces
;
Breadth First Search algorithm
void BFSint start, int goal
queue q;
vector visitedgraphsize false;
qpushstart;
visitedstart true;
whileqempty
int current qfront;
qpop;
if current goal
cout "Goal city" goal "found using BFS endl;
return;
for int neighbor : graphcurrent
if visitedneighbor
qpushneighbor;
visitedneighbor true;
cout "Goal city" goal "not found using BFS endl;
Depth First Search algorithm
void DFSint start, int goal
stack s;
vector visitedgraphsize false;
spushstart;
visitedstart true;
while sempty
int current stop;
spop;
if current goal
cout "Goal city"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
