예제 #1
0
        /// <summary>
        /// Faz a leitura de uma matriz de valores numéricos.
        /// </summary>
        /// <param name="lines">The number of lines.</param>
        /// <param name="columns">The number of columns.</param>
        /// <param name="arrayString">O texto que representa a matriz.</param>
        /// <param name="defaultValue">O valor por defeito.</param>
        /// <returns>A matriz lida.</returns>
        public SparseDictionaryMathMatrix <double> ReadArray(
            int lines,
            int columns,
            string arrayString,
            double defaultValue = 0)
        {
            var expressionParser   = new DoubleExpressionParser();
            var reader             = new StringReader(arrayString);
            var stringSymbolReader = new StringSymbolReader(reader, false);
            var arrayMatrixFactory = new SparseDictionaryMathMatrixFactory <double>();
            var arrayMatrixReader  = new ConfigMatrixReader <double, IMathMatrix <double>, string, string>(
                lines,
                columns);

            arrayMatrixReader.MapInternalDelimiters("left_bracket", "right_bracket");
            arrayMatrixReader.AddBlanckSymbolType("blancks");
            arrayMatrixReader.SeparatorSymbType = "comma";

            var matrix = default(IMathMatrix <double>);

            if (arrayMatrixReader.TryParseMatrix(
                    stringSymbolReader,
                    expressionParser,
                    (i, j) => arrayMatrixFactory.CreateMatrix(i, j, defaultValue),
                    out matrix))
            {
                return(matrix as SparseDictionaryMathMatrix <double>);
            }
            else
            {
                throw new ArgumentException("Can't read the specified matrix.");
            }
        }
        public void ComputeCostsCoefficientsTest()
        {
            var field             = new DoubleField();
            var revisedSimplexAlg = new RevisedSimplexAlgorithm <double>(
                Comparer <double> .Default,
                field);
            var target    = new PrivateObject(revisedSimplexAlg);
            var etaVector = new double[4];

            // Fábricas úteis para o teste dos quatro cenários.
            var arrayMatrixFactory        = new ArrayMathMatrixFactory <double>();
            var squareArrayMatrixFactory  = new ArraySquareMatrixFactory <double>();
            var sparseMatrixFactory       = new SparseDictionaryMathMatrixFactory <double>();
            var squareSparseMatrixFactory = new SparseDictionarySquareMatrixFactory <double>();

            this.TestComputeCostsCoefficients(target, squareArrayMatrixFactory, 0, arrayMatrixFactory, 0, etaVector);
            this.TestComputeCostsCoefficients(target, squareArrayMatrixFactory, 0, sparseMatrixFactory, 0, etaVector);
            this.TestComputeCostsCoefficients(target, squareSparseMatrixFactory, 0, arrayMatrixFactory, 0, etaVector);
            this.TestComputeCostsCoefficients(target, squareSparseMatrixFactory, 0, sparseMatrixFactory, 0, etaVector);
        }