资源简介

一个计算TSP问题模拟退火算法的小例子,并能绘制结果和迭代过程图。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZedGraph;

namespace SAA
{
    public partial class Form1 : Form
    {
        double[] point = new double[5 2];
        double[] distance = new double[5 5];
        int Number = 5;
        int[] order = new int[5];
        public Form1()
        {
            InitializeComponent();
        }
        public void init()
        {
            point[0 0] = 0.4;
            point[0 1] = 0.1;
            point[1 0] = 0.6;
            point[1 1] = 0.3;
            point[2 0] = 0.2;
            point[2 1] = 0.5;
            point[3 0] = 0.5;
            point[3 1] = 0.8;
            point[4 0] = 0.8;
            point[4 1] = 0.7;
            for (int i = 0; i < Number; i++)
            {
                order[i] = i;
                for (int j = 0; j < Number; j++)
                {
                    distance[i j] = Math.Sqrt((point[i 0] - point[j 0]) * (point[i 0] - point[j 0]) + (point[i 1] - point[j 1]) * (point[i 1] - point[j 1]));
                }
            }
        }
        private void button1_Click(object sender EventArgs e)
        {
            init();
            SimulateAnnealArithmetic saa = new SimulateAnnealArithmetic(Number order distance);
            saa.SAA();
            drawGraph(graph1 order);
            drawGraph(graph2 saa.List);
        }

        private void drawGraph(ZedGraphControl graphint[] drawOrder)
        {
            GraphPane myPane = graph.GraphPane;
            myPane.title.Text = “路径“;
            myPane.XAxis.IsVisible = false;
            myPane.YAxis.IsVisible = false;
            myPane.Legend.IsVisible = false;
            PointPairList list1 = new PointPairList();
            for (int i = 0; i < Number; i++)
            {
                list1.Add(point[drawOrder[i] 0] point[drawOrder[i] 1]);
            }
            list1.Add(point[drawOrder[0] 0] point[drawOrder[0] 1]);
            LineItem myCurve = myPane.AddCurve(“Porsche“ list1 Color.Red SymbolType.Default);
            myPane.AxisChange(this.CreateGraphics());
            graph.Invalidate();
        }
        private void drawGraph(ZedGraphControl graphPointPairList list)
        {
            GraphPane myPane = graph.GraphPane;
            myPane.title.Text = “距离“;
            myPane.XAxis.title.Text = “迭代次数“;
            myPane.YAxis.title.Text = “距离“;
            myPane.Legend.IsVisible = false;
            
            LineItem myCurve = myPane.AddCurve(“Porsche“ list Color.Blue SymbolType.Default);
            myCurve.Symbol.Type = SymbolType.None;
            myPane.AxisChange(this.CreateGraphics());
            graph.Invalidate();
        }
    }
}

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

     文件        898  2011-03-22 10:24  SAA.sln

    ..A..H.     13824  2011-03-24 10:59  SAA.suo

     文件      24576  2011-03-24 10:58  SAA\bin\Debug\SAA.exe

     文件      36352  2011-03-24 10:58  SAA\bin\Debug\SAA.pdb

     文件       5632  2005-12-08 14:51  SAA\bin\Debug\SAA.vshost.exe

     文件     307200  2008-12-12 16:01  SAA\bin\Debug\ZedGraph.dll

     文件       2924  2011-03-24 10:58  SAA\Form1.cs

     文件       3527  2011-03-24 10:58  SAA\Form1.Designer.cs

     文件       5814  2011-03-24 10:58  SAA\Form1.resx

     文件       5210  2011-03-24 10:29  SAA\obj\Debug\ResolveAssemblyReference.cache

     文件        842  2011-03-24 10:58  SAA\obj\Debug\SAA.csproj.GenerateResource.Cache

     文件      24576  2011-03-24 10:58  SAA\obj\Debug\SAA.exe

     文件        180  2011-03-24 10:58  SAA\obj\Debug\SAA.Form1.resources

     文件      36352  2011-03-24 10:58  SAA\obj\Debug\SAA.pdb

     文件        180  2011-03-22 10:34  SAA\obj\Debug\SAA.Properties.Resources.resources

     文件        240  2011-03-24 11:08  SAA\obj\SAA.csproj.FileList.txt

     文件        462  2011-03-22 10:24  SAA\Program.cs

     文件       1178  2011-03-22 10:24  SAA\Properties\AssemblyInfo.cs

     文件       2860  2011-03-22 10:24  SAA\Properties\Resources.Designer.cs

     文件       5612  2011-03-22 10:24  SAA\Properties\Resources.resx

     文件       1086  2011-03-22 10:24  SAA\Properties\Settings.Designer.cs

     文件        249  2011-03-22 10:24  SAA\Properties\Settings.settings

     文件       6076  2011-03-24 10:53  SAA\SAA.cs

     文件       3384  2011-03-24 10:29  SAA\SAA.csproj

     目录          0  2011-03-24 08:55  SAA\obj\Debug\Refactor

     目录          0  2011-03-22 10:24  SAA\obj\Debug\TempPE

     目录          0  2011-03-24 10:19  SAA\bin\Debug

     目录          0  2011-03-24 10:58  SAA\obj\Debug

     目录          0  2011-03-24 09:37  SAA\bin

     目录          0  2011-03-22 10:34  SAA\obj

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

评论

共有 条评论