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

📄 traveling salesman problem.cs

📁 Sample program for demonstrating Hopfield Neural Network to solve popular TSP
💻 CS
📖 第 1 页 / 共 4 页
字号:
// Traveling Salesman Problem via Hopfield-Tank Neural Network
// Written by David J. Stein, Esq. See "License.html" for terms and conditions of use.
//
// This module contains the front-end code for the Traveling Salesman Problem.

#region Using declarations 

using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.Diagnostics;

#endregion

namespace Hopfield_Tank_Neural_Network_Namespace {

	public class TravelingSalesmanProblem : System.Windows.Forms.Form	{

		#region Variables, initialization code, and Main

		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.PictureBox picMap;
		private System.Windows.Forms.ListView listDistances;
		private System.Windows.Forms.TextBox txtName;
		private System.Windows.Forms.Button btnLoadNetwork;
		private System.Windows.Forms.Button btnSaveNetwork;
		private System.Windows.Forms.Button btnClearNetwork;
		private System.Windows.Forms.Button btnAnalyzeStep;
		private System.Windows.Forms.Button btnAnalyzeFull;
		private System.Windows.Forms.Button btnClearSolution;
		private System.Windows.Forms.Button btnScaleCities;
		private System.Windows.Forms.TextBox txtTimeInterval;
		private System.Windows.Forms.TextBox txtdu0;
		private System.Windows.Forms.TextBox txtA;
		private System.Windows.Forms.TextBox txtB;
		private System.Windows.Forms.TextBox txtD;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.ListView listNetworkV;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox txtStatus;
		private System.Windows.Forms.GroupBox grpNetworkV;
		private System.Windows.Forms.Button btnResetSolution;
		private System.Windows.Forms.Button btnHFlip;
		private System.Windows.Forms.Button btnVFlip;
		private System.Windows.Forms.Button btnCWRotate;
		private System.Windows.Forms.Button btnCCWRotate;

		internal HopfieldTankNetwork network;
		private Thread thread = null;
		private System.Timers.Timer timerUpdate;
		private string strCurrentStatus;
		private Random r;
		private string XmlLoadErrors;
		private string strNetworkName = "Sample Network";
		private City movingCity = null;
		private int iMouseX = 0, iMouseY = 0;

		public TravelingSalesmanProblem()	{
			InitializeComponent();
			network = new HopfieldTankNetwork();
			r = new Random();
		}

		#region Windows Form Designer generated code

		protected override void Dispose(bool disposing)	{
			if (disposing) {
				if (components != null) {
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		private void InitializeComponent() {
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(TravelingSalesmanProblem));
			this.picMap = new System.Windows.Forms.PictureBox();
			this.btnClearNetwork = new System.Windows.Forms.Button();
			this.btnLoadNetwork = new System.Windows.Forms.Button();
			this.btnAnalyzeStep = new System.Windows.Forms.Button();
			this.btnAnalyzeFull = new System.Windows.Forms.Button();
			this.btnClearSolution = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.txtName = new System.Windows.Forms.TextBox();
			this.listDistances = new System.Windows.Forms.ListView();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.btnSaveNetwork = new System.Windows.Forms.Button();
			this.btnScaleCities = new System.Windows.Forms.Button();
			this.txtTimeInterval = new System.Windows.Forms.TextBox();
			this.txtdu0 = new System.Windows.Forms.TextBox();
			this.txtA = new System.Windows.Forms.TextBox();
			this.txtB = new System.Windows.Forms.TextBox();
			this.txtD = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.grpNetworkV = new System.Windows.Forms.GroupBox();
			this.listNetworkV = new System.Windows.Forms.ListView();
			this.label2 = new System.Windows.Forms.Label();
			this.txtStatus = new System.Windows.Forms.TextBox();
			this.timerUpdate = new System.Timers.Timer();
			this.btnResetSolution = new System.Windows.Forms.Button();
			this.btnHFlip = new System.Windows.Forms.Button();
			this.btnVFlip = new System.Windows.Forms.Button();
			this.btnCWRotate = new System.Windows.Forms.Button();
			this.btnCCWRotate = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.grpNetworkV.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.timerUpdate)).BeginInit();
			this.SuspendLayout();
			// 
			// picMap
			// 
			this.picMap.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.picMap.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.picMap.Location = new System.Drawing.Point(8, 8);
			this.picMap.Name = "picMap";
			this.picMap.Size = new System.Drawing.Size(468, 488);
			this.picMap.TabIndex = 0;
			this.picMap.TabStop = false;
			this.picMap.Click += new System.EventHandler(this.picMap_Click);
			this.picMap.Paint += new System.Windows.Forms.PaintEventHandler(this.picMap_Paint);
			this.picMap.MouseUp += new System.Windows.Forms.MouseEventHandler(this.picMap_MouseUp);
			this.picMap.MouseMove += new System.Windows.Forms.MouseEventHandler(this.picMap_MouseMove);
			this.picMap.MouseLeave += new System.EventHandler(this.picMap_MouseLeave);
			this.picMap.MouseDown += new System.Windows.Forms.MouseEventHandler(this.picMap_MouseDown);
			// 
			// btnClearNetwork
			// 
			this.btnClearNetwork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.btnClearNetwork.Location = new System.Drawing.Point(408, 504);
			this.btnClearNetwork.Name = "btnClearNetwork";
			this.btnClearNetwork.Size = new System.Drawing.Size(88, 23);
			this.btnClearNetwork.TabIndex = 7;
			this.btnClearNetwork.Text = "Clear Map";
			this.btnClearNetwork.Click += new System.EventHandler(this.btnClearNetwork_Click);
			// 
			// btnLoadNetwork
			// 
			this.btnLoadNetwork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnLoadNetwork.Location = new System.Drawing.Point(644, 208);
			this.btnLoadNetwork.Name = "btnLoadNetwork";
			this.btnLoadNetwork.Size = new System.Drawing.Size(88, 23);
			this.btnLoadNetwork.TabIndex = 13;
			this.btnLoadNetwork.Text = "Load Network";
			this.btnLoadNetwork.Click += new System.EventHandler(this.btnLoadNetwork_Click);
			// 
			// btnAnalyzeStep
			// 
			this.btnAnalyzeStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnAnalyzeStep.Location = new System.Drawing.Point(644, 112);
			this.btnAnalyzeStep.Name = "btnAnalyzeStep";
			this.btnAnalyzeStep.Size = new System.Drawing.Size(88, 23);
			this.btnAnalyzeStep.TabIndex = 9;
			this.btnAnalyzeStep.Text = "Analyze (Step)";
			this.btnAnalyzeStep.Click += new System.EventHandler(this.btnAnalyzeStep_Click);
			// 
			// btnAnalyzeFull
			// 
			this.btnAnalyzeFull.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnAnalyzeFull.Location = new System.Drawing.Point(644, 144);
			this.btnAnalyzeFull.Name = "btnAnalyzeFull";
			this.btnAnalyzeFull.Size = new System.Drawing.Size(88, 23);
			this.btnAnalyzeFull.TabIndex = 10;
			this.btnAnalyzeFull.Text = "Analyze (Full)";
			this.btnAnalyzeFull.Click += new System.EventHandler(this.btnAnalyzeFull_Click);
			// 
			// btnClearSolution
			// 
			this.btnClearSolution.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnClearSolution.Location = new System.Drawing.Point(644, 48);
			this.btnClearSolution.Name = "btnClearSolution";
			this.btnClearSolution.Size = new System.Drawing.Size(88, 23);
			this.btnClearSolution.TabIndex = 8;
			this.btnClearSolution.Text = "Clear Network";
			this.btnClearSolution.Click += new System.EventHandler(this.btnClearSolution_Click);
			// 
			// label1
			// 
			this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.label1.Location = new System.Drawing.Point(492, 48);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(40, 23);
			this.label1.TabIndex = 7;
			this.label1.Text = "Name";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// txtName
			// 
			this.txtName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.txtName.Location = new System.Drawing.Point(532, 48);
			this.txtName.Name = "txtName";
			this.txtName.Size = new System.Drawing.Size(104, 20);
			this.txtName.TabIndex = 0;
			this.txtName.Text = "Sample Network";
			this.txtName.TextChanged += new System.EventHandler(this.txtName_TextChanged);
			// 
			// listDistances
			// 
			this.listDistances.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.listDistances.AutoArrange = false;
			this.listDistances.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.listDistances.FullRowSelect = true;
			this.listDistances.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
			this.listDistances.Location = new System.Drawing.Point(8, 16);
			this.listDistances.MultiSelect = false;
			this.listDistances.Name = "listDistances";
			this.listDistances.Size = new System.Drawing.Size(264, 168);
			this.listDistances.TabIndex = 12;
			this.listDistances.View = System.Windows.Forms.View.Details;
			// 
			// groupBox1
			// 
			this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.groupBox1.Controls.Add(this.listDistances);
			this.groupBox1.Location = new System.Drawing.Point(740, 40);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(280, 192);
			this.groupBox1.TabIndex = 14;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Distances";
			this.groupBox1.Resize += new System.EventHandler(this.groupBox1_Resize);
			// 
			// btnSaveNetwork
			// 
			this.btnSaveNetwork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnSaveNetwork.Location = new System.Drawing.Point(644, 176);
			this.btnSaveNetwork.Name = "btnSaveNetwork";
			this.btnSaveNetwork.Size = new System.Drawing.Size(88, 23);
			this.btnSaveNetwork.TabIndex = 12;
			this.btnSaveNetwork.Text = "Save Network";
			this.btnSaveNetwork.Click += new System.EventHandler(this.btnSaveNetwork_Click);
			// 
			// btnScaleCities
			// 
			this.btnScaleCities.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.btnScaleCities.Location = new System.Drawing.Point(328, 504);
			this.btnScaleCities.Name = "btnScaleCities";
			this.btnScaleCities.Size = new System.Drawing.Size(72, 23);
			this.btnScaleCities.TabIndex = 14;
			this.btnScaleCities.Text = "Scale";
			this.btnScaleCities.Click += new System.EventHandler(this.btnScaleCities_Click);
			// 
			// txtTimeInterval
			// 
			this.txtTimeInterval.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.txtTimeInterval.Location = new System.Drawing.Point(532, 112);
			this.txtTimeInterval.Name = "txtTimeInterval";
			this.txtTimeInterval.Size = new System.Drawing.Size(104, 20);
			this.txtTimeInterval.TabIndex = 2;
			this.txtTimeInterval.Text = "0.0001";
			this.txtTimeInterval.TextChanged += new System.EventHandler(this.txtTimeInterval_TextChanged);
			// 
			// txtdu0
			// 
			this.txtdu0.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.txtdu0.Location = new System.Drawing.Point(532, 80);
			this.txtdu0.Name = "txtdu0";
			this.txtdu0.Size = new System.Drawing.Size(104, 20);
			this.txtdu0.TabIndex = 1;
			this.txtdu0.Text = "0.001";
			this.txtdu0.TextChanged += new System.EventHandler(this.txtdu0_TextChanged);
			// 
			// txtA
			// 
			this.txtA.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.txtA.Location = new System.Drawing.Point(532, 144);
			this.txtA.Name = "txtA";
			this.txtA.Size = new System.Drawing.Size(104, 20);
			this.txtA.TabIndex = 3;
			this.txtA.Text = "1.2";
			this.txtA.TextChanged += new System.EventHandler(this.txtA_TextChanged);
			// 
			// txtB
			// 
			this.txtB.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.txtB.Location = new System.Drawing.Point(532, 176);
			this.txtB.Name = "txtB";
			this.txtB.Size = new System.Drawing.Size(104, 20);

⌨️ 快捷键说明

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