private ResSum getsumConnect(int index, Neutron_struct[] neutrons) { bool sumconnects = false; Parallel.For(index, neutrons.Length - 1, (i, statei) => { for (int j = i + 1; j < neutrons.Length; j++) { double L = Math.Pow((neutrons[j].x - neutrons[i].x), 2) + Math.Pow((neutrons[j].y - neutrons[i].y), 2) + Math.Pow((neutrons[j].z - neutrons[i].z), 2); L = Math.Sqrt(L); if (Math.Abs(L) < neutrons[i].radius + neutrons[j].radius && sumconnects == false) { sumconnects = true; index = i; statei.Break(); break; } } }); ResSum r = new ResSum(); r.sumconnect = sumconnects; r.index = index; return(r); }
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; }