p align="left">// numericUpDown4 // this.numericUpDown4.Location = new System.Drawing.Point(269, 24); this.numericUpDown4.Minimum = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown4.Name = "numericUpDown4"; this.numericUpDown4.Size = new System.Drawing.Size(72, 20); this.numericUpDown4.TabIndex = 7; this.numericUpDown4.Value = new decimal(new int[] { 5, 0, 0, 0}); this.numericUpDown4.ValueChanged += new System.EventHandler(this.numericUpDown4_ValueChanged); this.numericUpDown4.Enter += new System.EventHandler(this.numericUpDown4_ValueChanged); // // numericUpDown3 // this.numericUpDown3.Location = new System.Drawing.Point(151, 24); this.numericUpDown3.Minimum = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown3.Name = "numericUpDown3"; this.numericUpDown3.Size = new System.Drawing.Size(72, 20); this.numericUpDown3.TabIndex = 6; this.numericUpDown3.Value = new decimal(new int[] { 10, 0, 0, 0}); this.numericUpDown3.ValueChanged += new System.EventHandler(this.numericUpDown3_ValueChanged); this.numericUpDown3.Enter += new System.EventHandler(this.numericUpDown3_ValueChanged); // // dataGrid1 // this.dataGrid1.AllowNavigation = false; this.dataGrid1.AllowSorting = false; this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.dataGrid1.CaptionVisible = false; this.dataGrid1.ColumnHeadersVisible = false; this.dataGrid1.DataMember = ""; this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataGrid1.Location = new System.Drawing.Point(0, 19); this.dataGrid1.Name = "dataGrid1"; this.dataGrid1.ParentRowsVisible = false; this.dataGrid1.ReadOnly = true; this.dataGrid1.RowHeadersVisible = false; this.dataGrid1.Size = new System.Drawing.Size(561, 230); this.dataGrid1.TabIndex = 6; // // dataGrid2 // this.dataGrid2.AllowNavigation = false; this.dataGrid2.AllowSorting = false; this.dataGrid2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.dataGrid2.CaptionVisible = false; this.dataGrid2.ColumnHeadersVisible = false; this.dataGrid2.DataMember = ""; this.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataGrid2.Location = new System.Drawing.Point(0, 266); this.dataGrid2.Name = "dataGrid2"; this.dataGrid2.ParentRowsVisible = false; this.dataGrid2.ReadOnly = true; this.dataGrid2.RowHeadersVisible = false; this.dataGrid2.Size = new System.Drawing.Size(561, 231); this.dataGrid2.TabIndex = 7; // // fastLine2 // // // // this.fastLine2.LinePen.Color = System.Drawing.Color.Green; this.fastLine2.Marks.Callout.ArrowHead = Steema.TeeChart.Styles.ArrowHeadStyles.None; this.fastLine2.Marks.Callout.ArrowHeadSize = 8; // // // this.fastLine2.Marks.Callout.Brush.Color = System.Drawing.Color.Black; this.fastLine2.Marks.Callout.Distance = 0; this.fastLine2.Marks.Callout.Draw3D = false; this.fastLine2.Marks.Callout.Length = 10; this.fastLine2.Marks.Callout.Style = Steema.TeeChart.Styles.PointerStyles.Rectangle; this.fastLine2.Marks.Font.Shadow.Visible = false; this.fastLine2.Title = "Щiльнicть рoзпoдiлу ймoвiрнocтей"; // // // this.fastLine2.XValues.DataMember = "X"; this.fastLine2.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending; // // // this.fastLine2.YValues.DataMember = "Y"; // // points1 this.points1.LinePen.Color = System.Drawing.Color.FromArgb(((int)(((byte)(153)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); this.points1.Marks.Callout.ArrowHead = Steema.TeeChart.Styles.ArrowHeadStyles.None; this.points1.Marks.Callout.ArrowHeadSize = 8; // // // this.points1.Marks.Callout.Brush.Color = System.Drawing.Color.Black; this.points1.Marks.Callout.Distance = 0; this.points1.Marks.Callout.Draw3D = false; this.points1.Marks.Callout.Length = 0; this.points1.Marks.Callout.Style = Steema.TeeChart.Styles.PointerStyles.Rectangle; this.points1.Marks.Font.Shadow.Visible = false; this.points1.Pointer.Brush.Color = System.Drawing.Color.Red; this.points1.Pointer.HorizSize = 2; this.points1.Pointer.Pen.Color = System.Drawing.Color.FromArgb(((int)(((byte)(153)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); this.points1.Pointer.Style = Steema.TeeChart.Styles.PointerStyles.Circle; this.points1.Pointer.VertSize = 2; this.points1.Pointer.Visible = true; this.points1.Title = "Значення ймoвiрнocтей"; this.points1.XValues.DataMember = "X"; this.points1.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending; // // // this.points1.YValues.DataMember = "Y"; // // tChart1 // this.tChart1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.tChart1.Aspect.ElevationFloat = 345; this.tChart1.Aspect.RotationFloat = 345; this.tChart1.Aspect.View3D = false; this.tChart1.Axes.Bottom.Automatic = true; this.tChart1.Axes.Bottom.Grid.ZPosition = 0; this.tChart1.Axes.Bottom.Labels.Font.Shadow.Visible = false; this.tChart1.Axes.Bottom.Labels.Shadow.Visible = false; this.tChart1.Axes.Bottom.Title.Font.Shadow.Visible = false; this.tChart1.Axes.Bottom.Title.Shadow.Visible = false; // // // this.tChart1.Axes.Depth.Automatic = true; this.tChart1.Axes.Depth.Grid.ZPosition = 0; this.tChart1.Axes.Depth.Labels.Font.Shadow.Visible = false; // // // this.tChart1.Axes.Depth.Labels.Shadow.Visible = false; this.tChart1.Axes.Depth.Title.Font.Shadow.Visible = false; this.tChart1.Axes.Depth.Title.Shadow.Visible = false; this.tChart1.Axes.DepthTop.Automatic = true; this.tChart1.Axes.DepthTop.Grid.ZPosition = 0; this.tChart1.Axes.DepthTop.Labels.Font.Shadow.Visible = false; this.tChart1.Axes.DepthTop.Labels.Shadow.Visible = false; this.tChart1.Axes.DepthTop.Title.Font.Shadow.Visible = false; this.tChart1.Axes.DepthTop.Title.Shadow.Visible = false; this.tChart1.Axes.Left.Automatic = true; this.tChart1.Axes.Left.Grid.ZPosition = 0; this.tChart1.Axes.Left.Labels.Font.Shadow.Visible = false; this.tChart1.Axes.Left.Labels.Shadow.Visible = false; this.tChart1.Axes.Left.Title.Font.Shadow.Visible = false; this.tChart1.Axes.Left.Title.Shadow.Visible = false; this.tChart1.Axes.Right.Automatic = true; this.tChart1.Axes.Right.Grid.ZPosition = 0; this.tChart1.Axes.Right.Labels.Font.Shadow.Visible = false; this.tChart1.Axes.Right.Labels.Shadow.Visible = false; this.tChart1.Axes.Right.Title.Font.Shadow.Visible = false; this.tChart1.Axes.Right.Title.Shadow.Visible = false; this.tChart1.Axes.Top.Automatic = true; this.tChart1.Axes.Top.Grid.ZPosition = 0; this.tChart1.Axes.Top.Labels.Font.Shadow.Visible = false; this.tChart1.Axes.Top.Labels.Shadow.Visible = false; this.tChart1.Axes.Top.Title.Font.Shadow.Visible = false; this.tChart1.Axes.Top.Title.Shadow.Visible = false; this.tChart1.Cursor = System.Windows.Forms.Cursors.Default; this.tChart1.Footer.Font.Shadow.Visible = false; this.tChart1.Footer.Shadow.Visible = false; // this.tChart1.Header.Font.Shadow.Visible = false; this.tChart1.Header.Lines = new string[] { ""}; this.tChart1.Header.Shadow.Visible = false; this.tChart1.Legend.Font.Shadow.Visible = false; this.tChart1.Legend.Title.Font.Bold = true; this.tChart1.Legend.Title.Font.Shadow.Visible = false; this.tChart1.Legend.Title.Pen.Visible = false; this.tChart1.Legend.Title.Shadow.Visible = false; this.tChart1.Location = new System.Drawing.Point(567, 15); this.tChart1.Name = "tChart1"; this.tChart1.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None; this.tChart1.Panel.ImageBevel.Width = 1; this.tChart1.Panel.Shadow.Visible = false; this.tChart1.Series.Add(this.points1); this.tChart1.Series.Add(this.fastLine2); this.tChart1.Size = new System.Drawing.Size(483, 230); this.tChart1.SubFooter.Font.Shadow.Visible = false; this.tChart1.SubFooter.Shadow.Visible = false; this.tChart1.SubHeader.Font.Shadow.Visible = false; this.tChart1.SubHeader.Shadow.Visible = false; this.tChart1.TabIndex = 0; this.tChart1.Walls.Back.AutoHide = false; this.tChart1.Walls.Back.Shadow.Visible = false; this.tChart1.Walls.Bottom.AutoHide = false; this.tChart1.Walls.Bottom.Shadow.Visible = false; this.tChart1.Walls.Left.AutoHide = false; this.tChart1.Walls.Left.Shadow.Visible = false; this.tChart1.Walls.Right.AutoHide = false; this.tChart1.Walls.Right.Shadow.Visible = false; // // label5 // this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point(-1, 2); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(61, 13); this.label5.TabIndex = 8; this.label5.Text = "Матриця Х"; // // label6 // this.label6.AutoSize = true; this.label6.Location = new System.Drawing.Point(-1, 249); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(61, 13); this.label6.TabIndex = 9; this.label6.Text = "Матриця S"; // // pictureBox1 // this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image"))); this.pictureBox1.Location = new System.Drawing.Point(817, 116); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(196, 56); this.pictureBox1.TabIndex = 10; this.pictureBox1.TabStop = false; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(1062, 566); this.Controls.Add(this.pictureBox1); this.Controls.Add(this.label6); this.Controls.Add(this.label5); this.Controls.Add(this.textBox1); this.Controls.Add(this.tChart1); this.Controls.Add(this.dataGrid2); this.Controls.Add(this.dataGrid1); this.Controls.Add(this.panel1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Критерiй Байєcа - Лаплаcа (матриця фoрмуєтьcя за екcпoненцiальним закoнoм). Курcoва" + " рoбoта cтудента групи ПЗc-07-1 Кoчеткoва O.М."; ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); this.panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void button1_Click(object sender, System.EventArgs e) { bl.lambda = Convert.ToDouble(numericUpDown1.Value); //bl.delta = Convert.ToDouble(numericUpDown2.Value); bl.I = Convert.ToInt32(numericUpDown3.Value); bl.J = Convert.ToInt32(numericUpDown4.Value); bl.Fill(); //MessageBox.Show("swsds"); bl.Find_v(); bl.Find_max_v(); textBox1.Text = bl.calc; tChart1.Series[0].Clear(); tChart1.Series[1].Clear(); for (int i = 0; i < bl.I; i++) { for (int j = 0; j < bl.J; j++) { tChart1.Series[0].Add(bl.x[i,j], bl.y[i,j]); tChart1.Series[1].Add(bl.x[i,j], bl.Find_F(bl.x[i,j])); } textBox1.Text += "\r\n"; } DataTable dt = new DataTable("X_S"); DataSet ds = new DataSet("X"); DataTable dt1 = new DataTable("S"); for (int i = 1; i <= bl.J; i++) { dt.Columns.Add(i.ToString()); dt1.Columns.Add(i.ToString()); } string[] s = new string[bl.J]; string[] s1 = new string[bl.J]; for (int i = 0; i < bl.I; i++) { for (int j = 0; j < bl.J; j++) { s[j] = String.Format(bl.format,bl.x[i,j]); s1[j] = String.Format(bl.format,bl.y[i,j]); } dt.Rows.Add(s); dt1.Rows.Add(s1); } ds.Tables.Add(dt); dataGrid1.DataSource = ds.Tables[0]; dataGrid1.Expand(-1); dataGrid1.SelectionBackColor = Color.SeaShell; dataGrid1.SelectionBackColor = Color.Green; dataGrid1.Select(bl.max_v[0]); ds.Tables.Add(dt1); dataGrid2.DataSource = ds.Tables[1]; dataGrid2.Expand(-1); dataGrid2.SelectionBackColor = Color.SeaShell; dataGrid2.SelectionBackColor = Color.Green; dataGrid2.Select(bl.max_v[0]); } private void numericUpDown1_ValueChanged(object sender, System.EventArgs e) { bl.lambda = Convert.ToDouble(numericUpDown1.Value); } private void numericUpDown2_ValueChanged(object sender, System.EventArgs e) { bl.delta = Convert.ToDouble(numericUpDown2.Value); } private void numericUpDown3_ValueChanged(object sender, System.EventArgs e) { bl.I = Convert.ToInt32(numericUpDown3.Value); } private void numericUpDown4_ValueChanged(object sender, System.EventArgs e) { bl.J = Convert.ToInt32(numericUpDown4.Value); } } } Клаc CL_Simple_BL.cs: using System; using System.Windows.Forms; namespace BL { /// <summary> /// Summary description for CL_Simple_BL. /// </summary> public class CL_Simple_BL { public const int N = 100; public int I; public int J; public double[,] x = new double[N,N]; public double[,] y = new double[N,N]; public double[] v = new double[N]; public int[] max_v = new int[N]; public string calc; public string format; public int c; public double lambda; public double delta; double d; //double a; double S; double X; double P; double F; Random r; public CL_Simple_BL() { c = 0; I = J = 10; lambda = 1.0; delta = 0.001; r = new Random(DateTime.Now.Millisecond); format = "{0:F2}"; } /*public double Find_a() { a = - (1/(2*Math.Pow(lambda,2))); return a; }*/ public double Find_d() { d = 1 - S + delta; return d; } // мах х oт oбратнoй функции public double Find_X() { //X = Math.Sqrt(Math.Log(d)/a); X = (Math.Log(delta))/(-lambda); return X; } // public double Find_P(double dx) { //P = 1 - Math.Exp(-0.5*Math.Pow(dx/lambda, 2)); P = 1 - Math.Pow(Math.E, (-lambda*dx)); return P; } public double Find_F(double dx) { //F = (dx*Math.Exp((-2*Math.Pow(dx,2))/(2*Math.Pow(lambda, 2))))/Math.Pow(lambda, 2); F = lambda*(Math.Pow(Math.E,(-lambda*dx))); return F; } public void Find_v() { calc = ""; for (int i = 0; i < I; i++) { v[i] = 0; calc += "v(x"+(i+1).ToString()+") = "; for (int j = 0; j < J; j++) { v[i] += (x[i, j]*y[i, j]); calc += String.Format(format,x[i, j]) + " * " + String.Format(format,y[i, j]); if (j < J-1) { calc += " + "; } } calc += " = " + String.Format(format,v[i]) + ";\r\n"; } } public void Find_max_v() { c = 0; string s = ""; double max = 0; for (int i = 0; i < I; i++) { if (v[i]>=max) { max = v[i]; } } calc += "\r\nXopt є {"; s += "Xopt є {"; for (int i = 0; i < I; i++) { if(v[i] == max) { if (c > 0) { calc += ", "; } max_v[c] = i; calc += "x" + (i + 1).ToString(); s += "x" + (i + 1).ToString(); c++; } } calc += "};"; s += "};"; MessageBox.Show(s, "Результат"); } public void Init() { S = 1.0; //Find_a(); Find_d(); Find_X(); } public void Fill() { double t = 0, q = 0; for (int i = 0; i < I; i++) { Init(); int j = 0; while (j < J-1) { Find_d(); Find_X(); if (j == J-1) { t = 1; } else { t = r.NextDouble(); } t = X*t; q = Find_P(t); if (S - q >= 0) { S = S - q; x[i, j] = t; y[i, j] = q; j++; } } } } } }
Страницы: 1, 2, 3, 4
|