?? readme.txt
字號(hào):
========================================================================
MICROSOFT FOUNDATION CLASS LIBRARY : AntClusting
========================================================================
3.5版把CalcuSimilar()函數(shù),CalcuPickProb()函數(shù),和CalcuDropProb()函數(shù)從CAnt類中移到
CAntClusteringAlogrithm類中,但還是將AntThreadProc函數(shù)做為全局函數(shù),采用多線程來(lái)實(shí)現(xiàn)聚類
。
3.6版把CalcuSimilar()函數(shù),CalcuPickProb()函數(shù),和CalcuDropProb()函數(shù)從CAnt類中移到
CAntClusteringAlogrithm類中,而且將AntThreadProc函數(shù)也做為CAntClusteringAlgorithm中
一個(gè)成員函數(shù),不采用多線程來(lái)實(shí)現(xiàn)聚類。不足之處是:只用了一個(gè)螞蟻實(shí)現(xiàn)聚類,沒(méi)有體現(xiàn)出
多個(gè)螞蟻共用行為。對(duì)程序進(jìn)行了進(jìn)一步的改進(jìn),把similar變量從CAnt類中轉(zhuǎn)到CAntClusteringAlogrithm類
中
4.0版繼承自3.6版
與3.6版的主要改進(jìn)在于,實(shí)現(xiàn)將任意數(shù)據(jù)文件讀入數(shù)組中,并將數(shù)組的頭指針傳入螞蟻聚類算法類中,可以進(jìn)行聚類操作。
對(duì)各類內(nèi)變量及成員函數(shù)進(jìn)行了調(diào)整。
1 螞蟻類
類中的成員包括:
數(shù)據(jù)對(duì)象的屬性值數(shù)組頭指針 float *m_pfAntPropArray、
螞蟻?zhàn)鴺?biāo) float m_dAntX,m_dAntY;
螞蟻是否有負(fù)載的標(biāo)識(shí) bool m_bIsLoad;
螞蟻考察的數(shù)據(jù)對(duì)象在整個(gè)數(shù)據(jù)對(duì)象數(shù)據(jù)組中的序號(hào) int m_nDataPosition;
數(shù)據(jù)對(duì)象的維度 int m_nAntPropNum;
除兩個(gè)構(gòu)造函數(shù)外,只有兩成員函數(shù):
螞蟻移動(dòng)函數(shù),即賦給螞蟻一對(duì)新的x、y坐標(biāo) void AntChangePosition(float newx,float newy);
設(shè)置螞蟻函數(shù),即把數(shù)據(jù)對(duì)象的屬性賦給螞蟻 void SetAnt(struct DataObject *data,int dataPosition);
取消了initant函數(shù),將其改造成構(gòu)造函數(shù)
2 螞蟻聚類算法類
類中的成員包括:
double m_dAlpha; //相似度參數(shù)alpha
int m_nAntNumber; //螞蟻數(shù)
double m_dPickK; //拾起概率
double m_dDropK; //放下概率
double m_dR; //螞蟻考察半徑
int m_nXSize; //二維平面x軸大小
int m_nYSize; //二維平面y軸大小
UINT m_nMaxCycNum; // 最大循環(huán)次數(shù)
int m_nACADataNum; //數(shù)據(jù)對(duì)象總數(shù)
int m_nACAPropNum; //數(shù)據(jù)對(duì)象維度
double m_dDist; //分類半徑
double m_dSimilar; //相似度
私有成員函數(shù)包括:
double CalcuDropProb(double similar); //計(jì)算放下概率函數(shù)
double CalcuSimilar(CAnt * m_pAnt); //計(jì)算相似度函數(shù)
double CalcuPickProb(double similar); //計(jì)算拾起概率函數(shù)
共有成員函數(shù)包括:
UINT AntThreadProc(DataObject* _dataObj,double alpha,int antnum,double pickk,double dropk,
double r,UINT maxcycnum);
/////螞蟻聚類算法實(shí)現(xiàn)函數(shù)
void InitDataObject(); //初始化數(shù)據(jù)對(duì)象
int ClassifyData(); //分類函數(shù)
將"計(jì)算放下概率函數(shù)"、"計(jì)算相似度函數(shù)"、"計(jì)算拾起概率函數(shù)"由CAnt類中移到聚類算法類CAntClusterAlogrithm中,將聚類計(jì)算放入一個(gè)類中實(shí)現(xiàn)。
3.視類CAntClustingView中主要在OnParameter()調(diào)用參數(shù)設(shè)置對(duì)話框,實(shí)現(xiàn)了參數(shù)傳遞。在OnDraw()中實(shí)現(xiàn)了聚類結(jié)果的可視化。
4.CArrayData為數(shù)據(jù)文件類,主要實(shí)現(xiàn)了將數(shù)據(jù)文件中的數(shù)據(jù)讀入數(shù)組中的功能
其主要成員有:
float* m_pfData; //存儲(chǔ)數(shù)據(jù)對(duì)象的數(shù)組指針
CString m_strPathName; //數(shù)據(jù)文件名
int m_nLine; //數(shù)據(jù)對(duì)象個(gè)數(shù),一個(gè)占一行
int m_nRow; //數(shù)據(jù)對(duì)象屬性數(shù),一個(gè)占一列
int m_nTotal; //數(shù)據(jù)對(duì)象總數(shù)
CString m_strLastError;
其對(duì)外接口的成員函數(shù)主要有:
int GetPropNum(); //獲取數(shù)據(jù)對(duì)象維數(shù)
int GetDataNum(void); //獲取數(shù)據(jù)對(duì)象總數(shù)
float* GetData(); //獲取存儲(chǔ)數(shù)據(jù)對(duì)象的數(shù)組句柄
4.5繼承自4.0版,對(duì)錯(cuò)誤的分類算法進(jìn)行了糾正,對(duì)最后顯示分類效果的可視化OnDraw函數(shù)進(jìn)行了改進(jìn),
使之能正常顯示分類結(jié)果,實(shí)現(xiàn)了比較大的突破。
在分類算法中采用了"隊(duì)列"和"鏈表"這兩個(gè)新的數(shù)據(jù)結(jié)構(gòu)
初始將所有元素放于鏈表中,從鏈表中取出頭元素放入隊(duì)列,并從表中刪除該元素。
依次從隊(duì)列中取出頭元素,順序計(jì)算該頭元素與鏈表中剩余元素間的距離,若與鏈表
中某一元素間的距離小于指定的類間距,則將該元素從鏈表中取出放入隊(duì)列,若遍歷
完鏈表,則將隊(duì)列頭元素出列。重復(fù)該過(guò)程直至鏈表中無(wú)剩余元素。
新添加的類如下:
結(jié)合類:CLink //單個(gè)結(jié)點(diǎn)
鏈表類LList
template <class Elem> class LList {
private:
CLink<Elem>* head; // Pointer to list header
CLink<Elem>* tail; // Pointer to last Elem in list
CLink<Elem>* fence; // Last element on left side //鏈表內(nèi)部指針,指向待考察元素的前一個(gè)元素
int leftcnt; // Size of left partition \\\鏈表內(nèi)部指針fence左側(cè)的元素個(gè)數(shù)
int rightcnt; // Size of right partition \\\鏈表內(nèi)部指針fence右側(cè)的元素個(gè)數(shù)
void init() ; //初始化
// Return link nodes to free store
void removeall() //刪除鏈表
public:
void clear(); //清空鏈(刪除鏈并新建一新鏈)
// Insert at front of right partition //當(dāng)內(nèi)部指針的右側(cè)加入一新元素
bool insert(const Elem&) ;
// Append Elem to end of the list //鏈表尾部加入新元素
bool append(const Elem& item)
// Remove and return first Elem in right partition 移除fence指針指向元素的下一個(gè)元素
bool remove(Elem& it)
bool is_empty(); //判斷鏈表是否為空
void setStart() //將鏈表內(nèi)部指針置于鏈表頭
void setEnd() //將鏈表內(nèi)部指針置于鏈表尾
// Move fence one step left; no change if left is empty //將鏈表內(nèi)部指針前移一位
void prev()
void next() //將鏈表內(nèi)部指針后移一位
int leftLength() const { return leftcnt; } //鏈表內(nèi)部指針左側(cè)元素個(gè)數(shù)
int rightLength() const { return rightcnt; } //鏈表內(nèi)部指針右側(cè)元素個(gè)數(shù)
// Set the size of left partition to pos
bool setPos(int pos)
bool getValue(Elem& it) const //獲取鏈表內(nèi)部指針指向的下一個(gè)元素值
bool Locate(Elem& it) //將內(nèi)部指針置于值為it的元素的前一個(gè)
};
隊(duì)列類:
template <class Elem> class LQueue
{
public:
CLink<Elem>* front; // Pointer to front queue node //隊(duì)列頭
CLink<Elem>* rear; // Pointer to rear queue node //隊(duì)列尾
int size; // Number of elements in queue //隊(duì)列中元素個(gè)數(shù)
public:
void clear() // Clear queue //刪除隊(duì)列中元素
bool enqueue(const Elem& it) //把新元素it加入隊(duì)列
bool dequeue(Elem& it) //隊(duì)列頭元素出列
bool frontValue(Elem& it) const //獲取隊(duì)列頭元素值
int length() const //獲取隊(duì)列中元素個(gè)數(shù)
bool is_outqueue(Elem& it) //判別隊(duì)列中是否有值為it的元素
若有則返回false。
};
5.0改進(jìn)了讀文件函數(shù),使之能正確讀地形數(shù)據(jù)文件。
AppWizard has created this AntClusting application for you. This application
not only demonstrates the basics of using the Microsoft Foundation classes
but is also a starting point for writing your application.
This file contains a summary of what you will find in each of the files that
make up your AntClusting application.
AntClusting.dsp
This file (the project file) contains information at the project level and
is used to build a single project or subproject. Other users can share the
project (.dsp) file, but they should export the makefiles locally.
AntClusting.h
This is the main header file for the application. It includes other
project specific headers (including Resource.h) and declares the
CAntClustingApp application class.
AntClusting.cpp
This is the main application source file that contains the application
class CAntClustingApp.
AntClusting.rc
This is a listing of all of the Microsoft Windows resources that the
program uses. It includes the icons, bitmaps, and cursors that are stored
in the RES subdirectory. This file can be directly edited in Microsoft
Visual C++.
AntClusting.clw
This file contains information used by ClassWizard to edit existing
classes or add new classes. ClassWizard also uses this file to store
information needed to create and edit message maps and dialog data
maps and to create prototype member functions.
res\AntClusting.ico
This is an icon file, which is used as the application's icon. This
icon is included by the main resource file AntClusting.rc.
res\AntClusting.rc2
This file contains resources that are not edited by Microsoft
Visual C++. You should place all resources not editable by
the resource editor in this file.
/////////////////////////////////////////////////////////////////////////////
For the main frame window:
MainFrm.h, MainFrm.cpp
These files contain the frame class CMainFrame, which is derived from
CFrameWnd and controls all SDI frame features.
res\Toolbar.bmp
This bitmap file is used to create tiled images for the toolbar.
The initial toolbar and status bar are constructed in the CMainFrame
class. Edit this toolbar bitmap using the resource editor, and
update the IDR_MAINFRAME TOOLBAR array in AntClusting.rc to add
toolbar buttons.
/////////////////////////////////////////////////////////////////////////////
AppWizard creates one document type and one view:
AntClustingDoc.h, AntClustingDoc.cpp - the document
These files contain your CAntClustingDoc class. Edit these files to
add your special document data and to implement file saving and loading
(via CAntClustingDoc::Serialize).
AntClustingView.h, AntClustingView.cpp - the view of the document
These files contain your CAntClustingView class.
CAntClustingView objects are used to view CAntClustingDoc objects.
/////////////////////////////////////////////////////////////////////////////
Other standard files:
StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named AntClusting.pch and a precompiled types file named StdAfx.obj.
Resource.h
This is the standard header file, which defines new resource IDs.
Microsoft Visual C++ reads and updates this file.
/////////////////////////////////////////////////////////////////////////////
Other notes:
AppWizard uses "TODO:" to indicate parts of the source code you
should add to or customize.
If your application uses MFC in a shared DLL, and your application is
in a language other than the operating system's current language, you
will need to copy the corresponding localized resources MFC42XXX.DLL
from the Microsoft Visual C++ CD-ROM onto the system or system32 directory,
and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation.
For example, MFC42DEU.DLL contains resources translated to German.) If you
don't do this, some of the UI elements of your application will remain in the
language of the operating system.
/////////////////////////////////////////////////////////////////////////////
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -