当前位置: 首页>>代码示例>>C#>>正文


C# DenseVector.ToList方法代码示例

本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Double.DenseVector.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# DenseVector.ToList方法的具体用法?C# DenseVector.ToList怎么用?C# DenseVector.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MathNet.Numerics.LinearAlgebra.Double.DenseVector的用法示例。


在下文中一共展示了DenseVector.ToList方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ModificatedDualIteration

        private static bool ModificatedDualIteration()
        {
            var vectorCollection = new List<Vector<double>>();
            foreach (var item in _task.Jb)
            {
                vectorCollection.Add(_task.A.Column(item));
            }

            var aBMatrix = DenseMatrix.OfColumnVectors(vectorCollection.ToArray());

            var bMatrix = aBMatrix.Inverse();

            // Step3
            var kappaList = bMatrix * _task.b;
            Vector<double> allKappaList = new DenseVector(_task.A.ColumnCount, 0);
            for (int i = 0; i < allKappaList.Count; i++)
            {
                if (_JNbUpper.Contains(i))
                {
                    allKappaList[i] = _task.dLower[i];
                }
                else if (_JNbLower.Contains(i))
                {
                    allKappaList[i] = _task.dUpper[i];
                }
                else
                {
                    allKappaList[i] = 0;
                }
            }

            kappaList = bMatrix * (_task.b - _task.A * allKappaList);

            for (int i = 0; i < _task.Jb.Count; i++)
            {
                allKappaList[_task.Jb[i]] = kappaList[i];
            }

            // Step3
            double kappaValue = 0;
            int kappaIndex = 0;
            var check = false;
            for (int i = 0; i < allKappaList.Count; i++)
            {
                if (allKappaList[i] > _task.dUpper[i] || allKappaList[i] < _task.dLower[i])
                {
                    check = true;
                    kappaValue = allKappaList[i];
                    kappaIndex = i;
                    break;
                }
            }

            if (!check)
            {
                _task.xo = allKappaList;
                //Logger.Log("Stopped at third step");
                _stopStep = 3;
                return false;
            }

            // Step4 is unnecessary

            // Step5
            var nk = kappaValue < _task.dLower[kappaIndex] ? 1 : -1;
            var deltaYT =
                nk * DenseVector.Create(_task.Jb.Count, i => i == _task.Jb.ToList().IndexOf(kappaIndex) ? 1 : 0)
                * DenseMatrix.OfColumnVectors(vectorCollection.ToArray()).Inverse();

            var nVector = new DenseVector(_task.A.ColumnCount);
            for (int i = 0; i < _task.A.ColumnCount; i++)
            {
                if (!_task.Jb.Contains(i))
                {
                    nVector[i] = (deltaYT * _task.A.Column(i));
                }
            }

            // Step6
            Vector<double> sigmaVector = new DenseVector(_task.A.ColumnCount);
            for (int i = 0; i < sigmaVector.Count; i++)
            {
                if (_task.dLower[i] == _task.dUpper[i])
                {
                    sigmaVector[i] = double.PositiveInfinity;
                }
                else if (_JNbUpper.Contains(i) && nVector[i] < Eps)
                {
                    sigmaVector[i] = -deltas[i] / nVector[i];
                }
                else if (_JNbLower.Contains(i) && nVector[i] > Eps)
                {
                    sigmaVector[i] = -deltas[i] / nVector[i];
                }
                else
                {
                    sigmaVector[i] = double.PositiveInfinity;
                }
            }

//.........这里部分代码省略.........
开发者ID:Kant8,项目名称:IOp,代码行数:101,代码来源:ModifiedDualSimplexMethod.cs

示例2: DualIteration

        private static bool DualIteration()
        {
            // Step1
            var vectorCollection = new List<Vector<double>>();
            foreach (var item in _Jb)
            {
                vectorCollection.Add(_A.Column(item));
            }

            var aBMatrix = DenseMatrix.OfColumnVectors(vectorCollection.ToArray());

            var bMatrix = aBMatrix.Inverse();

            var kappa = bMatrix * _b;

            // Step2
            if (kappa.ToList().TrueForAll(x => x >= Eps))
            {
                //Logger.Log("Stopped at second step");
                return false;
            }

            // Step3
            var minJ = kappa.MinimumIndex();
            var deltaYT = DenseVector.Create(_Jb.Length, i => i == minJ ? 1 : 0) * DenseMatrix.OfColumnVectors(vectorCollection.ToArray()).Inverse();
            var nVector = new DenseVector(_A.ColumnCount);

            for (int i = 0; i < _A.ColumnCount; i++)
            {
                if (!_Jb.Contains(i))
                {
                    nVector[i] = (deltaYT * _A.Column(i));
                }
            }

            if (nVector.ToList().TrueForAll(n => n >= Eps))
            {
                //Logger.Log("Stopped at third step");
                return false;
            }

            // Step4
            double sigma0 = Double.PositiveInfinity;
            int sigmaIndex = 0;
            var sigmaList = new DenseVector(_A.ColumnCount);
            for (int i = 0, j = 0; i < _A.ColumnCount; i++)
            {
                if (!_Jb.Contains(i) && (nVector[i] < 0))
                {
                    sigmaList[i] = ((_C[i] - _A.Column(i) * _Yb) / nVector[i]);
                    if (sigmaList[i] < sigma0)
                    {
                        sigma0 = sigmaList[i];
                        sigmaIndex = i;
                    }
                }
            }

            // Step5
            var newYb = _Yb.Add(sigma0 * deltaYT);
            _Yb = newYb;
            _Jb[minJ] = sigmaIndex;

            return true;
        }
开发者ID:Kant8,项目名称:IOp,代码行数:65,代码来源:DualSimplexMethod.cs


注:本文中的MathNet.Numerics.LinearAlgebra.Double.DenseVector.ToList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。