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

📄 frmsaparam.cs

📁 遗传算法求解大学考试时间表问题
💻 CS
字号:
using System;
using System.IO;
using System.Text;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace timetabling
{
	/// <summary>
	/// frmsaparam 的摘要说明。
	/// </summary>
	public class frmsaparam : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox endt;
		private System.Windows.Forms.TextBox maxt;
		private System.Windows.Forms.TextBox startt;
		private System.Windows.Forms.TextBox rdata;
		private System.Windows.Forms.TextBox cdata;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.TextBox tnum;
		private System.Windows.Forms.Label label5;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmsaparam(PARAMETER param,SA_PARAMETER saparam)
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
			param.CourseFile="coursedata.txt";
			param.RoomFile="roomdata.txt";
			param.TimeSolt=20;
			param.cms=20;
			saparam.endn=50;
			saparam.Nn=4000;
			saparam.t=2500.0f;
			this.cdata.Text=param.CourseFile;
			this.rdata.Text=param.RoomFile;			
			this.startt.Text =saparam.t.ToString();
			this.endt.Text=saparam.endn.ToString();
			this.maxt.Text=saparam.Nn.ToString();
			this.tnum.Text=param.TimeSolt.ToString();
			this.textBox1.Text=param.cms.ToString();
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.endt = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.maxt = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.startt = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.rdata = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.button2 = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.cdata = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.label8 = new System.Windows.Forms.Label();
			this.tnum = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// endt
			// 
			this.endt.Location = new System.Drawing.Point(248, 88);
			this.endt.Name = "endt";
			this.endt.Size = new System.Drawing.Size(104, 21);
			this.endt.TabIndex = 33;
			this.endt.Text = "50";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(248, 69);
			this.label7.Name = "label7";
			this.label7.TabIndex = 32;
			this.label7.Text = "收敛准则";
			// 
			// maxt
			// 
			this.maxt.Location = new System.Drawing.Point(40, 144);
			this.maxt.Name = "maxt";
			this.maxt.Size = new System.Drawing.Size(104, 21);
			this.maxt.TabIndex = 27;
			this.maxt.Text = "50";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(40, 120);
			this.label4.Name = "label4";
			this.label4.TabIndex = 26;
			this.label4.Text = "最大叠代次数";
			// 
			// startt
			// 
			this.startt.Location = new System.Drawing.Point(40, 88);
			this.startt.Name = "startt";
			this.startt.Size = new System.Drawing.Size(104, 21);
			this.startt.TabIndex = 25;
			this.startt.Text = "20";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(40, 69);
			this.label3.Name = "label3";
			this.label3.TabIndex = 24;
			this.label3.Text = "初始温度";
			// 
			// rdata
			// 
			this.rdata.Location = new System.Drawing.Point(248, 45);
			this.rdata.Name = "rdata";
			this.rdata.Size = new System.Drawing.Size(104, 21);
			this.rdata.TabIndex = 23;
			this.rdata.Text = "rdata.txt";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(248, 21);
			this.label2.Name = "label2";
			this.label2.TabIndex = 22;
			this.label2.Text = "教室数据文件";
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(216, 229);
			this.button2.Name = "button2";
			this.button2.TabIndex = 21;
			this.button2.Text = "默认";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(104, 229);
			this.button1.Name = "button1";
			this.button1.TabIndex = 20;
			this.button1.Text = "确定";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// cdata
			// 
			this.cdata.Location = new System.Drawing.Point(40, 45);
			this.cdata.Name = "cdata";
			this.cdata.Size = new System.Drawing.Size(104, 21);
			this.cdata.TabIndex = 19;
			this.cdata.Text = "cdata.txt";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(40, 21);
			this.label1.Name = "label1";
			this.label1.TabIndex = 18;
			this.label1.Text = "课程数据文件";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(40, 192);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(104, 21);
			this.textBox1.TabIndex = 35;
			this.textBox1.Text = "50";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(40, 168);
			this.label8.Name = "label8";
			this.label8.TabIndex = 34;
			this.label8.Text = "公共考试科目";
			// 
			// tnum
			// 
			this.tnum.Location = new System.Drawing.Point(248, 140);
			this.tnum.Name = "tnum";
			this.tnum.Size = new System.Drawing.Size(104, 21);
			this.tnum.TabIndex = 37;
			this.tnum.Text = "20";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(248, 116);
			this.label5.Name = "label5";
			this.label5.TabIndex = 36;
			this.label5.Text = "时间格数";
			// 
			// frmsaparam
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(392, 277);
			this.Controls.Add(this.tnum);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.endt);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.maxt);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.startt);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.rdata);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.cdata);
			this.Controls.Add(this.label1);
			this.Name = "frmsaparam";
			this.Text = "frmsaparam";
			this.ResumeLayout(false);

		}
		#endregion

		public void GetParamset(out PARAMETER param,out SA_PARAMETER saparam)
		{
			param.CourseFile=this.cdata.Text;
			param.RoomFile=this.rdata.Text;
			param.TimeSolt=Int32.Parse(this.tnum.Text);
			saparam.t=(float)Decimal.Parse (this.startt.Text);
			saparam.endn=Int32.Parse(this.endt.Text);
			saparam.Nn=Int32.Parse(this.maxt.Text);
			param.cms=Int32.Parse(this.textBox1.Text);
			param.course=new int[100,100];
			param.room=new int[3];
			param.nroom=0;
			param.coursenum=0;
			param.D =new int[param.coursenum,param.coursenum];
			param.check=true;
			
		
			FileStream strm;
			
			try//读取课程文件
			{
				strm=new FileStream(param.CourseFile,FileMode.Open,FileAccess.ReadWrite);
				StreamReader sr;
				sr=new StreamReader(strm);
				string temp = "";
				int i=0;
				temp = sr.ReadLine();
				while(temp!="end")
				{
					
					
					int j=0;
					string tt="";
					foreach(char t in temp)
					{
						if (t!=',')
						{
							tt+=t;
						}
						else
						{	
							param.course[i,j]=Int32.Parse(tt);							
							j++;
							tt="";							
						}							 
					}					
					i++;
					temp = sr.ReadLine();
				}
				param.coursenum=i;
				strm.Flush();
				strm.Close();
				   			  
			}
			catch(Exception e)
			{
				MessageBox.Show(e.Message,"erro");
				MessageBox.Show("不能打开文件,请重新设置参数","erro");

			}

			try//读取考场数据文件
			{
				strm=new FileStream(param.RoomFile,FileMode.Open,FileAccess.ReadWrite);
				StreamReader sr=new StreamReader(strm);

				string temp = "";
				int i=0;
				temp = sr.ReadLine();
				while(temp!="end")
				{
					string tt="";
					foreach(char t in temp)
					{
						if(t!=',')
						{
							tt+=t;
						}
					}
					param.room[i]=(int) Int32.Parse(tt);
					i++;	
					temp = sr.ReadLine();
				}
				param.nroom=param.room[0]+param.room[1]*2+param.room[2]*4;
				
				strm.Flush();
				sr.Close();	 
			}
			catch(Exception e)
			{
				MessageBox.Show(e.Message,"erro");
				MessageBox.Show("不能打开文件,请重新设置参数","erro");
			}
			param.D =new int[param.coursenum,param.coursenum];//参数D设置
			for(int i=0;i<param.coursenum;i++)
			{
				int [] tt=new int [100];//注意100这个参数
				for(int t=0;t<100;t++) tt[t]=param.course[i,t];
				foreach(int a in tt)
				{
					for(int j=i;j<param.coursenum;j++)
					{
						int [] kk=new int [100];
						for(int k=0;k<100;k++) kk[k]=param.course[j,k];
						foreach(int b in kk)
						{
							if(b==0) break;
							if(a==b) param.D[i,j]+=1;
						}
					}
					if(a==0) break;
				}

			}
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
		    this.Close();
		}
	}
}

⌨️ 快捷键说明

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