private OptVector BuildVectorB(
            List <Func <double[], double> > equalityConstraints,
            List <InequalityConstraintProperties> inequalityConstraints,
            Func <double[], double> lagrangian,
            OptVector x)
        {
            double[] lagrangianDerivative = numericalDerivative.EvaluatePartialDerivative(lagrangian, x.MinArray, 1);

            OptVector lagrangianOut = new OptVector(lagrangianDerivative);

            OptVector equalityConstraintsResult = new OptVector(equalityConstraints.Count);

            for (int i = 0; i < equalityConstraints.Count; i++)
            {
                equalityConstraintsResult[i] = equalityConstraints[i](x.MinArray);
            }

            lagrangianOut.Add(equalityConstraintsResult);

            OptVector inequalityConstraintsResult = new OptVector(inequalityConstraints.Count(k => k.IsActive));
            int       resIndex = 0;

            for (int i = 0; i < inequalityConstraints.Count; i++)
            {
                if (inequalityConstraints[i].IsActive)
                {
                    inequalityConstraintsResult[resIndex] = inequalityConstraints[i].Function(x.MinArray);
                    resIndex++;
                }
            }

            lagrangianOut.Add(inequalityConstraintsResult);

            return(lagrangianOut * -1.0);
        }
        private OptVector[] BuildMatrixA(
            List <Func <double[], double> > equalityConstraints,
            List <InequalityConstraintProperties> inequalityConstraints,
            OptVector[] lagrangianHessian,
            OptVector x)
        {
            List <OptVector> constraintDerivative = new List <OptVector>();

            for (int i = 0; i < equalityConstraints.Count; i++)
            {
                constraintDerivative.Add(new OptVector(numericalDerivative.EvaluatePartialDerivative(equalityConstraints[i], x.MinArray, 1)));
            }

            for (int i = 0; i < inequalityConstraints.Count; i++)
            {
                if (inequalityConstraints[i].IsActive)
                {
                    constraintDerivative.Add(new OptVector(numericalDerivative.EvaluatePartialDerivative(inequalityConstraints[i].Function, x.MinArray, 1)));
                }
            }

            OptVector[] bufHessian = new OptVector[lagrangianHessian.Length];

            OptVector[] modifiedLagrangian = OptVector.Sum(lagrangianHessian, epsilonNw);

            Array.Copy(modifiedLagrangian, bufHessian, lagrangianHessian.Length);

            for (int i = 0; i < bufHessian.Length; i++)
            {
                OptVector buf = new OptVector(constraintDerivative.Count);

                for (int j = 0; j < constraintDerivative.Count; j++)
                {
                    buf[j] = constraintDerivative[j][i];
                }

                bufHessian[i].Add(buf);
            }

            var lagrangianList = bufHessian.ToList();

            foreach (var item in constraintDerivative)
            {
                var res = OptVector.Add(item, new OptVector(constraintDerivative.Count, -epsilonSe));
                lagrangianList.Add(res);
            }

            return(lagrangianList.ToArray());
        }
        private OptVector CalculateDirection(
            OptVector[] A,
            OptVector b,
            OptVector x,
            OptVector lambdaEq,
            OptVector lambdaIq)
        {
            OptVector leq        = new OptVector(lambdaEq);
            OptVector liq        = new OptVector(lambdaIq);
            OptVector startValue = OptVector.Add(x, leq);

            startValue = OptVector.Add(startValue, liq);

            //startValue = new MinVector(startValue.Count);
            OptVector result = linearSolver.Solve(A, b, startValue, 1000);

            return(result);
        }