示例#1
0
        public Dictionary <int, Restrictions> getListOfComputedPoints(SimplexPlanningParams param)
        {
            Dictionary <int, Restrictions> tempIndexOfRestrictions = new Dictionary <int, Restrictions>();

            tempIndexOfRestrictions.Clear();

            if (param.equalRowsIndex.Count != 0)
            {
                var temp =
                    from x in param.indexOfRestrictions
                    join y in param.equalRowsIndex on x.Key equals y
                    select new { Key = y, x.Value.Filling, x.Value.Force };

                int z = 0;

                foreach (var element in temp)
                {
                    tempIndexOfRestrictions.Add(z, new Restrictions(element.Filling, element.Force));
                    z++;
                }

                param.indexOfRestrictions.Clear();
                param.indexOfRestrictions = tempIndexOfRestrictions.ToDictionary(kvp => kvp.Key, kvp => new Restrictions(kvp.Value.Filling, kvp.Value.Force));
            }

            return(param.indexOfRestrictions);
        }
示例#2
0
        public bool CheckRestrictions(SimplexPlanningParams param, FunctionParams funcParam)
        {
            bool breakFlag = true;

            //ищем минимальное значение, после подсчётов матрицы в функции
            funcParam.MinFilling = param.indexOfRestrictions.Select(v => v.Value.Filling).Min();
            funcParam.MaxForce   = param.indexOfRestrictions.Select(v => v.Value.Force).Max();

            double countOfGoodNodes = param.indexOfRestrictions.Where(v => v.Value.Filling >= 95).Count();

            if (param.arrayStatus == false && countOfGoodNodes < 2 && funcParam.MinFilling < 95)
            {
                MessageBox.Show("Choose another starting point!");
                breakFlag = false;
            }

            if (funcParam.MinFilling >= 95)
            {
                funcParam.Index        = param.indexOfRestrictions.Where(v => v.Value.Force == funcParam.MaxForce).Select(k => k.Key).FirstOrDefault();
                funcParam.IndexFilling = param.indexOfRestrictions.Where(v => v.Value.Force == funcParam.MaxForce).Select(v => v.Value.Filling).FirstOrDefault();
                funcParam.IndexForce   = param.indexOfRestrictions.Where(v => v.Value.Force == funcParam.MaxForce).Select(v => v.Value.Force).FirstOrDefault();
            }

            if (funcParam.MinFilling < 95)
            {
                funcParam.Index        = param.indexOfRestrictions.Where(v => v.Value.Filling == funcParam.MinFilling).Select(k => k.Key).FirstOrDefault();
                funcParam.IndexFilling = param.indexOfRestrictions.Where(v => v.Value.Filling == funcParam.MinFilling).Select(v => v.Value.Filling).FirstOrDefault();
                funcParam.IndexForce   = param.indexOfRestrictions.Where(v => v.Value.Filling == funcParam.MinFilling).Select(v => v.Value.Force).FirstOrDefault();
            }

            return(breakFlag);
        }
示例#3
0
        public int CheckNewRow(double[,] newArray, double[,] oldArray, SimplexPlanningParams param)
        {
            int newIndex = 0;

            double[] temp1 = new double[newArray.GetLength(1)];
            double[] temp2 = new double[newArray.GetLength(1)];

            param.equalRowsIndex.Clear();
            int k = 0;

            while (k < newArray.GetLength(0))
            {
                for (int i = 0; i <= k; i++)
                {
                    for (int j = 0; j < newArray.GetLength(1); j++)
                    {
                        temp1[j] = oldArray[i, j];
                    }
                }

                for (int i = 0; i < newArray.GetLength(0); i++)
                {
                    for (int j = 0; j < newArray.GetLength(1); j++)
                    {
                        temp2[j] = newArray[i, j];
                    }
                    if (temp1.SequenceEqual(temp2) == true)
                    {
                        newIndex++;
                        param.equalRowsIndex.Add(k);
                    }
                }

                k++;
            }

            return(newIndex++);
        }
示例#4
0
        public void AddingRow(double[,] original, SimplexPlanningParams param)
        {
            int lastRow    = original.GetUpperBound(0);
            int lastColumn = original.GetUpperBound(1);

            // Create new array.
            double[,] result = new double[lastRow + 2, lastColumn + 1];
            // Copy existing array into the new array.
            for (int i = 0; i <= lastRow; i++)
            {
                for (int x = 0; x <= lastColumn; x++)
                {
                    result[i, x] = original[i, x];
                }
            }
            // Add the new row.
            for (int i = 0; i < param.newCoordinate.Length; i++)
            {
                result[lastRow + 1, i] = param.newCoordinate[i];
            }

            param.finalArray = result;
        }
示例#5
0
        public void makeRewriteArray(SimplexPlanningParams param, FunctionParams funcParam, GeometryOptions model)
        {
            double[] x = new double[param.finalArray.Length];

            double[,] tempFinalArray = new double[param.finalArray.GetLength(0) - 1, param.finalArray.GetLength(1)];
            param.badCoordinate      = new double[param.finalArray.GetLength(1)];

            int currentRow = 0;

            for (int i = 0; i < param.finalArray.GetLength(0); i++)
            {
                if (i != funcParam.Index)
                {
                    for (int j = 0; j < param.finalArray.GetLength(1); j++)
                    {
                        tempFinalArray[currentRow, j] = param.finalArray[i, j];
                    }
                    currentRow++;
                }
                else
                {
                    for (int j = 0; j < param.finalArray.GetLength(1); j++)
                    {
                        param.badCoordinate[j] = param.finalArray[i, j];
                    }
                }
            }

            #region Проверка на зацикливание
            //сравнивание двух массивов на наличие одинаковой точки
            //если таково, то добавляем +2 в ячейку(т.к. сравниванием 2 массива)
            for (int i = 0; i < param.finalArray.GetLength(0); i++)
            {
                int Count = 2;
                for (int j = 0; j < param.finalArray.GetLength(1); j++)
                {
                    if (param.finalArray[i, j] == param.tempOldArray[i, j])
                    {
                        param.sameNodeSimplexCount[i, j] += Count;
                    }
                    else
                    {
                        param.sameNodeSimplexCount[i, j] = 0;
                    }
                }
            }
            //находим максимальную строку, по её сумме,
            //чтобы по ней посчитать сколько симплексов имеют одинаковую точку
            //симплексы могут иметь 2 одинаковые точки, но таких симплексов может быть 2 или 3
            //поэтому нужно отбросить такой вариант
            List <double> maxList = new List <double>();

            for (int i = 0; i < param.sameNodeSimplexCount.GetLength(0); i++)
            {
                double max = 0;
                for (int j = 0; j < param.sameNodeSimplexCount.GetLength(1); j++)
                {
                    max += param.sameNodeSimplexCount[i, j];
                }
                maxList.Add(max);
            }

            param.countOfArrays  = maxList.Max();
            param.countOfArrays /= (funcParam.getFactorsCount() * funcParam.getFactorsCount());

            param.Nmax = (1.65 * funcParam.getFactorsCount()) + (0.05 * Math.Pow(funcParam.getFactorsCount(), 2));

            //записываем новый массив в старый
            for (int i = 0; i < param.finalArray.GetLength(0); i++)
            {
                for (int j = 0; j < param.finalArray.GetLength(1); j++)
                {
                    param.tempOldArray[i, j] = param.finalArray[i, j];
                }
            }

            #endregion

            var newCoord = new NewCoordinate();

            newCoord.makeNewCoordinate(tempFinalArray, model, param, funcParam);

            var addRow = new AddRow();
            addRow.AddingRow(tempFinalArray, param);
        }
示例#6
0
        public void makeNewCoordinate(double[,] array, GeometryOptions model, SimplexPlanningParams param, FunctionParams funcParam)
        {
            double minRadius   = 10;
            double minFriction = 0.2;

            double maxRadius   = model.startBlankRadius * 1.25;
            double maxFriction = model.endFriction;

            param.newCoordinate = new double[array.GetLength(1)];

            double[,] temp = array;
            double[] f = new double[array.GetLength(1)];

            //новый шаг, который уменьшает размеры симплекса
            double newN = funcParam.getFactorsCount() + param.moreEps;

            if (param.countOfArrays > param.Nmax)
            {
                for (int i = 0; i < temp.GetLength(0); i++)
                {
                    for (int j = 0; j < temp.GetLength(1); j++)
                    {
                        f[j] += array[i, j];
                    }
                }

                for (int j = 0; j < temp.GetLength(1); j++)
                {
                    param.newCoordinate[j] = (2 * f[j] / newN) - param.badCoordinate[j];
                }
                param.moreEps += 0.005;
            }
            else
            {
                for (int i = 0; i < temp.GetLength(0); i++)
                {
                    for (int j = 0; j < temp.GetLength(1); j++)
                    {
                        f[j] += array[i, j];
                    }
                }

                for (int j = 0; j < temp.GetLength(1); j++)
                {
                    param.newCoordinate[j] = (2 * f[j] / funcParam.getFactorsCount()) - param.badCoordinate[j];
                }
            }

            #region проверка каждого элемента на мин и макс
            if (param.newCoordinate[0] < minRadius)
            {
                param.newCoordinate[0] = minRadius;
            }

            if (param.newCoordinate[1] < minFriction)
            {
                param.newCoordinate[1] = minFriction;
            }

            if (param.newCoordinate[0] > maxRadius)
            {
                param.newCoordinate[0] = maxRadius;
            }

            if (param.newCoordinate[1] > maxFriction)
            {
                param.newCoordinate[1] = maxFriction;
            }
            #endregion

            double tempStep = Math.Sqrt(Math.Pow(param.badCoordinate[0] - param.newCoordinate[0], 2)
                                        + Math.Pow(param.badCoordinate[1] - param.newCoordinate[1], 2));

            double[] tempPct = new double[param.newCoordinate.Length];

            for (int j = 0; j < tempPct.Length; j++)
            {
                tempPct[j] = (param.badCoordinate[j] * 1 / 100); //badCoordinate[j] * точность / 100
            }
            double maxPct = tempPct.Max();

            if (tempStep < maxPct)
            {
                param.Step = 0;
            }
            else
            {
                param.Step = 1;
            }
        }