-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
90 lines (72 loc) · 1.73 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* (C) 2014 Douglas Sievers
*
* main.cpph
*/
#include <iostream>
#include <exception>
#include <fstream>
#include <cstdlib>
#include <string>
#include "Graph.h"
#include "BestFirstSearch.h"
#include "UniformCostSearch.h"
#include "AStarSearch.h"
using namespace std;
string getFilename()
{
// READ A FILE NAME
string filename;
cout << "Enter a file name: ";
cin >> filename;
return filename;
}
int main()
{
// Prompt user for a file
string filename = getFilename();
try
{
// Create a graph instance, and read the file into it
Graph g;
g.readFile(filename.c_str());
g.print(); //print the graph, for fun
// Print the list of nodes available for user to choose
// start and end points
int numNodes = g.printNodeList();
int startNode, goalNode;
// Prompt user
cout << "\nEnter start Node (0-" << numNodes << ") : ";
cin >> startNode;
cout << "Enter goal Node (0-" << numNodes << ") : ";
cin >> goalNode;
cout << endl;
cout << "\nBEST FIRST SEARCH \n--------------------\n";
BestFirstSearch a = BestFirstSearch(g);
a.search(startNode, goalNode);
#ifdef _WIN32
system("PAUSE");
#endif
cout << "\nUNIFORM COST SEARCH \n--------------------\n";
UniformCostSearch b = UniformCostSearch(g);
b.search(startNode, goalNode);
#ifdef _WIN32
system("PAUSE");
#endif
cout << "\nA STAR SEARCH \n--------------------\n";
AStarSearch c = AStarSearch(g);
c.search(startNode, goalNode);
#ifdef _WIN32
system("PAUSE");
#endif
}
// catch any errors and quit
catch (std::exception& e)
{
cout << e.what() << endl;
#ifdef _WIN32
system("PAUSE");
#endif
}
return 0;
}