Beispiel #1
0
        /// <summary>
        /// Links vector elements.
        /// </summary>
        /// <param name="vector">The vector.</param>
        /// <param name="row">The row variable.</param>
        private void LinkElement(ISparseVector <T> vector, Bridge <int> row)
        {
            var loc = Solver.ExternalToInternal(new MatrixLocation(row.Local, row.Local));

            // Do we need to create an element?
            var local_elt = vector.FindElement(loc.Row);

            if (local_elt == null)
            {
                // Check if solving will result in an element
                var first = vector.GetFirstInVector();
                if (first == null || first.Index > Solver.Size - Solver.Degeneracy)
                {
                    return;
                }
                local_elt = vector.GetElement(loc.Row);
            }
            if (local_elt == null)
            {
                return;
            }
            var parent_elt = Parent.Solver.GetElement(row.Global);

            _elements.Add(new Bridge <Element <T> >(local_elt, parent_elt));
        }
Beispiel #2
0
        private void Count(ISparseMatrix <T> matrix, ISparseVector <T> rhs, int step, int max)
        {
            ISparseMatrixElement <T> element;

            // Get the first element in the vector
            var rhsElement = rhs.GetFirstInVector();

            // Generate Markowitz row count
            for (var i = max; i >= step; i--)
            {
                // Set count to -1 initially to remove count due to pivot element
                var count = -1;
                element = matrix.GetFirstInRow(i);
                while (element != null && element.Column < step)
                {
                    element = element.Right;
                }
                while (element != null) // We want to count the elements outside the limit as well
                {
                    count++;
                    element = element.Right;
                }

                // Include elements on the Rhs vector
                while (rhsElement != null && rhsElement.Index < step)
                {
                    rhsElement = rhsElement.Below;
                }
                if (rhsElement != null && rhsElement.Index == i)
                {
                    count++;
                }

                _markowitzRow[i] = Math.Min(count, _maxMarkowitzCount);
            }

            // Generate Markowitz column count
            for (var i = step; i <= max; i++)
            {
                // Set count to -1 initially to remove count due to pivot element
                var count = -1;
                element = matrix.GetFirstInColumn(i);
                while (element != null && element.Row < step)
                {
                    element = element.Below;
                }
                while (element != null)
                {
                    count++;
                    element = element.Below;
                }
                _markowitzColumn[i] = Math.Min(count, _maxMarkowitzCount);
            }
        }