资源简介

一个非常精美实用的蚁群算法演示程序,完整源代码以及工程文件,以C#完成,建议VS打开,可debug内直接exe运行,要求NET Framework,非原创,网络范围已有

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Ant
{
    class Antc
    {
        public Antc(int seed)
        {
            NowLocation.X = PlayGround.HomeLocation.X;
            NowLocation.Y = PlayGround.HomeLocation.Y;
            //LastLocation.X = NowLocation.X;
            //LastLocation.Y = NowLocation.Y;
            ran = new Random(seed);
            NowDirection = (AntDirection) ran.Next(4) + 1; // 4:只使用4个方向,8:使用8个方向
            HomeSmellNum = MaxSmell; // 蚂蚁身上携带的Home信息素的数量
            FoodSmellNum = 0;
            FoodNum = 0;
            ClearTrace();
        }

        private void ClearTrace()
        {
            for (int i = 0; i < MaxTrace; i++)
            {
                Trace[i].X = 0;
                Trace[i].Y = 0;
            }
        }

        private void DropHomeSmell()
        {
            if (HomeSmellNum <= 0) return;
            int groundsmell = PlayGround.HomeSmell[NowLocation.X NowLocation.Y];
            int smelldrop = (int) (HomeSmellNum * SmellDropRate);
            if (smelldrop > groundsmell) PlayGround.HomeSmell[NowLocation.X NowLocation.Y] = smelldrop;
            HomeSmellNum -= smelldrop;
            if (HomeSmellNum < 0) HomeSmellNum = 0;
        }

        private void DropFoodSmell()
        {
            if (FoodSmellNum <= 0) return;
            int groundsmell = PlayGround.FoodSmell[NowLocation.X NowLocation.Y];
            int smelldrop = (int)(FoodSmellNum * SmellDropRate);
            if (smelldrop > groundsmell) PlayGround.FoodSmell[NowLocation.X NowLocation.Y] = smelldrop;
            FoodSmellNum -= smelldrop;
            if (FoodSmellNum < 0) FoodSmellNum = 0;
        }

        public void AntOneStep() 
        /* 1、决定调用函数决定蚂蚁的下一步方向
         * 2、蚂蚁移动
         * 3、如果找到食物,或者回到窝,进行响应的处理
         * 4、释放信息素
         * 5、记录走过的路径?
         */
        {
            AntDirection ddir;
            int tttx ttty;

            tttx = NowLocation.X;
            ttty = NowLocation.Y;
            ddir = NowDirection;

            ddir = NextDirection(tttx ttty ddir);

            switch (ddir)
            {
                case AntDirection.Up: ttty--;
                    break;
                case AntDirection.Down: ttty++;
                    break;
                case AntDirection.Left: tttx--;
                    break;
                case AntDirection.Right: tttx++;
                    break;
                default: break;
            } /* of switch dir */
            NowLocation.X = tttx;
            NowLocation.Y = ttty;
            NowDirection = ddir;

            // 窝处理
            if (tttx == PlayGround.HomeLocation.X && ttty == PlayGround.HomeLocation.Y)
            {
                HomeSmellNum = MaxSmell;
                ClearTrace();
                if (FoodNum > 0)
                {
                    PlayGround.HomeNum += Foo

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3497  2012-06-19 00:26  蚁群算法演示\Ant\Ant\Ant.csproj

     文件      22007  2009-05-13 20:48  蚁群算法演示\Ant\Ant\Antc.cs

     文件      45056  2009-05-13 23:23  蚁群算法演示\Ant\Ant\bin\Debug\Ant.exe

     文件      14328  2012-06-19 00:27  蚁群算法演示\Ant\Ant\bin\Debug\Ant.vshost.exe

     文件        490  2009-06-11 05:14  蚁群算法演示\Ant\Ant\bin\Debug\Ant.vshost.exe.manifest

     文件     160054  2009-05-13 22:54  蚁群算法演示\Ant\Ant\bin\Debug\AntMap01.bmp

     文件     160054  2009-05-13 23:02  蚁群算法演示\Ant\Ant\bin\Debug\AntMap02.bmp

     文件     120054  2009-05-14 08:46  蚁群算法演示\Ant\Ant\bin\Debug\AntMap04.bmp

     文件     120054  2009-05-14 08:04  蚁群算法演示\Ant\Ant\bin\Debug\Matrix01.bmp

     文件     132774  2009-05-13 23:17  蚁群算法演示\Ant\Ant\bin\Debug\SizeError.bmp

     文件       1145  2009-05-13 23:25  蚁群算法演示\Ant\Ant\bin\Debug\版本说明.txt

     文件       7630  2009-05-14 14:18  蚁群算法演示\Ant\Ant\bin\Debug\群群算法.txt

     文件      24644  2009-05-13 23:23  蚁群算法演示\Ant\Ant\Form1.cs

     文件      25447  2009-05-13 23:23  蚁群算法演示\Ant\Ant\Form1.Designer.cs

     文件       6611  2009-05-13 23:23  蚁群算法演示\Ant\Ant\Form1.resx

     文件       4608  2012-06-19 00:27  蚁群算法演示\Ant\Ant\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件       4645  2009-05-13 21:42  蚁群算法演示\Ant\Ant\PlayGround.cs

     文件        462  2009-05-10 21:19  蚁群算法演示\Ant\Ant\Program.cs

     文件       1154  2009-05-13 23:23  蚁群算法演示\Ant\Ant\Properties\AssemblyInfo.cs

     文件       2830  2012-06-19 00:26  蚁群算法演示\Ant\Ant\Properties\Resources.Designer.cs

     文件       5612  2009-05-10 21:19  蚁群算法演示\Ant\Ant\Properties\Resources.resx

     文件       1101  2012-06-19 00:26  蚁群算法演示\Ant\Ant\Properties\Settings.Designer.cs

     文件        249  2009-05-10 21:19  蚁群算法演示\Ant\Ant\Properties\Settings.settings

     文件        899  2012-06-19 00:26  蚁群算法演示\Ant\Ant.sln

     文件       2560  2012-06-19 00:30  蚁群算法演示\Ant\Ant.suo

     文件        948  2012-06-19 00:26  蚁群算法演示\Ant\UpgradeLog.xml

     文件       3348  2012-06-19 00:26  蚁群算法演示\Ant\_UpgradeReport_Files\UpgradeReport.css

     文件      12505  2008-01-11 01:25  蚁群算法演示\Ant\_UpgradeReport_Files\UpgradeReport.xslt

     文件         69  2012-06-19 00:26  蚁群算法演示\Ant\_UpgradeReport_Files\UpgradeReport_Minus.gif

     文件         71  2012-06-19 00:26  蚁群算法演示\Ant\_UpgradeReport_Files\UpgradeReport_Plus.gif

............此处省略13个文件信息

评论

共有 条评论