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

📄 traveling salesman problem.cs

📁 Sample program for demonstrating Hopfield Neural Network to solve popular TSP
💻 CS
📖 第 1 页 / 共 4 页
字号:
			this.txtB.TabIndex = 4;
			this.txtB.Text = "1.2";
			this.txtB.TextChanged += new System.EventHandler(this.txtB_TextChanged);
			// 
			// txtD
			// 
			this.txtD.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.txtD.Location = new System.Drawing.Point(532, 208);
			this.txtD.Name = "txtD";
			this.txtD.Size = new System.Drawing.Size(104, 20);
			this.txtD.TabIndex = 6;
			this.txtD.Text = "1.5";
			this.txtD.TextChanged += new System.EventHandler(this.txtD_TextChanged);
			// 
			// label3
			// 
			this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.label3.Location = new System.Drawing.Point(492, 80);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(32, 23);
			this.label3.TabIndex = 25;
			this.label3.Text = "du0";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label5
			// 
			this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.label5.Location = new System.Drawing.Point(492, 144);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(32, 23);
			this.label5.TabIndex = 27;
			this.label5.Text = "A";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label6
			// 
			this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.label6.Location = new System.Drawing.Point(492, 176);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(32, 23);
			this.label6.TabIndex = 28;
			this.label6.Text = "B";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label8
			// 
			this.label8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.label8.Location = new System.Drawing.Point(492, 208);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(32, 23);
			this.label8.TabIndex = 30;
			this.label8.Text = "D";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label4
			// 
			this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.label4.Location = new System.Drawing.Point(492, 112);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(32, 23);
			this.label4.TabIndex = 26;
			this.label4.Text = "dt";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// grpNetworkV
			// 
			this.grpNetworkV.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.grpNetworkV.Controls.Add(this.listNetworkV);
			this.grpNetworkV.Location = new System.Drawing.Point(484, 240);
			this.grpNetworkV.Name = "grpNetworkV";
			this.grpNetworkV.Size = new System.Drawing.Size(536, 288);
			this.grpNetworkV.TabIndex = 16;
			this.grpNetworkV.TabStop = false;
			this.grpNetworkV.Text = "Network (V and u)";
			// 
			// listNetworkV
			// 
			this.listNetworkV.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.listNetworkV.AutoArrange = false;
			this.listNetworkV.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.listNetworkV.FullRowSelect = true;
			this.listNetworkV.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
			this.listNetworkV.Location = new System.Drawing.Point(8, 16);
			this.listNetworkV.MultiSelect = false;
			this.listNetworkV.Name = "listNetworkV";
			this.listNetworkV.Size = new System.Drawing.Size(520, 264);
			this.listNetworkV.TabIndex = 12;
			this.listNetworkV.View = System.Windows.Forms.View.Details;
			this.listNetworkV.Resize += new System.EventHandler(this.listNetworkV_Resize);
			// 
			// label2
			// 
			this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.label2.Location = new System.Drawing.Point(484, 8);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(56, 23);
			this.label2.TabIndex = 31;
			this.label2.Text = "Status:";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// txtStatus
			// 
			this.txtStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.txtStatus.Location = new System.Drawing.Point(540, 8);
			this.txtStatus.Name = "txtStatus";
			this.txtStatus.ReadOnly = true;
			this.txtStatus.Size = new System.Drawing.Size(480, 20);
			this.txtStatus.TabIndex = 32;
			this.txtStatus.Text = "";
			// 
			// timerUpdate
			// 
			this.timerUpdate.Enabled = true;
			this.timerUpdate.Interval = 200;
			this.timerUpdate.SynchronizingObject = this;
			this.timerUpdate.Elapsed += new System.Timers.ElapsedEventHandler(this.timerUpdate_Elapsed);
			// 
			// btnResetSolution
			// 
			this.btnResetSolution.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnResetSolution.Location = new System.Drawing.Point(644, 80);
			this.btnResetSolution.Name = "btnResetSolution";
			this.btnResetSolution.Size = new System.Drawing.Size(88, 23);
			this.btnResetSolution.TabIndex = 33;
			this.btnResetSolution.Text = "Reset Network";
			this.btnResetSolution.Click += new System.EventHandler(this.btnResetSolution_Click);
			// 
			// btnHFlip
			// 
			this.btnHFlip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.btnHFlip.Location = new System.Drawing.Point(8, 504);
			this.btnHFlip.Name = "btnHFlip";
			this.btnHFlip.Size = new System.Drawing.Size(64, 24);
			this.btnHFlip.TabIndex = 34;
			this.btnHFlip.Text = "H Flip";
			this.btnHFlip.Click += new System.EventHandler(this.btnHFlip_Click);
			// 
			// btnVFlip
			// 
			this.btnVFlip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.btnVFlip.Location = new System.Drawing.Point(80, 504);
			this.btnVFlip.Name = "btnVFlip";
			this.btnVFlip.Size = new System.Drawing.Size(64, 24);
			this.btnVFlip.TabIndex = 35;
			this.btnVFlip.Text = "V Flip";
			this.btnVFlip.Click += new System.EventHandler(this.btnVFlip_Click);
			// 
			// btnCWRotate
			// 
			this.btnCWRotate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.btnCWRotate.Location = new System.Drawing.Point(152, 504);
			this.btnCWRotate.Name = "btnCWRotate";
			this.btnCWRotate.Size = new System.Drawing.Size(80, 24);
			this.btnCWRotate.TabIndex = 36;
			this.btnCWRotate.Text = "CW Rotate";
			this.btnCWRotate.Click += new System.EventHandler(this.btnCWRotate_Click);
			// 
			// btnCCWRotate
			// 
			this.btnCCWRotate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.btnCCWRotate.Location = new System.Drawing.Point(240, 504);
			this.btnCCWRotate.Name = "btnCCWRotate";
			this.btnCCWRotate.Size = new System.Drawing.Size(80, 24);
			this.btnCCWRotate.TabIndex = 37;
			this.btnCCWRotate.Text = "CCW Rotate";
			this.btnCCWRotate.Click += new System.EventHandler(this.btnCCWRotate_Click);
			// 
			// TravelingSalesmanProblem
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(1028, 534);
			this.Controls.Add(this.btnCCWRotate);
			this.Controls.Add(this.btnCWRotate);
			this.Controls.Add(this.btnVFlip);
			this.Controls.Add(this.btnHFlip);
			this.Controls.Add(this.btnResetSolution);
			this.Controls.Add(this.txtStatus);
			this.Controls.Add(this.txtD);
			this.Controls.Add(this.txtB);
			this.Controls.Add(this.txtA);
			this.Controls.Add(this.txtdu0);
			this.Controls.Add(this.txtTimeInterval);
			this.Controls.Add(this.txtName);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.btnScaleCities);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.btnClearSolution);
			this.Controls.Add(this.btnAnalyzeFull);
			this.Controls.Add(this.btnAnalyzeStep);
			this.Controls.Add(this.btnSaveNetwork);
			this.Controls.Add(this.btnLoadNetwork);
			this.Controls.Add(this.btnClearNetwork);
			this.Controls.Add(this.picMap);
			this.Controls.Add(this.grpNetworkV);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "TravelingSalesmanProblem";
			this.Text = "Traveling Salesman Problem via Hopfield-Tank Neural Network";
			this.Resize += new System.EventHandler(this.TravelingSalesmanProblem_Resize);
			this.Closing += new System.ComponentModel.CancelEventHandler(this.TravelingSalesmanProblem_Closing);
			this.Load += new System.EventHandler(this.TravelingSalesmanProblem_Load);
			this.groupBox1.ResumeLayout(false);
			this.grpNetworkV.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.timerUpdate)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		[STAThread]
		static void Main() {
			Application.Run(new TravelingSalesmanProblem());
		}

		#endregion

		#region Button-click event handlers

		private void txtName_TextChanged(object sender, System.EventArgs e) {
			network.name = txtName.Text;
		}

		private void btnClearNetwork_Click(object sender, System.EventArgs e) {
			network.cities = new ArrayList();
			strNetworkName = txtName.Text = "Sample Network";
			picMap.Refresh();
			SetDistanceList();
			SetNetworkLists();
		}

		private void btnScaleCities_Click(object sender, System.EventArgs e) {
			// find largest coordinates
			double dMaxX = 0;
			double dMaxY = 0;
			double dMinX = picMap.Width;
			double dMinY = picMap.Height;
			foreach (object cityobject in network.cities) {
				dMaxX = Math.Max(dMaxX, ((City) cityobject).x);
				dMaxY = Math.Max(dMaxY, ((City) cityobject).y);
				dMinX = Math.Min(dMinX, ((City) cityobject).x);
				dMinY = Math.Min(dMinY, ((City) cityobject).y);
			}
			if (dMaxX == dMinX) {
				dMinX = picMap.Width / 2;
				dMaxX = 0;
			}
			else
				dMaxX = (picMap.Width - 40) / (dMaxX - dMinX);
			if (dMaxY == dMinY) {
				dMinY = picMap.Height / 2;
				dMaxY = 0;
			}
			else
				dMaxY = (picMap.Height - 40) / (dMaxY - dMinY);
			// adjust cities
			foreach (object cityobject in network.cities) {
				City city = (City) cityobject;
				city.x = 20 + (city.x - dMinX) * dMaxX;
				city.y = 20 + (city.y - dMinY) * dMaxY;
			}
			// show new coords, etc.
			picMap.Refresh();
			listDistances.Refresh();
		}

		private void txtTimeInterval_TextChanged(object sender, System.EventArgs e) {
			try {
				network.dTimeInterval = Double.Parse(txtTimeInterval.Text);
			} catch (Exception ex) {}
		}

		private void btnAnalyzeStep_Click(object sender, System.EventArgs e) {
			txtStatus.Text = network.Analyze();
			txtStatus.Refresh();
			SetNetworkLists();
			picMap.Refresh();
		}

		private void btnClearSolution_Click(object sender, System.EventArgs e) {
			network.Initialize(r.Next(99999));
			SetNetworkLists();
			picMap.Refresh();
		}

		private void txtdu0_TextChanged(object sender, System.EventArgs e) {
			try { network.u0variation = double.Parse(txtdu0.Text); } catch (Exception ex) {}
		}

		//private void txtA_TextChanged(object sender, System.EventArgs e) {
		//	try { network.A = double.Parse(txtA.Text); } catch (Exception ex) {}

⌨️ 快捷键说明

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