private void CheckRepair(RepairMathModel repair)
 {
     if (repair.MaxPumps.Count() != PumpsCount)
     {
         throw new Exception();
     }
 }
        /// <summary>
        /// Система "МЕНЬШЕ ИЛИ РАВНО"
        /// </summary>
        /// <param name="repair"></param>
        /// <returns></returns>
        public Tuple <double[][], double[]> GetSystemOfInequalities(RepairMathModel repair)
        {
            CheckRepair(repair);

            int rowsCount = PumpsCount * 2 + 1;

            double[][] A = new double[rowsCount][];
            double[]   b = new double[rowsCount];

            A[rowsCount - 1] = new double[PumpsCount];
            for (int i = 0; i < PumpsCount; i++)
            {
                A[i * 2]        = new double[PumpsCount];
                A[i * 2 + 1]    = new double[PumpsCount];
                A[i * 2][i]     = 1.0;
                A[i * 2 + 1][i] = -1.0;
                b[i * 2]        = Math.Min(GpumpMax[i], repair.MaxPumps[i]);
                b[i * 2 + 1]    = -GpumpMin[i];

                A[rowsCount - 1][i] = pumpSign[i];
            }
            b[rowsCount - 1] = repair.MaxOutput - Gin;

            return(new Tuple <double[][], double[]>(A, b));
        }
        public bool CanUse(RepairMathModel repair)
        {
            CheckRepair(repair);

            return(repair.MaxInput >= Gin &&
                   GpumpMin.Zip(repair.MaxPumps, (m, u) => m <= u).All(x => x) &&
                   GpumpMin.Zip(pumpSign, (x, y) => x * y).Sum() + Gin <= repair.MaxOutput);
        }
        public bool CanPump(double[] Gpumps, RepairMathModel repair)
        {
            CheckRepair(repair);
            CheckPumps(Gpumps);

            Tuple <double[][], double[]> ineq = GetSystemOfInequalities(repair);

            // Смотрим, можно или нет качать
            for (int i = 0; i < ineq.Item1.Count(); i++)
            {
                var multipleResult = ineq.Item1[i].Zip(Gpumps, (x, y) => x * y).Sum();
                if (multipleResult - ineq.Item2[i] > EPS)
                {
                    return(false);
                }
            }

            return(true);
        }
        public double[] GetNearestPumpsPoit(double[] Gpumps, RepairMathModel repair, double[] pumpsPriority = null)
        {
            CheckRepair(repair);
            CheckPumps(Gpumps);
            if (pumpsPriority == null)
            {
                pumpsPriority = pumpSign.Select(x => 1.0).ToArray();
            }
            else
            {
                if (pumpsPriority.Count() != PumpsCount)
                {
                    throw new Exception();
                }
                if (pumpsPriority.Any(x => x < 0))
                {
                    throw new Exception();
                }
            }

            var system = GetSystemOfInequalities(repair);

            double[,] A = system.Item1.ToMatrix().Multiply(-1.0);
            double[] b = system.Item2.Multiply(-1.0);

            double[,] Q = new double[PumpsCount, PumpsCount];
            double[] d = new double[PumpsCount];

            for (int i = 0; i < PumpsCount; i++)
            {
                Q[i, i] = 2.0 * pumpsPriority[i] * pumpsPriority[i];
                d[i]    = pumpsPriority[i] * pumpsPriority[i] * -2.0 * Gpumps[i];
            }

            return(AlgorithmHelper.SolveQP(Q, d, A, b, 0));
        }
Example #6
0
 public RepairMathModel(RepairMathModel p)
 {
     _maxInput  = p._maxInput;
     _maxPumps  = p._maxPumps.ToList().ToArray();
     _maxOutput = p._maxOutput;
 }