public void Mutations() { int p, x = 0; int number_of_mutation, point_of_mutation; for (int i = 0; i < individuals.Count; i++) { p = Convert.ToInt32(CDll1.Rand(0, 100)); if (p < P) { if (p % 2 == 0) { number_of_mutation = (int)CDll1.Rand(1, Neq); point_of_mutation = (int)CDll1.Rand(1, Bits - 1); x = (int)Math.Pow(2, point_of_mutation); individuals[i][number_of_mutation] = (individuals[i][number_of_mutation] >> (point_of_mutation + 1)) << (point_of_mutation + 1) + (individuals[i][number_of_mutation] << (Bits - point_of_mutation + 2)) >> (Bits - point_of_mutation + 2) + (~(individuals[i][number_of_mutation] & x)) & x; } else { number_of_mutation = (int)CDll1.Rand(1, Neq); individuals[i][number_of_mutation] += 1; } } } }
public void GenerateNewIndividuals(int N) { int[] a = new int[Neq]; for (int i = 0; i < N; i++) { for (int j = 0; i < Neq; j++) { a[j] = Convert.ToInt32(CDll1.Rand(0.0, 100.0)); } individuals.Add(a); } }
public void Crossing() { int i1, i2; int[] f1 = new int[Neq]; int[] f2 = new int[Neq]; for (int i = 0; i < CrossingConst; i++) { //choose 2 random individuals i1 = (int)CDll1.Rand(0, startN); i2 = (int)CDll1.Rand(0, startN); CrossingOver(individuals[i1], individuals[i2], f1, f2); individuals.Add(f1); individuals.Add(f2); } }
public void CrossingOver(int[] p1, int[] p2, int[] f1, int[] f2) { //choose a point of crossingover int number_of_crossing = (int)CDll1.Rand(1, Neq); int point_of_crossing = (int)CDll1.Rand(1, Bits - 1); //inside and outside the bit of crossing for (int i = 0; i < number_of_crossing; i++) { f1[i] = p2[i]; f2[i] = p1[i]; } for (int i = number_of_crossing + 1; i < Neq; i++) { f1[i] = p1[i]; f2[i] = p2[i]; } //in the bit of crossing int m = Bits - point_of_crossing; int x = 0, y = 0; for (int i = m; i < Bits; i++) { x += (int)Math.Pow(2, i); } for (int i = 0; i < m; i++) { y += (int)Math.Pow(2, i); } f1[number_of_crossing] = p1[number_of_crossing] & x + p2[number_of_crossing] & y; f2[number_of_crossing] = p2[number_of_crossing] & x + p2[number_of_crossing] & y; }
public double[,] RandomizeForSphere(int N) { /* GraphPane gr = zd.GraphPane; * gr.CurveList.Clear(); * gr.Title.Text = "Random Sphere"; * * PointPairList list = new PointPairList(); * JimRandom rnd = new JimRandom();*/ //StreamWriter wr = new StreamWriter("E:\\testrand.txt"); double[,] arr = new double[N, 2]; double pseudophi, teta; double max = Math.PI; for (int i = 0; i < N; i++) { // pseudophi = r_pseudophi.Next(0, Convert.ToInt16(2 * max)) + r_pseudophi.NextDouble(); // teta = r_pseudophi.Next(0, 90) + r_pseudophi.NextDouble(); // pseudophi = rnd.Next(0, Convert.ToInt16(2 * max)) + rnd.NextDouble(); // teta = rnd.Next(0, 90) + rnd.NextDouble(); // list.Add(pseudophi, teta); pseudophi = CDll1.Rand(0.0, 2.0 * max); teta = CDll1.Rand(0.0, 90.0); if (pseudophi <= max) { if ((-1.0 * max * Math.Sin((teta * Math.PI) / 180.0)) + max <= pseudophi) { if (teta != 0.0) { double phi = 360.0 - (180.0 * (max - pseudophi)) / ((max * Math.Sin((teta * Math.PI) / 180.0))); arr[i, 0] = teta; arr[i, 1] = phi; //list.Add(phi, teta); } else { i--; } } else { i--; } } else { if ((max * Math.Sin((teta * Math.PI) / 180.0)) + max >= pseudophi) { if (teta != 0.0) { double phi = (180.0 * (-max + pseudophi)) / ((max * Math.Sin((teta * Math.PI) / 180.0))); arr[i, 0] = teta; arr[i, 1] = phi; // list.Add(phi, teta); } else { i--; } } else { i--; } } } /* LineItem myCurve = gr.AddCurve("Random", list, Color.Blue, SymbolType.Diamond); * myCurve.Line.IsVisible = true; * myCurve.Symbol.Fill.Color = Color.Blue; * myCurve.Symbol.Fill.Type = FillType.Solid; * myCurve.Symbol.Size = 2; * * gr.XAxis.Title.Text = "Phi"; * gr.XAxis.Scale.Min = 0; * // gr.XAxis.Title.Text = "PseudoPhi"; * // gr.XAxis.Scale.Max = 2*max; * gr.XAxis.Scale.Max = 360; * * gr.YAxis.Scale.Min = 0; * gr.YAxis.Scale.Max = 90; * gr.YAxis.Title.Text = "Theta"; * zd.AxisChange(); * * zd.Invalidate();*/ /* for (int i = 0; i < N; i++) * { * wr.WriteLine(arr[i,0]); * wr.WriteLine(arr[i, 1]); * } * wr.Close();*/ return(arr); }
private void button2_Click(object sender, EventArgs e) { double a = CDll1.Rand(0, 10); textBox1.Text = Convert.ToString(a); }