public static double[] LimitDeltaIndexes(DACEmulator emulator, int input, double threshold = 0.001) { double[] oldIndexes = emulator.DeltaIndexes; LongBits outputBinaryCode = emulator.GetDKFromComparators(input); LongBits inputBinaryCode = new LongBits(input, emulator.N); double k = 1.1; while (inputBinaryCode != outputBinaryCode) { for (int i = 0; i < outputBinaryCode.Length; i++) { if (emulator.DeltaIndexes[i] > -threshold && emulator.DeltaIndexes[i] < threshold) { return(null); } if (inputBinaryCode != outputBinaryCode) { emulator.DeltaIndexes[i] /= k; } } outputBinaryCode = emulator.GetDKFromComparators(input); } double[] critical = emulator.DeltaIndexes; emulator.DeltaIndexes = oldIndexes; return(critical); }
private static List <Point3D> GetPointsOfCriticalArea(DACEmulator emulator, DACEmulator.Delta minMaxDeltaParameter, DACEmulator.Delta changingDeltaParameter, double minMaxDeltaParameterStep = 1, double changingDeltaParameterStep = 1, double accuracy = 0.0001) { List <Point3D> area = new List <Point3D>(); double deltaMin = TestingDelta(emulator.N, emulator.Coeff, minMaxDeltaParameter, -minMaxDeltaParameterStep, accuracy, emulator.DeltaCoeff, emulator.DeltaIndex, emulator.DeltaSM, true).GetDeltaParameter(minMaxDeltaParameter); double deltaMax = TestingDelta(emulator.N, emulator.Coeff, minMaxDeltaParameter, minMaxDeltaParameterStep, accuracy, emulator.DeltaCoeff, emulator.DeltaIndex, emulator.DeltaSM, true).GetDeltaParameter(minMaxDeltaParameter); double step = (deltaMax - deltaMin) / (minMaxDeltaParameterStep - 1); double i = deltaMin; for (int j = 0; j < minMaxDeltaParameterStep; j++) { emulator.SetDeltaParameter(minMaxDeltaParameter, i); double deltaStepWithAccuracy = changingDeltaParameterStep; while (Math.Abs(deltaStepWithAccuracy) * 2 > accuracy) { bool needCorrecting = false; while (ErrorChecking(emulator)) { emulator.AddDeltaParameter(changingDeltaParameter, deltaStepWithAccuracy); needCorrecting = true; } if (needCorrecting) { emulator.AddDeltaParameter(changingDeltaParameter, -deltaStepWithAccuracy); } deltaStepWithAccuracy /= 2; } area.Add(new Point3D((float)emulator.GetDeltaParameter(DACEmulator.Delta.Coeff), (float)emulator.GetDeltaParameter(DACEmulator.Delta.SM), (float)emulator.GetDeltaParameter(DACEmulator.Delta.Index))); emulator.SetDeltaParameter(changingDeltaParameter, 0); i += step; } return(area); }
private void buttonGetModel_Click(object sender, EventArgs e) { int n = 0; double coeff = 0, deltaCoeff = 0, deltaSM = 0; double[] masDelta; try { n = (int)numericUpDownN.Value; coeff = (double)numericUpDownK.Value; deltaCoeff = (double)numericUpDownDK.Value; { List <double> l = new List <double> { }; foreach (DataGridViewCell cell in dataGridViewDeltaI.Rows[0].Cells) { l.Add(Convert.ToDouble(cell.Value)); } masDelta = l.ToArray(); } deltaSM = (double)numericUpDownDUsm.Value; } catch { MessageBox.Show("Неверный формат входных параметров!"); return; } DACEmulator emulator = new DACEmulator(coeff, deltaCoeff, masDelta, deltaSM); voltagesQuantumStep = emulator.RealStep; int countNumbers = (int)Math.Pow(2, n); modelVoltages = new double[countNumbers]; idealVoltages = new double[countNumbers]; dataGridViewVect.Rows.Clear(); for (int x = 0; x < countNumbers; x++) { modelVoltages[x] = emulator.Uin(x); idealVoltages[x] = emulator.IdealUin(x); LongBits binaryCode = emulator.GetDKFromComparators(x); LongBits inCode = new LongBits(x, n); int[] errorInds = emulator.GetEKPErrorFromComparators(x); dataGridViewVect.Rows.Add(new object[] { inCode, binaryCode, inCode.ToLong(), binaryCode.ToLong(), string.Join(", ", errorInds) }); if (inCode != binaryCode) { dataGridViewVect.Rows[x].DefaultCellStyle.BackColor = errorCellBackColor; } } modelVoltageColor = Color.DarkOrchid; VoltageChartService chartService = new VoltageChartService(this.mainChart, "Входное напряжение", voltagesQuantumStep); chartService.AddInputVoltageList("Voltages", modelVoltages, modelVoltageColor, 2); chartService.AddInputVoltageList("Ideal voltages", idealVoltages, idealVoltageColor, 2); }
private void buttonGetModel_Click(object sender, EventArgs e) { int n = 0; double coeff = 0, deltaCoeff = 0, deltaSM = 0, deltaI = 0; try { n = (int)numericUpDownN.Value; coeff = (double)numericUpDownK.Value; deltaCoeff = (double)numericUpDownDK.Value; deltaI = (double)numericUpDownDI.Value; deltaSM = (double)numericUpDownDUsm.Value; } catch { MessageBox.Show("Неверный формат входных параметров!"); return; } if (graphForm != null && graphForm.Visible) { graphForm.SelectedPoint = new Point3D((float)deltaCoeff, (float)deltaSM, (float)deltaI); graphForm.RefreshGraph(); } DACEmulator emulator = new DACEmulator(n, coeff, deltaCoeff, deltaI, deltaSM); voltagesQuantumStep = emulator.RealStep; int countNumbers = (int)Math.Pow(2, n); modelVoltages = new double[countNumbers]; idealVoltages = new double[countNumbers]; dataGridViewVect.Rows.Clear(); for (int x = 0; x < countNumbers; x++) { modelVoltages[x] = emulator.Uin(x); idealVoltages[x] = emulator.IdealUin(x); LongBits binaryCode = emulator.GetDKFromComparators(x); LongBits inCode = new LongBits(x, n); int[] errorInds = emulator.GetEKPErrorFromComparators(x); dataGridViewVect.Rows.Add(new object[] { inCode, binaryCode, inCode.ToLong(), binaryCode.ToLong(), string.Join(", ", errorInds) }); if (inCode != binaryCode) { dataGridViewVect.Rows[x].DefaultCellStyle.BackColor = errorCellBackColor; } } toolStripMenuItemCopy.Visible = true; modelVoltageColor = Color.DarkOrchid; VoltageChartService chartService = new VoltageChartService(this.mainChart, "Входное напряжение", voltagesQuantumStep); chartService.AddInputVoltageList("Voltages", modelVoltages, modelVoltageColor, 2); chartService.AddInputVoltageList("Ideal voltages", idealVoltages, idealVoltageColor, 2); }
private static bool ErrorChecking(DACEmulator emulator) { int countNumbers = (int)Math.Pow(2, emulator.N); LongBits inputBinaryCode = new LongBits(0, emulator.N), outputBinaryCode = inputBinaryCode; for (int x = 0; x < countNumbers; x++) { inputBinaryCode = new LongBits(x, emulator.N); outputBinaryCode = emulator.GetDKFromComparators(x); if (inputBinaryCode != outputBinaryCode) { return(false); } } return(true); }
private void buttonCritical_Click(object sender, EventArgs e) { int n = 0, deltaIndex = 0; double coeff = 0, deltaCoeff = 0, deltaSM = 0; n = (int)numericUpDownN.Value; coeff = (double)numericUpDownK.Value; try { deltaSM = double.Parse(labelCriticalDsm.Text); } catch { MessageBox.Show("Критические параметры отсутствуют!"); return; } DACEmulator emulator = new DACEmulator(n, coeff, deltaCoeff, deltaIndex, deltaSM); voltagesQuantumStep = emulator.RealStep; int countNumbers = (int)Math.Pow(2, n); modelVoltages = new double[countNumbers]; idealVoltages = new double[countNumbers]; dataGridViewVect.Rows.Clear(); for (int x = 0; x < countNumbers; x++) { modelVoltages[x] = emulator.Uin(x); idealVoltages[x] = emulator.IdealUin(x); LongBits binaryCode = emulator.GetDKFromComparators(x); LongBits inCode = new LongBits(x, n); int[] errorInds = emulator.GetEKPErrorFromComparators(x); dataGridViewVect.Rows.Add(new object[] { inCode, binaryCode, inCode.ToLong(), binaryCode.ToLong(), string.Join(", ", errorInds) }); if (inCode != binaryCode) { dataGridViewVect.Rows[x].DefaultCellStyle.BackColor = errorCellBackColor; } } toolStripMenuItemCopy.Visible = true; modelVoltageColor = Color.FromKnownColor(KnownColor.Highlight); VoltageChartService chartService = new VoltageChartService(this.mainChart, "Входное напряжение при критическом δсм", voltagesQuantumStep); chartService.AddInputVoltageList("Voltages", modelVoltages, modelVoltageColor, 2); chartService.AddInputVoltageList("Ideal voltages", idealVoltages, idealVoltageColor, 2); }
private static List <Point3D> GetPointsOfCriticalArea(DACEmulator emulator, DACEmulator.Delta minMaxDeltaParameter, DACEmulator.Delta changingDeltaParameter, double minMaxDeltaParameterStep = 1, double changingDeltaParameterStep = 1) { double accuracy = 0.0001; List <Point3D> area = new List <Point3D>(); double deltaMin = TestingDelta(emulator.N, emulator.Coeff, minMaxDeltaParameter, -minMaxDeltaParameterStep, accuracy, emulator.DeltaCoeff, emulator.DeltaIndex, emulator.DeltaSM).GetDeltaParameter(minMaxDeltaParameter); double deltaMax = TestingDelta(emulator.N, emulator.Coeff, minMaxDeltaParameter, minMaxDeltaParameterStep, accuracy, emulator.DeltaCoeff, emulator.DeltaIndex, emulator.DeltaSM).GetDeltaParameter(minMaxDeltaParameter); minMaxDeltaParameterStep = (deltaMax - deltaMin) / minMaxDeltaParameterStep; for (double i = deltaMin; i <= deltaMax; i += minMaxDeltaParameterStep) { emulator.SetDeltaParameter(minMaxDeltaParameter, i); while (ErrorChecking(emulator)) { emulator.AddDeltaParameter(changingDeltaParameter, changingDeltaParameterStep); } area.Add(new Point3D((float)emulator.GetDeltaParameter(DACEmulator.Delta.Coeff), (float)emulator.GetDeltaParameter(DACEmulator.Delta.SM), (float)emulator.GetDeltaParameter(DACEmulator.Delta.Index))); emulator.SetDeltaParameter(changingDeltaParameter, 0); } return(area); }
public static ParamsContainer TestingDeltaIndexes(int n, double coeff, double initialStep = 1, double accuracy = 0.0000001) { double[] deltaIndexes = new double[n]; double[] deltaIndexesSteps = new double[n]; for (int i = 0; i < deltaIndexesSteps.Length; i++) { deltaIndexesSteps[i] = initialStep / (Math.Pow(2, i)); } ParamsContainer container = new ParamsContainer(); container.N = n; container.Coeff = coeff; DACEmulator emulator = new DACEmulator(n, 0, deltaIndexes, 0); emulator.DeltaIndexes = deltaIndexes; bool isContinue = true; while (isContinue) { isContinue = deltaIndexesSteps.Select(x => Math.Abs(x)).Max() >= accuracy; for (int i = deltaIndexes.Length - 1; i >= 0; i--) { deltaIndexes[i] += deltaIndexesSteps[i]; emulator.DeltaIndexes = deltaIndexes; bool noErrors = ErrorChecking(emulator); if (!noErrors) { deltaIndexes[i] -= deltaIndexesSteps[i]; deltaIndexesSteps[i] /= 2; } } } for (int i = deltaIndexes.Length - 1; i >= 0; i--) { emulator.DeltaIndexes[i] += deltaIndexesSteps[i]; } container.DeltaIndexes = deltaIndexes; return(container); }
public static double LimitDeltaCoeff(DACEmulator emulator, int input, double threshold = 0.001) { double oldDeltaCoeff = emulator.DeltaCoeff; LongBits inputBinaryCode = new LongBits(input, emulator.N); LongBits outputBinaryCode = emulator.GetDKFromComparators(input); double k = 1.1; while (inputBinaryCode != outputBinaryCode) { if (emulator.DeltaCoeff > -threshold && emulator.DeltaCoeff < threshold) { return(0); } emulator.DeltaCoeff /= k; outputBinaryCode = emulator.GetDKFromComparators(input); } double critical = emulator.DeltaCoeff; emulator.DeltaCoeff = oldDeltaCoeff; return(critical); }
/// <summary> /// Поиск области допустимых значений критических параметров для двумерного случая, /// то есть для deltaSm и deltaK /// Идея такова: на плоскости X, Y находится верхняя и нижняя части области areaUp и areaBottom и объединяются в общую область /// Затем по оси Z строятся дуги edgeUp (верхняя) и edgeBottom (нижняя) - они также объединяются в одну плоскость /// Таким образом строятся ребра, после чего все записывается в один массив точек /// Ребра были сделаны для того, чтобы их потом последовательно можно было соединить линиями /// А можно и отрисовать только лишь точки /// </summary> /// <param name="n"></param> /// <param name="coeff"></param> /// <param name="deltaSmStep"></param> /// <param name="deltaSmStep"></param> public static List <Point3D> GetCriticalArea(int n, double coeff, double deltaSmInitialStep = 1, double deltaCoeffStep = 1) { if (deltaSmInitialStep <= 0 || deltaCoeffStep <= 0) { throw new Exception("Недопустимые аргументы, должны быть > 0!"); } List <Point3D> areaUp = new List <Point3D>(); List <Point3D> areaBottom = new List <Point3D>(); DACEmulator emulator = new DACEmulator(n, coeff, 0, 0, 0); //Нижняя и верхняя половины области int edgesCount = 0; areaUp = GetPointsOfCriticalArea(emulator, DACEmulator.Delta.Coeff, DACEmulator.Delta.SM, deltaSmInitialStep, deltaCoeffStep); emulator.DeltaCoeff = 0; emulator.DeltaIndex = 0; emulator.DeltaSM = 0; areaBottom = GetPointsOfCriticalArea(emulator, DACEmulator.Delta.Coeff, DACEmulator.Delta.SM, deltaSmInitialStep, -deltaCoeffStep); edgesCount = areaUp.Count; for (int i = 0; i < edgesCount; i++) { emulator.DeltaCoeff = areaUp[i].X; emulator.DeltaIndex = 0; List <Point3D> edgeUp = GetPointsOfCriticalArea(emulator, areaBottom[i].Y, areaUp[i].Y, DACEmulator.Delta.SM, DACEmulator.Delta.Index, deltaSmInitialStep, deltaCoeffStep / 10000); emulator.DeltaCoeff = areaUp[i].X; emulator.DeltaIndex = 0; List <Point3D> edgeBottom = GetPointsOfCriticalArea(emulator, areaBottom[i].Y, areaUp[i].Y, DACEmulator.Delta.SM, DACEmulator.Delta.Index, deltaSmInitialStep, -deltaCoeffStep / 10000); edgeBottom.Reverse(); edgeUp.AddRange(edgeBottom); areaUp.AddRange(edgeUp); } areaBottom.Reverse(); //areaUp.AddRange(areaBottom); areaUp.RemoveRange(0, edgesCount); return(areaUp); }
public static List <ParamsPolygon> GetPolygonsOfCriticalArea(int n, double coeff, double deltaSmInitialStep = 1, double deltaCoeffStep = 1) { if (deltaSmInitialStep <= 0 || deltaCoeffStep <= 0) { throw new Exception("Недопустимые аргументы, должны быть > 0!"); } Log("Построение основы... Подсчет точек... 0%"); List <ParamsPolygon> polygons = new List <ParamsPolygon>(); List <Point3D> areaUp = new List <Point3D>(); List <Point3D> areaBottom = new List <Point3D>(); List <Point3D> areaResult = new List <Point3D>(); DACEmulator emulator = new DACEmulator(n, coeff, 0, 0, 0);//Нижняя и верхняя половины области int edgesCount = 0; areaUp = GetPointsOfCriticalArea(emulator, DACEmulator.Delta.Coeff, DACEmulator.Delta.SM, deltaSmInitialStep, deltaCoeffStep); emulator.DeltaCoeff = 0; emulator.DeltaIndex = 0; emulator.DeltaSM = 0; areaBottom = GetPointsOfCriticalArea(emulator, DACEmulator.Delta.Coeff, DACEmulator.Delta.SM, deltaSmInitialStep, -deltaCoeffStep); edgesCount = areaUp.Count; areaResult.AddRange(areaUp); List <Point3D> edgePrevious = new List <Point3D>(); for (int i = 0; i < deltaSmInitialStep * 2; i++) { edgePrevious.Add(areaUp[0]); } for (int i = 0; i < edgesCount; i++) { emulator.DeltaCoeff = areaUp[i].X; emulator.DeltaIndex = 0; List <Point3D> edgeUp = GetPointsOfCriticalArea(emulator, areaBottom[i].Y, areaUp[i].Y, DACEmulator.Delta.SM, DACEmulator.Delta.Index, deltaSmInitialStep, deltaCoeffStep); emulator.DeltaCoeff = areaUp[i].X; emulator.DeltaIndex = 0; List <Point3D> edgeBottom = GetPointsOfCriticalArea(emulator, areaBottom[i].Y, areaUp[i].Y, DACEmulator.Delta.SM, DACEmulator.Delta.Index, deltaSmInitialStep, -deltaCoeffStep); edgeBottom.Reverse(); edgeUp.AddRange(edgeBottom); areaResult.AddRange(edgeUp); if (i == edgesCount - 1) { edgeUp.Clear(); for (int k = 0; k < deltaSmInitialStep * 2; k++) { edgeUp.Add(new Point3D(areaUp[areaUp.Count - 1].X, areaUp[areaUp.Count - 1].Y, areaBottom[areaUp.Count - 1].Z)); } } if (i > 0) { ParamsPolygon polygon = null; for (int j = 0; j < edgeUp.Count - 1; j++) { polygon = new ParamsPolygon(); polygon.Vertexs.Add(edgePrevious[j]); polygon.Vertexs.Add(edgePrevious[j + 1]); polygon.Vertexs.Add(edgeUp[j + 1]); polygon.Vertexs.Add(edgeUp[j]); polygons.Add(polygon); } polygon = new ParamsPolygon(); polygon.Vertexs.Add(edgePrevious[edgePrevious.Count - 1]); polygon.Vertexs.Add(edgePrevious[0]); polygon.Vertexs.Add(edgeUp[0]); polygon.Vertexs.Add(edgeUp[edgeUp.Count - 1]); polygons.Add(polygon); Point3D[] pointsPrevious = new Point3D[edgeUp.Count]; edgeUp.CopyTo(pointsPrevious); edgePrevious = pointsPrevious.ToList(); } Log("Создание полигонов области допустимых значений... " + (i / edgesCount) + "%"); } areaBottom.Reverse(); //areaResult.AddRange(areaBottom); areaResult.RemoveRange(0, edgesCount); Log("Готово! 100%"); return(polygons); }
/// <summary> /// Поиск области допустимых значений критических параметров для двумерного случая, /// то есть для deltaSm и deltaK /// Идея такова: на плоскости X, Y находится верхняя и нижняя части области areaUp и areaBottom и объединяются в общую область /// Затем по оси Z строятся дуги edgeUp (верхняя) и edgeBottom (нижняя) - они также объединяются в одну плоскость /// Таким образом строятся ребра, после чего все записывается в один массив точек /// Ребра были сделаны для того, чтобы их потом последовательно можно было соединить линиями /// А можно и отрисовать только лишь точки /// </summary> /// <param name="n"></param> /// <param name="coeff"></param> /// <param name="deltaSmStep"></param> /// <param name="deltaSmStep"></param> public static ParamsModel3D GetCriticalAreaSpecialEditionOfTheBestPractises(int n, double coeff, double deltaSmInitialStep = 1, double deltaCoeffStep = 1) { if (deltaSmInitialStep <= 0 || deltaCoeffStep <= 0) { throw new Exception("Недопустимые аргументы, должны быть > 0!"); } List <List <Point3D> > edges = new List <List <Point3D> >(); List <Point3D> edgeHorizontalUpMin = new List <Point3D>(); List <Point3D> edgeHorizontalBottomMin = new List <Point3D>(); List <Point3D> edgeHorizontalUpMax = new List <Point3D>(); List <Point3D> edgeHorizontalBottomMax = new List <Point3D>(); List <Point3D> areaUp = new List <Point3D>(); List <Point3D> areaBottom = new List <Point3D>(); DACEmulator emulator = new DACEmulator(n, coeff, 0, 0, 0); //Нижняя и верхняя половины области int edgesCount = 0; areaUp = GetPointsOfCriticalArea(emulator, DACEmulator.Delta.Coeff, DACEmulator.Delta.SM, deltaSmInitialStep, deltaCoeffStep); emulator.DeltaCoeff = 0; emulator.DeltaIndex = 0; emulator.DeltaSM = 0; areaBottom = GetPointsOfCriticalArea(emulator, DACEmulator.Delta.Coeff, DACEmulator.Delta.SM, deltaSmInitialStep, -deltaCoeffStep); edgesCount = areaUp.Count; for (int i = 0; i < edgesCount; i++) { List <Point3D> edge = new List <Point3D>(); emulator.DeltaCoeff = areaUp[i].X; emulator.DeltaIndex = 0; List <Point3D> edgeUp = GetPointsOfCriticalArea(emulator, areaBottom[i].Y, areaUp[i].Y, DACEmulator.Delta.SM, DACEmulator.Delta.Index, deltaSmInitialStep, deltaCoeffStep); edge.AddRange(edgeUp); emulator.DeltaCoeff = areaUp[i].X; emulator.DeltaIndex = 0; List <Point3D> edgeBottom = GetPointsOfCriticalArea(emulator, areaBottom[i].Y, areaUp[i].Y, DACEmulator.Delta.SM, DACEmulator.Delta.Index, deltaSmInitialStep, -deltaCoeffStep); //edgeBottom.Reverse(); //Формирование боковых граней Point3D pointUpMax = edgeUp[edgeUp.Count - 1]; Point3D pointUpMin = edgeUp[0]; Point3D pointBottomMax = edgeBottom[edgeUp.Count - 1]; Point3D pointBottomMin = edgeBottom[0]; float stepMax = (pointUpMax.Z - pointBottomMax.Z) / (float)(deltaSmInitialStep - 1); for (int j = 0; j < deltaSmInitialStep; j++) { edge.Add(new Point3D(pointUpMax.X, pointUpMax.Y, pointUpMax.Z - stepMax * j)); } edgeBottom.Reverse(); float stepMin = (pointUpMin.Z - pointBottomMin.Z) / (float)(deltaSmInitialStep - 1); for (int j = 0; j < deltaSmInitialStep; j++) { edge.Add(new Point3D(pointBottomMin.X, pointBottomMin.Y, pointBottomMin.Z + stepMin * j)); } edgeHorizontalUpMin.Add(pointUpMin); edgeHorizontalUpMax.Add(pointUpMax); edgeHorizontalBottomMin.Add(pointBottomMin); edgeHorizontalBottomMax.Add(pointBottomMax); //Строим заднюю стенку //if (edgesCount > 0 && i == edgesCount - 1) //{ // float stepSm = (pointUpMax.Y - pointUpMin.Y) / (float)(deltaSmInitialStep - 1); // for (int j = 0; j < deltaSmInitialStep; j++) // for (int k = 0; k < deltaSmInitialStep; k++) // areaOfWalls.Add(new Point3D(pointBottomMin.X, pointBottomMin.Y + stepSm * j, edgeBottom[j].Z + stepMin * k)); //} edgeUp.AddRange(edgeBottom); areaUp.AddRange(edgeUp); edges.Add(edge); } edgeHorizontalUpMax.Reverse(); edgeHorizontalUpMin.AddRange(edgeHorizontalUpMax); edgeHorizontalBottomMax.Reverse(); edgeHorizontalBottomMin.AddRange(edgeHorizontalBottomMax); edges.Add(edgeHorizontalUpMin); edges.Add(edgeHorizontalBottomMin); areaBottom.Reverse(); //areaUp.AddRange(areaBottom); areaUp.RemoveRange(0, edgesCount); return(new ParamsModel3D(edges, areaUp)); }
public static ParamsContainer TestingDelta(int n, double coeff, DACEmulator.Delta delta, double initialStep = 1, double accuracy = 0.0001, double deltaCoeff = 0, double deltaIndex = 0, double deltaSM = 0, bool isAllowedValues = false) { int countNumbers = (int)Math.Pow(2, n); List <int> indexes = new List <int>(); ParamsContainer container = new ParamsContainer(n, coeff, deltaCoeff, deltaIndex, deltaSM); LongBits inputBinaryCode = new LongBits(0, n), outputBinaryCode = inputBinaryCode; DACEmulator emulator = new DACEmulator(n, coeff, deltaCoeff, deltaIndex, deltaSM); while (Math.Abs(initialStep * 2) > accuracy) { inputBinaryCode = outputBinaryCode; while (inputBinaryCode == outputBinaryCode) { emulator.DeltaCoeff = deltaCoeff; emulator.DeltaIndex = deltaIndex; emulator.DeltaSM = deltaSM; for (int x = 0; x < countNumbers; x++) { inputBinaryCode = new LongBits(x, n); outputBinaryCode = emulator.GetDKFromComparators(x); if (inputBinaryCode != outputBinaryCode) { break; } } if (inputBinaryCode == outputBinaryCode) { if (delta == DACEmulator.Delta.Coeff) { deltaCoeff += initialStep; } else if (delta == DACEmulator.Delta.Index) { deltaIndex += initialStep; } else if (delta == DACEmulator.Delta.SM) { deltaSM += initialStep; } } } if (delta == DACEmulator.Delta.Coeff) { deltaCoeff -= initialStep; } else if (delta == DACEmulator.Delta.Index) { deltaIndex -= initialStep; } else if (delta == DACEmulator.Delta.SM) { deltaSM -= initialStep; } initialStep /= 2; } //Корректировка значений, если необходимо if (isAllowedValues) { if (delta == DACEmulator.Delta.Coeff) { emulator.DeltaCoeff -= initialStep * 2; } else if (delta == DACEmulator.Delta.Index) { emulator.DeltaIndex -= initialStep * 2; } else if (delta == DACEmulator.Delta.SM) { emulator.DeltaSM -= initialStep * 2; } } for (int x = 0; x < countNumbers; x++) { indexes.AddRange(emulator.GetEKPErrorFromComparators(x).ToList()); inputBinaryCode = new LongBits(x, n); outputBinaryCode = emulator.GetDKFromComparators(x); if (inputBinaryCode != outputBinaryCode) { container.ErrorIndexesFromInputAndOutputCodes.Add(x); } container.InputBinaryCodes.Add(inputBinaryCode); container.OutputBinaryCodes.Add(outputBinaryCode); } container.DeltaCoeff = emulator.DeltaCoeff; container.DeltaIndex = emulator.DeltaIndex; container.DeltaSM = emulator.DeltaSM; container.ComparatorsErrorIndexes = indexes.Distinct().ToArray(); return(container); }