예제 #1
0
        private static double EvaluateValue(Coefs coefs, double xVal)
        {
            double ret = coefs.Coef3 * xVal * xVal * xVal
                         + coefs.Coef2 * xVal * xVal + coefs.Coef1 * xVal + coefs.Coef0;

            return(ret);
        }
예제 #2
0
        public SymplexMatrix(ObjectiveFunction objectiveFunction, double[,] coefs, double[] basis, Sign[] signs)
            : base(coefs, basis, signs)
        {
            ObjectiveFunction = objectiveFunction;
            Variables         = new Coef[Coefs.GetLength(0)][];

            ValidateBasis();
            IntroduceBalanceVariable();
            IntroduceArtificialVariable();
        }
예제 #3
0
        public void SetSign(int row, Sign sign)
        {
            if (Coefs == null || Basis == null)
            {
                throw new ArgumentException("Не задан базис или коэффициенты при переменных");
            }

            if (row < 0 || row >= Coefs.GetLength(0))
            {
                throw new ArgumentException("Строка должна существовать");
            }

            Signs[row] = sign;
        }
예제 #4
0
        private static Coefs[] CalcCoefs(I_V_Point[] oriPoints)
        {
            int len = oriPoints.Length;

            Coefs[] CoefsArray = new Coefs[len - 1];
            for (int i = 0; i < len - 1; i++)
            {
                Coefs  coef   = new Coefs();
                double dy     = oriPoints[i + 1].Current - oriPoints[i].Current;
                double dx     = oriPoints[i + 1].Voltage - oriPoints[i].Voltage;
                double divdif = dy / dx;

                coef.Coef0 = oriPoints[i].Current;
                coef.Coef1 = 00;
                coef.Coef2 = 00;
                coef.Coef3 = 00;

                //yi=y(:,ind).';
                //dx = diff(x);
                //divdif = diff(yi)./dx;
                //else % set up the sparse, tridiagonal, linear system for the slopes at  X .
                //   b=zeros(n,yd);
                //   b(2:n-1)=3*(dx(2:n-1).*divdif(1:n-2)+dx(1:n-2).*divdif(2:n-1));
                //   x31=x(3)-x(1);xn=x(n)-x(n-2);
                //   b(1)=((dx(1)+2*x31)*dx(2)*divdif(1)+dx(1)^2*divdif(2))/x31;
                //   b(n)=(dx(n-1)^2*divdif(n-2)+(2*xn+dx(n-1))*dx(n-2)*divdif(n-1))/xn;

                //   c = spdiags([ [dx(2:n-1);xn;0] ...
                //        [dx(2);2*[dx(2:n-1)+dx(1:n-2)];dx(n-2)] ...
                //        [0;x31;dx(1:n-2)] ],[-1 0 1],n,n);

                //   % sparse linear equation solution for the slopes
                //   mmdflag = spparms('autommd');
                //   spparms('autommd',0);
                //   s=c\b;
                //   spparms('autommd',mmdflag);
                //   % convert to pp form
                //   c4=(s(1:n-1)+s(2:n)-2*divdif(1:n-1))./dx;
                //   c3=(divdif(1:n-1)-s(1:n-1))./dx - c4;
                //   pp=mkpp(x.', ...
                //      reshape([(c4./dx).' c3.' s(1:n-1).' yi(1:n-1).'], ...
                //               (n-1)*yd,4),yd);
            }

            return(CoefsArray);
        }
예제 #5
0
        public void MultiplyRow(int row, double number)
        {
            Basis[row] *= number;

            for (int j = 0; j < Coefs.GetLength(1); j++)
            {
                Coefs[row, j] *= number;

                Sign sign = GetSign(row);

                if (sign == Sign.LessOrEqual)
                {
                    SetSign(row, Sign.MoreOrEqual);
                }
                else if (sign == Sign.MoreOrEqual)
                {
                    SetSign(row, Sign.LessOrEqual);
                }
            }
        }
예제 #6
0
        public Coef GetIndexBasisElement(int row)
        {
            var coefs = Coefs.Where(it => it.Row == row && it.TypeCoef != TypeCoef.Default).ToArray();

            if (coefs.Length == 0)
            {
                return(null);
            }

            switch (coefs.Length)
            {
            case 0:
                return(null);

            case 1:
                return(coefs[0]);

            case 2:
                return(coefs[1]);

            default:
                throw new ArgumentException("Нестандартных переменных не может быть больше 2!");
            }
        }
예제 #7
0
 public int GetCountArt()
 {
     return(Coefs.Where(it => it.TypeCoef == TypeCoef.Art).Count());
 }
예제 #8
0
 public Coef GetArt(int row)
 {
     return(Coefs.Where(it => it.Row == row && it.TypeCoef == TypeCoef.Balance).FirstOrDefault());
 }