private void saveTechnology(Technology tech)
 {
     DBWorker dbConnection = new DBWorker();
     if (dbConnection.isConnected)
     {
         tech.id = dbConnection.GetID(DbSelect.TechID) + 1;
         if (dbConnection.InsertModel(task, tech) == -1)
         {
             MessageBox.Show("Ошибка сохранения технологии");
             tech.id = -1;
         }
         else
         {
             if (tech.isCorrected != true) MessageBox.Show("Cохранено!");
             labelOptID.Text = "ID: " + tech.id.ToString();
         }
     }
 }
        private void optimizeBtn_Click(object sender, RoutedEventArgs e)
        {
            if (modelRegress == null)
            {
                Log.Text = "Регрессионная модель не загружена";
                return;
            }
            if (modelDescret == null)
            {
                Log.Text = "Дискретная модель не загружена";
                return;
            }
            for (int i=0; i<modelRegress.x.Count; i++)
                if (modelRegress.x[i] != modelDescret.x[i])
                {
                    Log.Text = "Дискретная и регрессионная модель используют разные факторы!";
                    return;
                }
            for (int i = 0; i < modelRegress.y.Count; i++)
                if (modelRegress.y[i] != modelDescret.y[i])
                {
                    Log.Text = "Дискретная и регрессионная модель используют разные выходные свойства!";
                    return;
                }
            for(int i=0; i<modelRegress.y.Count; i++)
                if ( yOptData[i].val1 == -1 )
                {
                    Log.Text = "Не выбраны оптимальные значения свойств";
                    return;
                }

            double[] yOpt = new double[modelRegress.y.Count];
            for (int i = 0; i < modelRegress.y.Count; i++) yOpt[i] = yOptData[i].val1;
            modelOpt = new CondOptModel(modelRegress, modelDescret, yOpt, Convert.ToDouble(epsgTextBox.Text),
                Convert.ToDouble(epsxTextBox.Text), Convert.ToInt32(iterTextBox.Text));
            technology = modelOpt.StartOptimize(); //численный градиент

            SetTechnology();
        }
        private void correctBtn_Click(object sender, RoutedEventArgs e)
        {
            if (technology == null)
            {
                Log.Text = "Технология не загружена";
                return;
            }
            if (modelDescret == null)
            {
                Log.Text = "Дискретная модель не загружена";
                return;
            }
            if (modelRegress == null)
            {
                Log.Text = "Регрессионная модель не загружена";
                return;
            }
            for (int i = 0; i < modelRegress.x.Count; i++)
                if (modelRegress.x[i] != modelDescret.x[i])
                {
                    Log.Text = "Модели используют разные факторы!";
                    return;
                }

            double[] xDone = new double[xOptData.Count];
            for (int i = 0; i < xOptData.Count; i++) xDone[i] = xOptData[i].val2;
            CondOptModel modelCor = new CondOptModel(modelRegress, modelDescret, technology,Convert.ToDouble(epsgTextBox2.Text),
                Convert.ToDouble(epsxTextBox2.Text), Convert.ToInt32(iterTextBox2.Text),xDone);
            technologyCorrected = modelCor.StartCorrect();
            //заполняем результаты
            for (int i = 0; i < modelRegress.x.Count; i++) xOptData[i].val2 = technologyCorrected.xOpt[i];
            XcurrentGrid.ItemsSource = null;
            XcurrentGrid.ItemsSource = xOptData;
            for (int i = 0; i < modelRegress.y.Count; i++)
            {
                yOptData[i].val2 = modelCor.yModel[i];
                yOptData[i].val3 = technologyCorrected.error[i];
            }

            YcurrentGrid.Columns[2].Visibility = System.Windows.Visibility.Visible;
            YcurrentGrid.Columns[3].Visibility = System.Windows.Visibility.Visible;
            YcurrentGrid.ItemsSource = null;
            YcurrentGrid.ItemsSource = yOptData;
            Log.Text = "Технология скорректирована!";

            List<itemGrid> YnotCorrectedData = new List<itemGrid>();
            for (int i = 0; i < yOptData.Count; i++)
                YnotCorrectedData.Add(new itemGrid(yOptData[i].header, yOptData[i].val1));
            double[] oldOpt = new double[technology.xOpt.Count];
            for (int i = 0; i < oldOpt.Length; i++) oldOpt[i] = technology.xOpt[i];
            for (int i = 0; i < yOptData.Count; i++)
            {
                if (modelRegress.isUpgraded) YnotCorrectedData[i].val2 = modelRegress.equation[i].Calculate(oldOpt, modelRegress.typesF);
                else YnotCorrectedData[i].val2 = modelRegress.equation[i].Calculate(xDone);
                YnotCorrectedData[i].val3 = Math.Abs(YnotCorrectedData[i].val2 - YnotCorrectedData[i].val1);
            }
            YolDcurrentGrid.ItemsSource = null;
            YolDcurrentGrid.ItemsSource = YnotCorrectedData;

            labelCorID.Text = "ID: local";
            labelCorDate.Text = "Дата: " + DateTime.Now.Date.ToShortDateString();
            labelCorGOST.Text = labelDesGOST.Text;
            labelCorMark.Text = labelDesMark.Text;
            labelCorOptID.Text = "ID исходной техн-ии: " + technologyCorrected.baseTechnologyID;
            labelCorDesID.Text = "ID дескр. модели: " + modelDescret.id.ToString();
            technologyCorrected.mark = modelDescret.mark;
            technologyCorrected.GOST = modelDescret.GOST;
            technologyCorrected.date = DateTime.Now.Date;
            expanderCor.IsExpanded = true;
        }
示例#4
0
 public CondOptModel(RegressionModel regr, DescrModel descr, Technology tech, double _epsg, double _epsi, int _iter, double[] _xCur)
 {
     regModel = regr;
     desModel = descr;
     epsg = _epsg;
     epsx = _epsi;
     epsi = _epsi;
     iter = _iter;
     yModel = new double[regModel.y.Count];
     technology = tech;
     technology.baseTechnologyID = tech.id;
     technology.id = -1;
     xDone = _xCur;
     for (int i = 0; i < xDone.Length; i++)
         if (xDone[i] == -1)
         {
             numDone = i;
             break;
         }
 }
示例#5
0
        public CondOptModel(RegressionModel regr, DescrModel descr, double[] _y, double _epsg, double _epsi, int _iter)
        {
            regModel = regr;
            desModel = descr;
            epsg = _epsg;
            epsx = _epsi;
            epsi = _epsi;
            iter = _iter;
            yModel = new double[regModel.y.Count];

            technology = new Technology(regr.x, regr.y, descr.id, regr.id, _y);
        }
示例#6
0
        private void correctBtn_Click(object sender, RoutedEventArgs e)
        {
            if (technology == null)
            {
                Log.Text = "Технология не загружена";
                return;
            }
            if (modelDescret == null)
            {
                Log.Text = "Дискретная модель не загружена";
                return;
            }
            if (modelRegress == null)
            {
                Log.Text = "Регрессионная модель не загружена";
                return;
            }
            for (int i = 0; i < modelRegress.x.Count; i++)
            {
                if (modelRegress.x[i] != modelDescret.x[i])
                {
                    Log.Text = "Модели используют разные факторы!";
                    return;
                }
            }

            double[] xDone = new double[xOptData.Count];
            for (int i = 0; i < xOptData.Count; i++)
            {
                xDone[i] = xOptData[i].val2;
            }
            CondOptModel modelCor = new CondOptModel(modelRegress, modelDescret, technology, Convert.ToDouble(epsgTextBox2.Text),
                                                     Convert.ToDouble(epsxTextBox2.Text), Convert.ToInt32(iterTextBox2.Text), xDone);

            technologyCorrected = modelCor.StartCorrect();
            //заполняем результаты
            for (int i = 0; i < modelRegress.x.Count; i++)
            {
                xOptData[i].val2 = technologyCorrected.xOpt[i];
            }
            XcurrentGrid.ItemsSource = null;
            XcurrentGrid.ItemsSource = xOptData;
            for (int i = 0; i < modelRegress.y.Count; i++)
            {
                yOptData[i].val2 = modelCor.yModel[i];
                yOptData[i].val3 = technologyCorrected.error[i];
            }

            YcurrentGrid.Columns[2].Visibility = System.Windows.Visibility.Visible;
            YcurrentGrid.Columns[3].Visibility = System.Windows.Visibility.Visible;
            YcurrentGrid.ItemsSource           = null;
            YcurrentGrid.ItemsSource           = yOptData;
            Log.Text = "Технология скорректирована!";

            List <itemGrid> YnotCorrectedData = new List <itemGrid>();

            for (int i = 0; i < yOptData.Count; i++)
            {
                YnotCorrectedData.Add(new itemGrid(yOptData[i].header, yOptData[i].val1));
            }
            double[] oldOpt = new double[technology.xOpt.Count];
            for (int i = 0; i < oldOpt.Length; i++)
            {
                oldOpt[i] = technology.xOpt[i];
            }
            for (int i = 0; i < yOptData.Count; i++)
            {
                if (modelRegress.isUpgraded)
                {
                    YnotCorrectedData[i].val2 = modelRegress.equation[i].Calculate(oldOpt, modelRegress.typesF);
                }
                else
                {
                    YnotCorrectedData[i].val2 = modelRegress.equation[i].Calculate(xDone);
                }
                YnotCorrectedData[i].val3 = Math.Abs(YnotCorrectedData[i].val2 - YnotCorrectedData[i].val1);
            }
            YolDcurrentGrid.ItemsSource = null;
            YolDcurrentGrid.ItemsSource = YnotCorrectedData;

            labelCorID.Text          = "ID: local";
            labelCorDate.Text        = "Дата: " + DateTime.Now.Date.ToShortDateString();
            labelCorGOST.Text        = labelDesGOST.Text;
            labelCorMark.Text        = labelDesMark.Text;
            labelCorOptID.Text       = "ID исходной техн-ии: " + technologyCorrected.baseTechnologyID;
            labelCorDesID.Text       = "ID дескр. модели: " + modelDescret.id.ToString();
            technologyCorrected.mark = modelDescret.mark;
            technologyCorrected.GOST = modelDescret.GOST;
            technologyCorrected.date = DateTime.Now.Date;
            expanderCor.IsExpanded   = true;
        }