public void BuildFromUpperDiagonalRow_DimensionsDoesNotFitInputData_ThrowsException() { MatrixBuilder builder = new MatrixBuilder(); builder.BuildFromUpperDiagonalRow(new double[] { 1, 2, 3, 4, 5, 0, 0, 0, 0 }, 10); Assert.Fail(); }
/// <summary> /// Loads weight matrix from tsp data /// </summary> /// <returns>Edge weight matrix</returns> protected double[,] LoadWeightMatrix() { MatrixBuilder matrixBuilder = new MatrixBuilder(); switch (tspFile.EdgeWeightFormat) { case Defines.EdgeWeightFormat.FullMatrix: return matrixBuilder.BuildFromFullMatrix(tspFile.EdgeWeights, tspFile.Dimension); case Defines.EdgeWeightFormat.UpperRow: case Defines.EdgeWeightFormat.LowerColumn: return matrixBuilder.BuildFromUpperRow(tspFile.EdgeWeights, tspFile.Dimension); case Defines.EdgeWeightFormat.LowerRow: case Defines.EdgeWeightFormat.UpperColumn: return matrixBuilder.BuildFromLowerRow(tspFile.EdgeWeights, tspFile.Dimension); case Defines.EdgeWeightFormat.UpperDiagonalRow: case Defines.EdgeWeightFormat.LowerDiagonalColumn: return matrixBuilder.BuildFromUpperDiagonalRow(tspFile.EdgeWeights, tspFile.Dimension); case Defines.EdgeWeightFormat.LowerDiagonalRow: case Defines.EdgeWeightFormat.UpperDiagonalColumn: return matrixBuilder.BuildFromLowerDiagonalRow(tspFile.EdgeWeights, tspFile.Dimension); default: throw new NotSupportedException(); } }
public void ValidateBuildFromUpperDiagonalRow() { MatrixBuilder builder = new MatrixBuilder(); int dimension = 4; double[] input = { 0, 1, 2, 3, // only top right triangle with diagonal, read by rows 0, 4, 5, 0, 6, 0 }; double[,] expectedOutput = { { 0, 1, 2, 3 }, { 1, 0, 4, 5 }, { 2, 4, 0, 6 }, { 3, 5, 6, 0 } }; var output = builder.BuildFromUpperDiagonalRow(input, dimension); AssertArraysAreEqual(expectedOutput, output); }