00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <memory>
00011 #include "pathfind.h"
00012
00013 using namespace std;
00014 using namespace PathFind;
00015
00016
00017
00018 static const int s_numberRuns = 100;
00019 static const int s_columns = 50;
00020 static const int s_rows = 50;
00021 static const float s_obstaclePercentage = 0.2;
00022 static const long long int s_nodesLimit = 100000000L;
00023
00024
00025
00026 typedef enum {A_STAR, IDA_STAR, FRINGE} SearchAlgorithm;
00027
00028
00029
00030 void printHeader(SearchAlgorithm searchAlgorithm, Tiling::Type type)
00031 {
00032 cout << "==============================================================\n";
00033 switch (searchAlgorithm)
00034 {
00035 case A_STAR:
00036 cout << "A_STAR";
00037 break;
00038 case IDA_STAR:
00039 cout << "IDA_STAR";
00040 break;
00041 case FRINGE:
00042 cout << "FRINGE";
00043 break;
00044 }
00045 cout << " ";
00046 switch (type)
00047 {
00048 case Tiling::TILE:
00049 cout << "TILE";
00050 break;
00051 case Tiling::OCTILE:
00052 cout << "OCTILE";
00053 break;
00054 case Tiling::OCTILE_UNICOST:
00055 cout << "OCTILE_UNICOST";
00056 break;
00057 case Tiling::HEX:
00058 cout << "HEX";
00059 break;
00060 }
00061 cout << '\n';
00062 cout << "==============================================================\n";
00063 }
00064
00065 void runExperiment(SearchAlgorithm searchAlgorithm, Tiling::Type type)
00066 {
00067 printHeader(searchAlgorithm, type);
00068 auto_ptr<Search> search;
00069 switch (searchAlgorithm)
00070 {
00071 case A_STAR:
00072 search.reset(new AStar<>());
00073 break;
00074 case IDA_STAR:
00075 search.reset(new IDAStar(IDAStar::f_CACHING));
00076 break;
00077 case FRINGE:
00078 search.reset(new FringeSearch<>());
00079 break;
00080 }
00081 search->setNodesLimit(s_nodesLimit);
00082 SearchUtils searchUtils;
00083 StatisticsCollection statistics = search->createStatistics();
00084 for (int runIndex = 0; runIndex < s_numberRuns; ++runIndex)
00085 {
00086
00087 Tiling tiling(type, s_rows, s_columns);
00088 tiling.setObstacles(s_obstaclePercentage, false);
00089
00090
00091 int start, target;
00092 searchUtils.findRandomStartTarget(tiling, start, target);
00093
00094
00095
00096
00097
00098 search->findPath(tiling, start, target);
00099
00100
00101
00102
00103
00104
00105
00106
00107 const StatisticsCollection& searchStatistics = search->getStatistics();
00108
00109
00110 statistics.add(searchStatistics);
00111
00112
00113 }
00114 statistics.print(cout);
00115 }
00116
00117 int main()
00118 {
00119 try
00120 {
00121
00122 runExperiment(A_STAR, Tiling::TILE);
00123
00124
00125
00126 runExperiment(IDA_STAR, Tiling::TILE);
00127
00128
00129
00130 runExperiment(FRINGE, Tiling::TILE);
00131 }
00132 catch (const exception& e)
00133 {
00134 cerr << "Error: " << e.what() << '\n';
00135 return -1;
00136 }
00137 return 0;
00138 }
00139
00140