Project Doc Dijkstra's Shortest Path
Project Doc Dijkstra's Shortest Path
Submitted by: Rosales, Eldhie Ann Sabanal, Karen Balala, Kvin BSCpE 2
ALGORITHM Print out the graph with its vertices name. Input the value of its edges. Show the possible path. Print out the value of the shortest path.
Source Code #include<iostream> using namespace std; int main() { int e1, e2, e3, e4, e5,e6; int p1, p2, p3, p4; cout<<"Dijkstra's Shortest Path Algorithm cout<<" c * cout<<" * * * cout<<" * * * cout<<" * * * cout<<" * * * cout<<" a * * * b cout<<" * * * cout<<" * * * * * cout<<" * * * * * cout<<" * * * * * cout<<" * * * * * cout<<" * * * * * cout<<" * d* * cout<<" * * cout<<" * * * * * *
\n\n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n\n";
cout<<" The program will find the shortest possible path in the graph from a to b.\n"; cout<<"Enter the value of edges:\n"; cout<<"\ta->c: "; cin>>e1; cout<<"\tc->b: "; cin>>e2; cout<<"\ta->d: "; cin>>e3; cout<<"\tc->d: "; cin>>e4; cout<<"\td->b: "; cin>>e5; cout<<"\ta->b: "; cin>>e6; p1=e1+e2; p2=e3+e5; p3=e1+e4+e5; p4=e2+e3+e4;
cout<<"There are five possible path:\n"; cout<<" a, c, b\n"; cout<<" a, d, b\n"; cout<<" a, c, d, b\n"; cout<<" a, d, c. b\n"; cout<<" a to b\n\n"; if ((p1<p2)&&(p1<p3)&&(p1<p4)&&(p1<e6)) cout<<"The shortest path is "<<p1<<".It passes through the vertices of a, c, b."<<endl; else if ((p2<p1)&&(p2<p3)&&(p2<p4)&&(p2<e6)) cout<<"The shortest path is "<<p2<<".It passes through the vertices of a, d, b."<<endl; else if ((p3<p1)&&(p3<p2)&&(p3<p4)&&(p3<e6)) cout<<"The shortest path is "<<p3<<". It passes through the vertices of a, c, d, b."<<endl; else if ((p4<p1)&&(p4<p2)&&(p4<p3)&&(p4<e6)) cout<<"The shortest path is "<<p4<<". It passes through the vertices of a, d, c. b."<<endl; else if ((e6<p1)&&(e6<p2)&&(e6<p3)&&(e6<p4)) cout<<"The shortest path is "<<e6<<".It passes through the vertices of a to b."<<endl; return 0; }
OUTPUT