/// <summary> /// получить новое значение координат нейтрона. Возвращает нейтрон. /// </summary> /// <param name="neutron">Нейтрон координаты которого нужно изменить</param> /// <returns></returns> private Neutron_struct getNewValue(Neutron_struct neutron) { int rand = DateTime.Now.DayOfYear + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second; rand = Math.Abs(rand + (int)neutron.x + (int)neutron.y + (int)neutron.z + (int)neutron.radius); rand = rand * DateTime.Now.Millisecond; Random random = new Random(rand); ret1: neutron.x = random.Next((int)BoxNeutoron.x, (int)BoxNeutoron.xmax); neutron.x += random.NextDouble(); if (!getBoolProvKordNeuBox(neutron.x, neutron.radius, BoxNeutoron.x, BoxNeutoron.xmax)) { goto ret1; } ret2: neutron.y = random.Next((int)BoxNeutoron.y, (int)BoxNeutoron.ymax); neutron.y += random.NextDouble(); if (!getBoolProvKordNeuBox(neutron.y, neutron.radius, BoxNeutoron.y, BoxNeutoron.ymax)) { goto ret2; } ret3: neutron.z = random.Next((int)BoxNeutoron.z, (int)BoxNeutoron.zmax); neutron.z += random.NextDouble(); if (!getBoolProvKordNeuBox(neutron.z, neutron.radius, BoxNeutoron.z, BoxNeutoron.zmax)) { goto ret3; } return(neutron); }
/// <summary> /// Генерирует массив слуайных радиусов /// </summary> /// <param name="n">Число зерен</param> /// <param name="dr">R большое</param> /// <returns>Возвращает массив Neutron_struct с заполненным полем 'r'</returns> /// <exception cref="Деление на нуль при генерации W(r)">Возможно деление на нуль при генерации очередного значения W(r)</exception> public Neutron_struct[] randomInW_R(int n, double dr) { int rand = DateTime.Now.Year - DateTime.Now.Day - DateTime.Now.Month; rand = rand - DateTime.Now.Hour - DateTime.Now.Minute - DateTime.Now.Millisecond; rand += (int)Math.Truncate(dr); rand = Math.Abs(rand); Neutron_struct[] neutrons = new Neutron_struct[n]; Random randoms = new Random(rand); Parallel.For(0, neutrons.Length, (i, state) => { Random random = randoms; reti: double _r = random.Next(0, (int)dr + 1) + Math.Round(random.NextDouble(), 6); double w_r = ((3 * Math.Pow(_r, 2)) / (Math.Pow(dr, 3))); double w_ = Math.Exp(-Math.Pow((_r / dr), 3)); w_r = w_r * w_; w_r *= 10; if (w_r < 0.1) { if (_r == 0) { int randi = DateTime.Now.Year + DateTime.Now.DayOfYear + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Millisecond + i; randi *= (i + 1); random = new Random(randi); } goto reti; } neutrons[i] = new Neutron_struct(); neutrons[i].radius = w_r; }); return(neutrons); }
private bool getNeutoronsNotConnect(Neutron_struct[] neutrons) { int maxrestartmetod = 0; int restartmetod = 0; int index = 0; start1: for (int i = 0; i < neutrons.Length - 1; i++) { int swap = i; Parallel.For(0, neutrons.Length, (j, state) => { if (neutrons[j].radius > neutrons[swap].radius) { swap = j; } }); Neutron_struct sw = neutrons[i]; neutrons[i] = neutrons[swap]; neutrons[swap] = sw; } start0: restartmetod++; DateTime chetchik = DateTime.Now; ResSum sum = getsumConnect(index, neutrons); bool sumconnects = sum.sumconnect; index = sum.index; Console.WriteLine("Подсчет суммы занял - " + (DateTime.Now - chetchik).ToString()); chetchik = DateTime.Now; mainwindow.newValueProgresBar(); if (sumconnects == false) { if (index != 0) { index = 0; goto start0; } return(true); } if (restartmetod > Properties.Settings.Default.restarnfor) { maxrestartmetod++; restartmetod = 0; new System.Threading.Thread(delegate() { MessageBox.Show("Проход разбиения по просранству №" + maxrestartmetod + "(maxrestartmetod).", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); }).Start(); Random rand = new Random(DateTime.Today.Millisecond * DateTime.Today.Minute); if (deleteConnectOtherNeutron(index, neutrons, false) == false) { for (int i = 0; i < rand.Next(5, 20); i++) { int c = rand.Next(neutrons.Length); neutrons[c] = getNewValue(neutrons[c]); } } goto start1; } else if (neutrons.Length >= 10000000) { new System.Threading.Thread(delegate() { MessageBox.Show("Проход разбиения по просранству №" + restartmetod + "(restartmetod).", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); }).Start(); } int restartswap = 0; ret0: bool ifi = deleteConnectOtherNeutron(index, neutrons, true); if (ifi) { restartswap++; if (restartswap > Properties.Settings.Default.restarnfor) { goto start0; } neutrons[index] = getNewValue(neutrons[index]); goto ret0; } Console.WriteLine("Проверка пересечений заняла - " + (DateTime.Now - chetchik).ToString()); goto start0; }