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

📄 frmparamset.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>
	/// frmparamset 的摘要说明。
	/// </summary>
	public class frmparamset : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.TextBox fname;
		private System.Windows.Forms.TextBox rname;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox tnum;
		private System.Windows.Forms.TextBox rnum;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox ppc;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox ppm;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.TextBox pnum;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Label label8;

		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmparamset(PARAMETER param,GA_PARAMETER gaparam)
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();


			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
			param.CourseFile="coursedata.txt";
			param.RoomFile="roomdata.txt";
			param.TimeSolt=20;
			param.cms=20;
			gaparam.pn=100;
			gaparam.Nn=100;
			gaparam.Pc=0.9f;
			gaparam.Pm=0.2f;			
			fname.Text=param.CourseFile;
			rname.Text=param.RoomFile;			
			tnum.Text =param.TimeSolt.ToString();
			rnum.Text=gaparam.Nn.ToString();
			pnum.Text=gaparam.pn.ToString();
			ppc.Text=gaparam.Pc.ToString();
			ppm.Text=gaparam.Pm.ToString();
			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.label1 = new System.Windows.Forms.Label();
			this.fname = new System.Windows.Forms.TextBox();
			this.button2 = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.rname = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.tnum = new System.Windows.Forms.TextBox();
			this.rnum = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.ppc = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.ppm = new System.Windows.Forms.TextBox();
			this.label6 = new System.Windows.Forms.Label();
			this.pnum = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.label8 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(40, 8);
			this.label1.Name = "label1";
			this.label1.TabIndex = 0;
			this.label1.Text = "课程数据文件";
			// 
			// fname
			// 
			this.fname.Location = new System.Drawing.Point(40, 32);
			this.fname.Name = "fname";
			this.fname.Size = new System.Drawing.Size(104, 21);
			this.fname.TabIndex = 1;
			this.fname.Text = "cdata.txt";
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(223, 216);
			this.button2.Name = "button2";
			this.button2.TabIndex = 3;
			this.button2.Text = "默认";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(111, 216);
			this.button1.Name = "button1";
			this.button1.TabIndex = 2;
			this.button1.Text = "确定";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// rname
			// 
			this.rname.Location = new System.Drawing.Point(256, 32);
			this.rname.Name = "rname";
			this.rname.Size = new System.Drawing.Size(104, 21);
			this.rname.TabIndex = 5;
			this.rname.Text = "rdata.txt";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(256, 8);
			this.label2.Name = "label2";
			this.label2.TabIndex = 4;
			this.label2.Text = "教室数据文件";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(40, 56);
			this.label3.Name = "label3";
			this.label3.TabIndex = 6;
			this.label3.Text = "时间格数";
			// 
			// tnum
			// 
			this.tnum.Location = new System.Drawing.Point(40, 80);
			this.tnum.Name = "tnum";
			this.tnum.Size = new System.Drawing.Size(104, 21);
			this.tnum.TabIndex = 7;
			this.tnum.Text = "20";
			// 
			// rnum
			// 
			this.rnum.Location = new System.Drawing.Point(40, 136);
			this.rnum.Name = "rnum";
			this.rnum.Size = new System.Drawing.Size(104, 21);
			this.rnum.TabIndex = 9;
			this.rnum.Text = "50";
			this.rnum.TextChanged += new System.EventHandler(this.rnum_TextChanged);
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(40, 112);
			this.label4.Name = "label4";
			this.label4.TabIndex = 8;
			this.label4.Text = "叠代次数";
			this.label4.Click += new System.EventHandler(this.label4_Click);
			// 
			// ppc
			// 
			this.ppc.Location = new System.Drawing.Point(40, 184);
			this.ppc.Name = "ppc";
			this.ppc.Size = new System.Drawing.Size(104, 21);
			this.ppc.TabIndex = 11;
			this.ppc.Text = "0.8";
			this.ppc.TextChanged += new System.EventHandler(this.ppc_TextChanged);
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(40, 160);
			this.label5.Name = "label5";
			this.label5.TabIndex = 10;
			this.label5.Text = "交叉率";
			this.label5.Click += new System.EventHandler(this.label5_Click);
			// 
			// ppm
			// 
			this.ppm.Location = new System.Drawing.Point(256, 184);
			this.ppm.Name = "ppm";
			this.ppm.Size = new System.Drawing.Size(104, 21);
			this.ppm.TabIndex = 13;
			this.ppm.Text = "0.1";
			this.ppm.TextChanged += new System.EventHandler(this.ppm_TextChanged);
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(256, 160);
			this.label6.Name = "label6";
			this.label6.TabIndex = 12;
			this.label6.Text = "变异率";
			this.label6.Click += new System.EventHandler(this.label6_Click);
			// 
			// pnum
			// 
			this.pnum.Location = new System.Drawing.Point(256, 80);
			this.pnum.Name = "pnum";
			this.pnum.Size = new System.Drawing.Size(104, 21);
			this.pnum.TabIndex = 15;
			this.pnum.Text = "50";
			this.pnum.TextChanged += new System.EventHandler(this.pnum_TextChanged);
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(256, 56);
			this.label7.Name = "label7";
			this.label7.TabIndex = 14;
			this.label7.Text = "种群个数";
			this.label7.Click += new System.EventHandler(this.label7_Click);
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(256, 128);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(104, 21);
			this.textBox1.TabIndex = 17;
			this.textBox1.Text = "50";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(256, 104);
			this.label8.Name = "label8";
			this.label8.TabIndex = 16;
			this.label8.Text = "公共考试科目";
			// 
			// frmparamset
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.SystemColors.ActiveBorder;
			this.ClientSize = new System.Drawing.Size(408, 261);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.pnum);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.ppm);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.ppc);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.rnum);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.tnum);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.rname);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.fname);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmparamset";
			this.Text = "frmparamset";
			this.Load += new System.EventHandler(this.frmparamset_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void button1_Click(object sender, System.EventArgs e)
		{
	this.Close();
		}
		public void GetParamset(out PARAMETER param,out GA_PARAMETER gaparam)
		{
			param.CourseFile=fname.Text;
			param.RoomFile=rname.Text;
			param.TimeSolt=Int32.Parse(tnum.Text);
			gaparam.pn=Int32.Parse(pnum.Text);
			gaparam.Nn=Int32.Parse(rnum.Text);
			param.cms=Int32.Parse(this.textBox1.Text);
			gaparam.Pm=(float)Decimal.Parse(ppm.Text);
			gaparam.Pc=(float)Decimal.Parse(ppc.Text);
			param.course=new int[200,150];//需要改
			param.room=new int[3];
			param.nroom=0;
			param.coursenum=0;           
			param.check=true;
			
		
			FileStream strm;
			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");
			}
			
			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");

			}

			
		
			param.D =new int[param.coursenum,param.coursenum];//参数D设置
			for(int i=0;i<param.coursenum;i++)
			{
				int [] tt=new int [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 frmparamset_Load(object sender, System.EventArgs e)
		{
		
		}

		private void label7_Click(object sender, System.EventArgs e)
		{
		
		}

		private void rnum_TextChanged(object sender, System.EventArgs e)
		{
		
		}

		private void label4_Click(object sender, System.EventArgs e)
		{
		
		}

		private void ppc_TextChanged(object sender, System.EventArgs e)
		{
		
		}

		private void label5_Click(object sender, System.EventArgs e)
		{
		
		}

		private void ppm_TextChanged(object sender, System.EventArgs e)
		{
		
		}

		private void label6_Click(object sender, System.EventArgs e)
		{
		
		}

		private void pnum_TextChanged(object sender, System.EventArgs e)
		{
		
		}




		
	}
}

⌨️ 快捷键说明

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