資源簡介
C++編寫的最短路徑蟻群搜索算法,帶有界面,可編輯地圖。
代碼片段和文件信息
#include?“StdAfx.h“
#include?“.\ant.h“
CAnt::CAnt(void)
{
m_pMapAry=Create2DArray(N_MAX_MAP_WIDTHN_MAX_MAP_HEIGHT);
}
CAnt::~CAnt(void)
{
Free2DArray(m_pMapAryN_MAX_MAP_WIDTH);
}
void?CAnt::Init()
{
//清空螞蟻?zhàn)叩穆窂?br/> m_tabuAry.RemoveAll();?
//設(shè)置螞蟻?zhàn)哌^的地方為地圖初始狀態(tài)
for?(int?i=0;i {
for?(int?j=0;j {
m_pMapAry[i][j]=g_pMapAry[i][j];
}
}
//加入起始點(diǎn),并設(shè)置起始點(diǎn)為去過了
m_ptCurrent=g_ptStart;
m_tabuAry.Add(m_ptCurrent);?
m_pMapAry[m_ptCurrent.x][m_ptCurrent.y]=1;?
//設(shè)置完成搜索標(biāo)志為false
m_blComplete=false;
?//螞蟻?zhàn)哌^的路徑長度設(shè)置為0
m_dbPathLength=0.0;
}
//檢查從(x0y0)到(xy)是否允許
bool?CAnt::CheckXY(int?x0int?y0int?xint?y)
{
//越界
if?((x<0)?||?(x>=N_MAP_WIDTH))
{
return?false;
}
//越界
if?((y<0)?||?(y>=N_MAP_HEIGHT))
{
return?false;
}
//該位置是障礙或者去過了
if?((m_pMapAry[x][y]?==?BARRIER)?||?(m_pMapAry[x][y]?==?MOVED))
{
return?false;
}
//如果沒有越界且位置為空,要檢查如果是斜穿,斜穿點(diǎn)的兩邊是否有障礙
if?((x-
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????880??2011-06-16?21:05??Robot.sln
????..A..H.?????70144??2011-06-23?18:47??Robot.suo
?????文件??????11127??2011-06-23?14:47??Robot\Ant.cpp
?????文件????????949??2011-06-20?15:29??Robot\Ant.h
?????文件???????1516??2011-06-23?14:30??Robot\Common.cpp
?????文件???????2441??2011-06-23?14:36??Robot\Common.h
?????文件???????1426??2011-06-21?19:44??Robot\DlgNewMap.cpp
?????文件????????615??2011-06-21?19:30??Robot\DlgNewMap.h
?????文件??????13416??2011-06-23?18:45??Robot\MapView.cpp
?????文件???????1136??2011-06-23?18:39??Robot\MapView.h
?????文件???????7955??2011-01-19?20:07??Robot\MyButton.cpp
?????文件???????1250??2011-01-12?13:30??Robot\MyButton.h
?????文件???????2855??2011-06-16?21:05??Robot\ReadMe.txt
?????文件???????7734??2011-06-21?19:33??Robot\res\btnbmp.bmp
?????文件???????3126??2011-06-21?13:12??Robot\res\rbt.bmp
?????文件???????5430??2011-06-21?18:24??Robot\res\robot.ico
?????文件????????361??2011-06-16?21:05??Robot\res\Robot.rc2
?????文件???????1592??2011-06-23?16:26??Robot\resource.h
?????文件???????1636??2011-06-16?21:05??Robot\Robot.cpp
?????文件????????435??2011-06-16?21:05??Robot\Robot.h
?????文件???????6561??2011-06-23?16:28??Robot\Robot.rc
?????文件???????6628??2011-06-21?19:03??Robot\Robot.vcproj
?????文件??????13427??2011-06-23?16:28??Robot\RobotDlg.cpp
?????文件???????1623??2011-06-23?16:26??Robot\RobotDlg.h
?????文件????????136??2011-06-16?21:05??Robot\stdafx.cpp
?????文件???????2508??2011-06-16?21:13??Robot\stdafx.h
?????文件???????4597??2011-06-23?14:48??Robot\Tsp.cpp
?????文件????????364??2011-06-23?13:41??Robot\Tsp.h
?????目錄??????????0??2011-06-21?19:03??Robot\res
?????目錄??????????0??2011-06-23?18:47??Robot
............此處省略3個文件信息
評論
共有 條評論