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);
        }
        public void Run_TriangDiagSymmDecompNoInverse()
        {
            // Definição dos domínios e fábricas.
            var integerDomain = new IntegerDomain();
            var fractionField = new FractionField <int>(integerDomain);

            // Definição dos algoritmos.
            var target       = new TriangDiagSymmDecompInverseAlg <Fraction <int> >();
            var triangDecomp = new ParallelTriangDiagSymmMatrixDecomp <Fraction <int> >(fractionField);

            var arraySquareMatrixFactory = new ArraySquareMatrixFactory <Fraction <int> >();
            var arrayMatrixFactory       = new ArrayMathMatrixFactory <Fraction <int> >();

            // A matriz
            var matrix = this.GetSingularMatrix(integerDomain);

            // Cálculos
            var triangDiagDecomp = triangDecomp.Run(
                matrix);
            var inverseMatrix = target.Run(
                triangDiagDecomp,
                arraySquareMatrixFactory,
                fractionField);

            // Verificação dos valores.
            var expected = ArrayMathMatrix <Fraction <int> > .GetIdentity(3, fractionField);

            var matrixMultiplication = new MatrixMultiplicationOperation <Fraction <int> >(
                arrayMatrixFactory,
                fractionField,
                fractionField);
            var actual = matrixMultiplication.Multiply(inverseMatrix, matrix);

            for (int i = 0; i < 3; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    Assert.AreEqual(expected[i, j], actual[i, j]);
                }
            }
        }
Exemplo n.º 3
0
        public void GetPolynomialDerivativeTest_IntegerMatrix()
        {
            // Os valores a serem lidos
            var polynomialText           = "[[1,2],[3,4]]*x^2-[[1,0],[0,1]]*x+[[7,6],[9,8]]";
            var polynomialDerivativeText = "[[2,4],[6,8]]*x+[[-1,0],[0,-1]]";
            var variableName             = "x";

            var arrayDelimiters = new Dictionary <string, string>();

            arrayDelimiters.Add("left_bracket", "right_bracket");

            // Os domínios responsáveis sobre as operações sobre os inteiros.
            var integerDomain    = new IntegerDomain();
            var longDomain       = new LongDomain();
            var bigIntegerDomain = new BigIntegerDomain();

            // Os leitore sde inteiros
            var integerParser    = new IntegerParser <string>();
            var longParser       = new LongParser <string>();
            var bigIntegerParser = new BigIntegerParser <string>();

            // As fábricas responsáveis pela instanciação de matrizes
            var integerSquareArrayMatrixfactory    = new ArraySquareMatrixFactory <int>();
            var longSquareArrayMatrixFactory       = new ArraySquareMatrixFactory <long>();
            var bigIntegerSquareArrayMatrixfactory = new ArraySquareMatrixFactory <BigInteger>();

            // Os anéis de matrizes
            var integerGenericMatrixRing = new GeneralMatrixRing <int>(
                2,
                integerSquareArrayMatrixfactory,
                integerDomain);
            var longGenericMatrixRing = new GeneralMatrixRing <long>(
                2,
                longSquareArrayMatrixFactory,
                longDomain);
            var bigIntegerGenericMatrixRing = new GeneralMatrixRing <BigInteger>(
                2,
                bigIntegerSquareArrayMatrixfactory,
                bigIntegerDomain);

            // Os objectos responsáveis pela conversão entre os coeficientes e o grau (inteiro)
            var integerMatrixConversion    = new CantConvertConversion <int, IMatrix <int> >();
            var longMatrixConversion       = new CantConvertConversion <int, IMatrix <long> >();
            var bigIntegerMatrixConversion = new CantConvertConversion <int, IMatrix <BigInteger> >();

            var integerMatrixConfigParser = new ConfigMatrixParser <int, IMatrix <int> >(
                integerParser,
                2,
                2,
                (i, j) => integerSquareArrayMatrixfactory.CreateMatrix(i, j));

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

            var longMatrixConfigParser = new ConfigMatrixParser <long, IMatrix <long> >(
                longParser,
                2,
                2,
                (i, j) => longSquareArrayMatrixFactory.CreateMatrix(i, j));

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

            var bigIntegerMatrixConfigParser = new ConfigMatrixParser <BigInteger, IMatrix <BigInteger> >(
                bigIntegerParser,
                2,
                2,
                (i, j) => bigIntegerSquareArrayMatrixfactory.CreateMatrix(i, j));

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

            // Leitura dos polinómios e subsequente teste.
            var integerPolynomial = TestsHelper.ReadUnivarPolynomial <IMatrix <int> >(
                polynomialText,
                integerGenericMatrixRing,
                integerMatrixConfigParser,
                integerMatrixConversion,
                variableName,
                arrayDelimiters);
            var integerExpectedDerivative = TestsHelper.ReadUnivarPolynomial(
                polynomialDerivativeText,
                integerGenericMatrixRing,
                integerMatrixConfigParser,
                integerMatrixConversion,
                variableName,
                arrayDelimiters,
                true);
            var integerActualDerivative = integerPolynomial.GetPolynomialDerivative(integerGenericMatrixRing);

            Assert.IsTrue(
                new UnivarPolynomNormalFormEqualityComparer <IMatrix <int> >(integerGenericMatrixRing).Equals(integerExpectedDerivative, integerActualDerivative),
                string.Format("Expected {0} isn't equal to actual {1}.", integerExpectedDerivative, integerActualDerivative));

            var longPolynomial = TestsHelper.ReadUnivarPolynomial(
                polynomialText,
                longGenericMatrixRing,
                longMatrixConfigParser,
                longMatrixConversion,
                variableName,
                arrayDelimiters);
            var longExpectedDerivative = TestsHelper.ReadUnivarPolynomial(
                polynomialDerivativeText,
                longGenericMatrixRing,
                longMatrixConfigParser,
                longMatrixConversion,
                variableName,
                arrayDelimiters,
                true);
            var longActualDerivative = longPolynomial.GetPolynomialDerivative(longGenericMatrixRing);

            Assert.IsTrue(
                new UnivarPolynomNormalFormEqualityComparer <IMatrix <long> >(longGenericMatrixRing).Equals(longExpectedDerivative, longActualDerivative),
                string.Format("Expected {0} isn't equal to actual {1}.", integerExpectedDerivative, integerActualDerivative));

            var bigIntegerPolynomial = TestsHelper.ReadUnivarPolynomial(
                polynomialText,
                bigIntegerGenericMatrixRing,
                bigIntegerMatrixConfigParser,
                bigIntegerMatrixConversion,
                variableName,
                arrayDelimiters);
            var bigIntegerExpectedDerivative = TestsHelper.ReadUnivarPolynomial(
                polynomialDerivativeText,
                bigIntegerGenericMatrixRing,
                bigIntegerMatrixConfigParser,
                bigIntegerMatrixConversion,
                variableName,
                arrayDelimiters,
                true);
            var bigIntegerActualDerivative = bigIntegerPolynomial.GetPolynomialDerivative(bigIntegerGenericMatrixRing);

            Assert.IsTrue(
                new UnivarPolynomNormalFormEqualityComparer <IMatrix <BigInteger> >(
                    bigIntegerGenericMatrixRing).Equals(bigIntegerExpectedDerivative,
                                                        bigIntegerActualDerivative),
                string.Format("Expected {0} isn't equal to actual {1}.", integerExpectedDerivative, integerActualDerivative));
        }