public void SubsetSumLLLReductionAlgorithmConstructorTest() { var integerDomain = new IntegerDomain(); var decimalField = new DecimalField(); var vectorFactory = new ArrayVectorFactory <decimal>(); var decimalComparer = Comparer <decimal> .Default; var nearest = new DecimalNearestInteger(); // Permite calcular o produto escalar de vectores sobre o corpo de decimais. var scalarProd = new OrthoVectorScalarProduct <decimal>( decimalComparer, decimalField); // Permite converter um número decimal num inteiro, caso seja possível. var integerDecimalConverter = new IntegerDecimalConverter(); var subsetSumAlg = new SubsetSumLLLReductionAlgorithm <int, decimal>( vectorFactory, scalarProd, nearest, Comparer <decimal> .Default, integerDecimalConverter, decimalField); var vector = new[] { 366, 385, 392, 401, 422, 437 }; var result = subsetSumAlg.Run(vector, 1215, 3M / 4); var expected = new[] { 392, 401, 422 }; CollectionAssert.AreEquivalent(expected, result); }
public void RunTest2() { var integerDomain = new IntegerDomain(); var decimalField = new DecimalField(); var vectorFactory = new ArrayVectorFactory <decimal>(); var decimalComparer = Comparer <decimal> .Default; var nearest = new DecimalNearestInteger(); var scalarProd = new OrthoVectorScalarProduct <decimal>( decimalComparer, decimalField); var integerDecimalConverter = new IntegerDecimalConverter(); var dim = 4; var vectorSet = new IMathVector <decimal> [dim]; var lllReductionAlg = new LLLBasisReductionAlgorithm <IMathVector <decimal>, decimal, int>( new VectorSpace <decimal>(dim, vectorFactory, decimalField), scalarProd, nearest, Comparer <decimal> .Default); vectorSet[0] = new ArrayMathVector <decimal>(new decimal[] { 1, 1, 7, 2 }); vectorSet[1] = new ArrayMathVector <decimal>(new decimal[] { 9, 8, 4, 6 }); vectorSet[2] = new ArrayMathVector <decimal>(new decimal[] { 1, 8, 5, 7 }); vectorSet[3] = new ArrayMathVector <decimal>(new decimal[] { 2, 3, 1, 1 }); var reduced = lllReductionAlg.Run(vectorSet, 3M / 4); var expected = new IMathVector <decimal> [dim]; expected[0] = new ArrayMathVector <decimal>(new decimal[] { 2, 3, 1, 1 }); expected[1] = new ArrayMathVector <decimal>(new decimal[] { 3, -1, 1, 3 }); expected[2] = new ArrayMathVector <decimal>(new decimal[] { -2, 2, 6, -1 }); expected[3] = new ArrayMathVector <decimal>(new decimal[] { -4, 1, -4, 3 }); this.AsserVectorLists(expected, reduced); }
public void RunTest1() { var integerDomain = new IntegerDomain(); var decimalField = new DecimalField(); var vectorFactory = new ArrayVectorFactory <decimal>(); var decimalComparer = Comparer <decimal> .Default; var nearest = new DecimalNearestInteger(); var scalarProd = new OrthoVectorScalarProduct <decimal>( decimalComparer, decimalField); var integerDecimalConverter = new IntegerDecimalConverter(); var lllReductionAlg = new LLLBasisReductionAlgorithm <IMathVector <decimal>, decimal, int>( new VectorSpace <decimal>(3, vectorFactory, decimalField), scalarProd, nearest, Comparer <decimal> .Default); var vectorSet = new IMathVector <decimal> [3]; vectorSet[0] = new ArrayMathVector <decimal>(new decimal[] { 1, 1, 1 }); vectorSet[1] = new ArrayMathVector <decimal>(new decimal[] { -1, 0, 2 }); vectorSet[2] = new ArrayMathVector <decimal>(new decimal[] { 3, 5, 6 }); var reduced = lllReductionAlg.Run(vectorSet, 3M / 4); // O resultado esperado. var expected = new IMathVector <decimal> [3]; expected[0] = new ArrayMathVector <decimal>(new decimal[] { 0, 1, 0 }); expected[1] = new ArrayMathVector <decimal>(new decimal[] { 1, 0, 1 }); expected[2] = new ArrayMathVector <decimal>(new decimal[] { -1, 0, 2 }); this.AsserVectorLists(expected, reduced); }