⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme.txt

📁 这是一个蚁群算法的蚂蚁聚类的程序
💻 TXT
字号:
========================================================================
       MICROSOFT FOUNDATION CLASS LIBRARY : AntClusting
========================================================================



3.5版把CalcuSimilar()函数,CalcuPickProb()函数,和CalcuDropProb()函数从CAnt类中移到
CAntClusteringAlogrithm类中,但还是将AntThreadProc函数做为全局函数,采用多线程来实现聚类

3.6版把CalcuSimilar()函数,CalcuPickProb()函数,和CalcuDropProb()函数从CAnt类中移到
CAntClusteringAlogrithm类中,而且将AntThreadProc函数也做为CAntClusteringAlgorithm中
一个成员函数,不采用多线程来实现聚类。不足之处是:只用了一个蚂蚁实现聚类,没有体现出
多个蚂蚁共用行为。对程序进行了进一步的改进,把similar变量从CAnt类中转到CAntClusteringAlogrithm类


4.0版继承自3.6版
与3.6版的主要改进在于,实现将任意数据文件读入数组中,并将数组的头指针传入蚂蚁聚类算法类中,可以进行聚类操作。
对各类内变量及成员函数进行了调整。
 
 1 蚂蚁类
   类中的成员包括:
    
	数据对象的属性值数组头指针    float  *m_pfAntPropArray、
    蚂蚁坐标                      float m_dAntX,m_dAntY;
	蚂蚁是否有负载的标识           bool   m_bIsLoad;
	蚂蚁考察的数据对象在整个数据对象数据组中的序号	int    m_nDataPosition;  
	数据对象的维度                 int    m_nAntPropNum;       
   
    除两个构造函数外,只有两成员函数:
	
	蚂蚁移动函数,即赋给蚂蚁一对新的x、y坐标  void AntChangePosition(float newx,float newy);    
	设置蚂蚁函数,即把数据对象的属性赋给蚂蚁  void SetAnt(struct DataObject *data,int dataPosition); 

取消了initant函数,将其改造成构造函数

  2 蚂蚁聚类算法类
   类中的成员包括:
        double m_dAlpha;    //相似度参数alpha
	int m_nAntNumber;   //蚂蚁数
	double m_dPickK;    //拾起概率
	double m_dDropK;    //放下概率
	double m_dR;        //蚂蚁考察半径
	int m_nXSize;       //二维平面x轴大小
	int m_nYSize;       //二维平面y轴大小
	UINT   m_nMaxCycNum;   // 最大循环次数
	int    m_nACADataNum;  //数据对象总数
	int    m_nACAPropNum;  //数据对象维度
	double m_dDist;        //分类半径     
	double m_dSimilar;     //相似度

   私有成员函数包括:

        double CalcuDropProb(double similar);    //计算放下概率函数
	double CalcuSimilar(CAnt * m_pAnt);      //计算相似度函数
	double CalcuPickProb(double similar);    //计算拾起概率函数
   共有成员函数包括:
 	
      UINT AntThreadProc(DataObject* _dataObj,double alpha,int antnum,double pickk,double dropk,
		                double r,UINT maxcycnum);
	/////蚂蚁聚类算法实现函数
	void InitDataObject();   //初始化数据对象
	int ClassifyData();      //分类函数
将"计算放下概率函数"、"计算相似度函数"、"计算拾起概率函数"由CAnt类中移到聚类算法类CAntClusterAlogrithm中,将聚类计算放入一个类中实现。

     3.视类CAntClustingView中主要在OnParameter()调用参数设置对话框,实现了参数传递。在OnDraw()中实现了聚类结果的可视化。
     
     4.CArrayData为数据文件类,主要实现了将数据文件中的数据读入数组中的功能
    其主要成员有:
        float* m_pfData;	//存储数据对象的数组指针
        CString m_strPathName;   //数据文件名
	int m_nLine;               //数据对象个数,一个占一行
	int m_nRow;                //数据对象属性数,一个占一列
	int m_nTotal;              //数据对象总数
	CString m_strLastError;

     其对外接口的成员函数主要有:
        int GetPropNum();          //获取数据对象维数
	int GetDataNum(void);      //获取数据对象总数
	float* GetData();          //获取存储数据对象的数组句柄     
   

4.5继承自4.0版,对错误的分类算法进行了纠正,对最后显示分类效果的可视化OnDraw函数进行了改进,
使之能正常显示分类结果,实现了比较大的突破。
在分类算法中采用了"队列"和"链表"这两个新的数据结构
初始将所有元素放于链表中,从链表中取出头元素放入队列,并从表中删除该元素。
依次从队列中取出头元素,顺序计算该头元素与链表中剩余元素间的距离,若与链表
中某一元素间的距离小于指定的类间距,则将该元素从链表中取出放入队列,若遍历
完链表,则将队列头元素出列。重复该过程直至链表中无剩余元素。

新添加的类如下:

结合类:CLink          //单个结点


链表类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 //链表内部指针,指向待考察元素的前一个元素
  int leftcnt;            // Size of left partition     \\\链表内部指针fence左侧的元素个数
  int rightcnt;           // Size of right partition    \\\链表内部指针fence右侧的元素个数
  void init() ;          //初始化
 
// Return link nodes to free store 
void removeall()         //删除链表 
public:
  void clear();           //清空链(删除链并新建一新链)
  
 // Insert at front of right partition  //当内部指针的右侧加入一新元素
  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指针指向元素的下一个元素
 bool remove(Elem& it)
 
 bool is_empty();    //判断链表是否为空

 void setStart()     //将链表内部指针置于链表头
 
 void setEnd()       //将链表内部指针置于链表尾
  
 // Move fence one step left; no change if left is empty    //将链表内部指针前移一位
  void prev()
 
  void next()                                                 //将链表内部指针后移一位     

  int leftLength() const  { return leftcnt; }                  //链表内部指针左侧元素个数
  
  int rightLength() const { return rightcnt; }         //链表内部指针右侧元素个数
 
// Set the size of left partition to pos             
  bool setPos(int pos)

bool getValue(Elem& it) const                      //获取链表内部指针指向的下一个元素值
  
bool  Locate(Elem& it)                            //将内部指针置于值为it的元素的前一个
};


队列类:
template <class Elem> class LQueue
{
public:
    CLink<Elem>* front;     // Pointer to front queue node       //队列头
    CLink<Elem>* rear;      // Pointer to rear queue node        //队列尾

	int size;              // Number of elements in queue    //队列中元素个数

public:
		
	void clear()        // Clear queue                       //删除队列中元素
	
   
	bool enqueue(const Elem& it)                             //把新元素it加入队列
		
	bool dequeue(Elem& it)                                   //队列头元素出列
		
	bool frontValue(Elem& it) const                           //获取队列头元素值
			
	int length() const                                       //获取队列中元素个数

	bool is_outqueue(Elem& it)                               //判别队列中是否有值为it的元素
                                                                  若有则返回false。

};


5.0改进了读文件函数,使之能正确读地形数据文件。




      

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.

/////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -