//
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();
}
}
}