public double[,] GetPollution(int index, Axis axis, ThreadDispatcherType dispatcherType) { double[,] res; switch (dispatcherType) { default: case ThreadDispatcherType.Auto: if ((Length > 150) || (Ray > 14)) { res = GetAsyncPollution(index, axis); } else { res = GetSyncPollution(index, axis); } break; case ThreadDispatcherType.Async: res = GetAsyncPollution(index, axis); break; case ThreadDispatcherType.Sync: res = GetSyncPollution(index, axis); break; } return(res); }
public void Next(ThreadDispatcherType dispatcherType) { switch (dispatcherType) { case ThreadDispatcherType.Auto: if (Length > 200) { NextAsync(); } else { NextSync(); } break; case ThreadDispatcherType.Async: NextAsync(); break; case ThreadDispatcherType.Sync: NextSync(); break; } }
public bool OpenXML(string pathXML) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(pathXML); XmlElement xroot = xmlDocument.DocumentElement; bool error = false; string iteratorValue = ""; try { iteratorValue = xroot.SelectSingleNode("iterator").InnerText; } catch { Length = 100; Ray = 5; _countThread = Environment.ProcessorCount; AddPollution(25, 75, 25, 75, 25, 75); _pAxis = 1.0 / 3.0; _pDirection = 1.0 / 3.0; Name = "New_CA"; _selectThreadDispatcher = ThreadDispatcherType.Auto; MaxWind = 20; _wind = 0; Angel = 0; return(false); } string threadDispatcherValue = ""; try { threadDispatcherValue = xroot.SelectSingleNode("threadDispatcher").InnerText; if (threadDispatcherValue == "Sync") { _selectThreadDispatcher = ThreadDispatcherType.Sync; } else if (threadDispatcherValue == "Async") { _selectThreadDispatcher = ThreadDispatcherType.Async; } else { _selectThreadDispatcher = ThreadDispatcherType.Auto; } } catch { _selectThreadDispatcher = ThreadDispatcherType.Auto; } string windValue = ""; try { windValue = xroot.SelectSingleNode("wind").InnerText; } catch { error = true; windValue = (0).ToString(); } string angelValue = ""; try { angelValue = xroot.SelectSingleNode("angel").InnerText; } catch { error = true; angelValue = (0).ToString(); } string maxWindValue = ""; try { maxWindValue = xroot.SelectSingleNode("maxWind").InnerText; } catch { error = true; maxWindValue = (20).ToString(); } try { Name = xroot.SelectSingleNode("name").InnerText; } catch { Name = "NewCA"; error = true; } string pAxisValue = ""; try { pAxisValue = xroot.SelectSingleNode("pAxis").InnerText; } catch { pAxisValue = (1.0 / 3.0).ToString(); error = true; } string pDirectionValue = ""; try { pDirectionValue = xroot.SelectSingleNode("pDirection").InnerText; } catch { pDirectionValue = (1.0 / 3.0).ToString(); error = true; } string countThreadValue; try { countThreadValue = xroot.SelectSingleNode("countThread").InnerText; } catch { countThreadValue = (2).ToString(); } string lengthValue = ""; try { lengthValue = xroot.SelectSingleNode("length").InnerText; } catch { lengthValue = (100).ToString(); } string rayValue = ""; try { rayValue = xroot.SelectSingleNode("ray").InnerText; } catch { rayValue = (5).ToString(); } if (int.TryParse(iteratorValue, out int count)) { Iterator = count; } else { Length = 100; Ray = 5; _countThread = Environment.ProcessorCount; AddPollution(25, 75, 25, 75, 25, 75); _pAxis = 1.0 / 3.0; _pDirection = 1.0 / 3.0; Name = "New_CA"; _selectThreadDispatcher = ThreadDispatcherType.Auto; MaxWind = 20; _wind = 0; Angel = 0; return(false); } if (double.TryParse(pAxisValue, out double p)) { _pAxis = p; } else { error = true; _pAxis = 1.0 / 3.0; } if (double.TryParse(pDirectionValue, out p)) { _pDirection = p; } else { error = true; _pDirection = 1.0 / 3.0; } if (int.TryParse(countThreadValue, out count)) { _countThread = count > Environment.ProcessorCount ? Environment.ProcessorCount : count; } else { error = true; _countThread = Environment.ProcessorCount; } if (int.TryParse(lengthValue, out count)) { Length = count; } else { error = true; Length = 100; } if (double.TryParse(maxWindValue, out p)) { if (MaxWind > 0) { MaxWind = p < Length ? p : Length / 2; } else { MaxWind = 0; } } else { error = true; MaxWind = 20 < Length ? 20 : Length / 2; } if (double.TryParse(windValue, out p)) { Wind = p; } else { error = true; Wind = 0; } if (double.TryParse(angelValue, out p)) { Angel = p; } else { error = true; Angel = 0; } if (int.TryParse(rayValue, out count)) { Ray = count; } else { error = true; Ray = 5; } XmlNode xmlNode; try { xmlNode = xroot.GetElementsByTagName("pollutions").Item(0); } catch { error = true; return(!error); } foreach (XmlNode x in xmlNode.ChildNodes) { string xString1, xString2, yString1, yString2, zString1, zString2; try { xString1 = x.Attributes.GetNamedItem("x1").Value; } catch { xString1 = ""; } try { xString2 = x.Attributes.GetNamedItem("x2").Value; } catch { xString2 = ""; } try { yString1 = x.Attributes.GetNamedItem("y1").Value; } catch { yString1 = ""; } try { yString2 = x.Attributes.GetNamedItem("y2").Value; } catch { yString2 = ""; } try { zString1 = x.Attributes.GetNamedItem("z1").Value; } catch { zString1 = ""; } try { zString2 = x.Attributes.GetNamedItem("z2").Value; } catch { zString2 = ""; } int x1, x2, y1, y2, z1, z2; if (int.TryParse(xString1, out count)) { x1 = count < Length ? count : 0; } else { error = true; x1 = 25 < Length ? count : 0; } if (int.TryParse(xString2, out count)) { if (count < Length) { x2 = count >= x1 ? count : Length - 1; } else { x2 = Length - 1; } } else { error = true; if (75 < Length) { x2 = 75 >= x1 ? 75 : Length - 1; } else { x2 = Length - 1; } } if (int.TryParse(yString1, out count)) { y1 = count < Length ? count : 0; } else { error = true; y1 = 25 < Length ? 25 : 0; } if (int.TryParse(yString2, out count)) { if (count < Length) { y2 = count >= y1 ? count : Length - 1; } else { y2 = Length - 1; } } else { error = true; if (75 < Length) { y2 = 75 >= y1 ? 75 : Length - 1; } else { y2 = Length - 1; } } if (int.TryParse(zString1, out count)) { z1 = count < Length ? count : 0; } else { error = true; z1 = 25 < Length ? 25 : 0; } if (int.TryParse(zString2, out count)) { if (count < Length) { z2 = count >= z1 ? count : Length - 1; } else { z2 = Length - 1; } } else { error = true; if (75 < Length) { z2 = 75 >= z1 ? 75 : Length - 1; } else { z2 = Length - 1; } } AddPollution(x1, x2, y1, y2, z1, z2); } return(!error); }