摘要: 1 void main() 2 { 3 Path *path; 4 time_t t1,t2; 5 int i, times = 10000; 6 7 t1 = clock(); 8 for(i = 0; i visit;//std::priority_queue, InfoCmp> visit;我用了我自己的PriorityQueue,如果用std的priority_queue只要1375ms。那你问我为什么不用std的priority_queue,那是我在做跨平台是运行错误了。不得已自己写的。你可以自己测试,注意我自己的PriorityQueu... 阅读全文
posted @ 2013-11-23 02:19 liusijian 阅读(771) 评论(0) 推荐(0) 编辑
摘要: 如果你只需要知道是否存在一条路径就选BStarBstar能快速找到一条路径,只是99%不是最短路径。如果你要找一条最短路径 可以用AStarBFS算法,在地图比较简单AStar效率高,如果地图复杂还是选BFS吧(AStar要为自己的聪明付出代价)。如果你要寻很多条路但他们的起点或终点一样就选Dijkstra SPFA算法,因为他们一次寻路就把所有到相同目标的路径都算出来了,Dijkstra算法稳定,SPFA算法不稳定,但我测试基本都是SPFA要快那么一点。至于Floyd算法基本不实用,虽然一次计算把地图任意点对路径都算出来了,但效率实在太低。算法复杂度是格子数的3次方。 阅读全文
posted @ 2013-11-23 01:50 liusijian 阅读(652) 评论(0) 推荐(0) 编辑
摘要: 1 #ifndef __FLOYD__H 2 #define __FLOYD__H 3 4 #include "AIDefine.h" 5 6 class Floyd 7 { 8 private: 9 #define MAXNUM 0x7FFFFFFF 10 public: 11 Floyd() 12 { 13 m_nodeArr = NULL; 14 m_path = NULL; 15 m_able = false; 16 } 17 ~Floyd() 18 { 19 ... 阅读全文
posted @ 2013-11-23 01:39 liusijian 阅读(387) 评论(0) 推荐(0) 编辑
摘要: 1 #ifndef __SPFA__H 2 #define __SPFA__H 3 4 #include 5 #include "AIDefine.h" 6 7 class SPFA 8 { 9 public: 10 SPFA() 11 { 12 m_nodeArr = NULL; 13 m_able = false; 14 } 15 ~SPFA() 16 { 17 if(NULL != m_nodeArr) 18 { 19 delete[]... 阅读全文
posted @ 2013-11-23 01:38 liusijian 阅读(293) 评论(0) 推荐(0) 编辑
摘要: 1 #ifndef __DIJKSTRA__H 2 #define __DIJKSTRA__H 3 4 #include "AIDefine.h" 5 #include 6 7 class Dijkstra 8 { 9 private: 10 #define MAXNUM 0x7FFFFFFF 11 public: 12 Dijkstra() 13 { 14 m_nodeArr = NULL; 15 m_able = false; 16 } 17 ~Dijkstra() 18 { 19 ... 阅读全文
posted @ 2013-11-23 01:37 liusijian 阅读(686) 评论(0) 推荐(0) 编辑
摘要: 1 #ifndef __BFS__H 2 #define __BFS__H 3 4 #include "AIDefine.h" 5 #include 6 7 class BFS 8 { 9 private:10 BFS();11 public:12 static bool find(const PointI &size, const PointI &start, const PointI &end, AI_VisitFun visitFun, Path **path = NULL,13 EFindType findType = EFIND_TYPE8 阅读全文
posted @ 2013-11-23 01:30 liusijian 阅读(391) 评论(0) 推荐(0) 编辑
摘要: 1 #ifndef __BSTAR__H 2 #define __BSTAR__H 3 4 #include "AIDefine.h" 5 #include 6 7 class BStar 8 { 9 private: 10 BStar(); 11 public: 12 static bool find(const PointI &size, const PointI &start, const PointI &end, AI_VisitFun visitFun, Path **path = NULL) 13 { 14 if(s... 阅读全文
posted @ 2013-11-23 01:28 liusijian 阅读(1005) 评论(0) 推荐(0) 编辑
摘要: 1 #ifndef __ASTAR__H 2 #define __ASTAR__H 3 4 #include "AIDefine.h" 5 #include "../Common/PriorityQueue.h" 6 7 class AStar 8 { 9 private: 10 AStar(); 11 public: 12 static bool find(const PointI &size, const PointI &start, const PointI &end, AI_VisitFun visitFun, Path 阅读全文
posted @ 2013-11-23 01:26 liusijian 阅读(413) 评论(0) 推荐(0) 编辑
摘要: 1 #include "AIDefine.h"2 3 PointI AI_FindHelpPoint[8] = {PointI(-1,0),PointI(0,-1),PointI(1,0),PointI(0,1),PointI(-1,-1),PointI(1,-1),PointI(1,1),PointI(-1,1)}; 阅读全文
posted @ 2013-11-23 01:25 liusijian 阅读(244) 评论(0) 推荐(0) 编辑
摘要: 1 #ifndef __AIDEFINE__H 2 #define __AIDEFINE__H 3 4 #include 5 #include "../Common/Path.h" 6 7 #define MATH_SQRT2 1.4142135623731f 8 enum EFindType 9 {10 EFIND_TYPE4 = 4,//must be 411 EFIND_TYPE8 = 8//must be 812 };13 extern PointI AI_FindHelpPoint[8];14 typedef float (*AI_DitanceFun)(in.. 阅读全文
posted @ 2013-11-23 01:23 liusijian 阅读(261) 评论(0) 推荐(0) 编辑
摘要: 1 #ifndef __PRIORITYQUEUE__H 2 #define __PRIORITYQUEUE__H 3 4 #include 5 6 template, typename Container = std::deque > 7 class PriorityQueue 8 { 9 public:10 bool empty() const11 {12 return (m_container.empty());13 }14 15 unsigned int size() const16 {17 return ... 阅读全文
posted @ 2013-11-23 01:21 liusijian 阅读(283) 评论(0) 推荐(0) 编辑
摘要: 1 #ifndef __PATH__H 2 #define __PATH__H 3 4 #include 5 #include "Point.h" 6 7 class Path 8 { 9 public:10 typedef std::list PathList;11 typedef PathList::const_iterator Iterator;12 public:13 Path():m_find(false),m_step(0),m_dis(0.0f){}14 Path(bool find, float dis):m_find(find),m_s... 阅读全文
posted @ 2013-11-23 01:20 liusijian 阅读(312) 评论(0) 推荐(0) 编辑
摘要: 1 #ifndef __POINT__H 2 #define __POINT__H 3 4 template 5 struct Point 6 { 7 Point():x(0),y(0){} 8 Point(const T _x, const T _y):x(_x),y(_y){} 9 inline void set(const int _x, const int _y){x = _x; y = _y;}10 inline void set(const Point &point){x = point.x; y = point.y;}11 T x;12... 阅读全文
posted @ 2013-11-23 01:16 liusijian 阅读(329) 评论(0) 推荐(0) 编辑