Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
        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);
        }
Exemplo n.º 6
0
        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);
        }
        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);
        }