分享
 
 
 

模拟退火算法--求解货郎担问题(C#实现)(5)

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

//

this.label10.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(0)));

this.label10.Location = new System.Drawing.Point(168, 32);

this.label10.Name = "label10";

this.label10.Size = new System.Drawing.Size(256, 16);

this.label10.TabIndex = 7;

this.label10.Text = "Pls draw cities first !";

//

// button5

//

this.button5.Enabled = false;

this.button5.Location = new System.Drawing.Point(472, 24);

this.button5.Name = "button5";

this.button5.Size = new System.Drawing.Size(124, 23);

this.button5.TabIndex = 5;

this.button5.Text = "Draw Shortest Path";

this.button5.Click += new System.EventHandler(this.button5_Click);

//

// panel3

//

this.panel3.Controls.Add(this.pictureBox1);

this.panel3.Location = new System.Drawing.Point(52, 55);

this.panel3.Name = "panel3";

this.panel3.Size = new System.Drawing.Size(560, 448);

this.panel3.TabIndex = 4;

//

// pictureBox1

//

this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

this.pictureBox1.Location = new System.Drawing.Point(16, 16);

this.pictureBox1.Name = "pictureBox1";

this.pictureBox1.Size = new System.Drawing.Size(528, 416);

this.pictureBox1.TabIndex = 0;

this.pictureBox1.TabStop = false;

//

// button4

//

this.button4.Location = new System.Drawing.Point(64, 24);

this.button4.Name = "button4";

this.button4.TabIndex = 6;

this.button4.Text = "Draw City";

this.button4.Click += new System.EventHandler(this.button4_Click);

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);

this.ClientSize = new System.Drawing.Size(688, 561);

this.Controls.Add(this.tabControl1);

this.Menu = this.mainMenu1;

this.Name = "Form1";

this.Text = "Form1";

this.Load += new System.EventHandler(this.Form1_Load);

this.panel1.ResumeLayout(false);

this.panel2.ResumeLayout(false);

this.tabControl1.ResumeLayout(false);

this.TSP_SAA.ResumeLayout(false);

this.CITY_MAP.ResumeLayout(false);

this.panel3.ResumeLayout(false);

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// 应用程序的主入口点。

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}

private void Form1_Load(object sender, System.EventArgs e)

{

}

private void button1_Click(object sender, System.EventArgs e)

{

saa = new SAA();

saa.InitialPath();

saa.SetStartTemperature(Int32.Parse(textBox1.Text));

saa.SetMarkovLength(Int32.Parse(textBox2.Text));

saa.SetDiminishedRate(Double.Parse(textBox3.Text));

saa.SetDiminish_T_num(Int32.Parse(textBox4.Text));

saa.SetAIM(Int32.Parse(textBox5.Text));

DateTime start = DateTime.Now;

string path = saa.Anneal();

label9.Text = "" + (DateTime.Now-start);

richTextBox1.Text += " "+

"-----------------------------------------------------------------------------------------------"+

" "+

path;

button5.Enabled = true;

}

private void button2_Click(object sender, System.EventArgs e)

{

richTextBox1.Text = "";

}

private void button3_Click(object sender, System.EventArgs e)

{

FileStream file = File.Open("Result.txt",System.IO.FileMode.Create);

StreamWriter w = new StreamWriter(file);

w.Write(richTextBox1.Text);

w.Flush();

w.Close();

file.Close();

}

private void button4_Click(object sender, System.EventArgs e)

{

draw = new Thread(new ThreadStart(DrawCityMap));

draw.Start();

}

private void DrawCityMap()

{

int x , y ;

ReadData();

drawer = pictureBox1.CreateGraphics();

for(int i=0;i<143;i++)

{

x = city[i,0]/10;

y = city[i,1]/10;

drawer.DrawPie(Pens.Blue,x-2,y-2,4,4,0,360);

Thread.Sleep(10);

}

label10.Text = "Finish drawing city map !";

}

private void DrawShortestPath()

{

Point p1 , p2 ;

ArrayList bestPath = saa.bestPath;

if(bestPath==null)

return;

int pos1,pos2;

drawer = pictureBox1.CreateGraphics();

for(int i=0;i<143;i++)

{

pos1 = Int32.Parse(bestPath[i].ToString());

pos2 = Int32.Parse(bestPath[i+1].ToString());

p1 = new Point(city[pos1,0]/10,city[pos1,1]/10);

p2 = new Point(city[pos2,0]/10,city[pos2,1]/10);

drawer.DrawLine(Pens.Red,p1,p2);

Thread.Sleep(200);

}

pos1 = Int32.Parse(bestPath[143].ToString());

pos2 = Int32.Parse(bestPath[0].ToString());

p1 = new Point(city[pos1,0]/10,city[pos1,1]/10);

p2 = new Point(city[pos2,0]/10,city[pos2,1]/10);

drawer.DrawLine(Pens.Purple,p1,p2);

label1.Text = "Finish drawing the shortest path !";

}

private void button5_Click(object sender, System.EventArgs e)

{

draw = new Thread(new ThreadStart(DrawShortestPath));

draw.Start();

}

private void ReadData()

{

FileStream file = File.Open("city.txt",System.IO.FileMode.Open);

StreamReader r = new StreamReader(file);

string temp = r.ReadLine();

int i = 0;

int startP = 0;

int length = 0;

while(i!=144)

{

startP = 0;

length = 0;

startP = temp.IndexOf("x=");

length = temp.IndexOf(";")-startP-2;

city[i,0] = Int32.Parse(temp.Substring(startP+2,length));

startP = temp.IndexOf("y=");

length = temp.IndexOf(";",startP)-startP-2;

city[i,1] = Int32.Parse(temp.Substring(startP+2,length));

temp = r.ReadLine();

i++;

}

r.Close();

file.Close();

}

private void menuItem4_Click(object sender, System.EventArgs e)

{

Application.Exit();

}

}

}

第一頁    上一頁    第5頁/共5頁    下一頁    最後頁
第01頁 第02頁 第03頁 第04頁 第05頁 
 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有