public bool IsPartitionTrivial(bool G = false) { PartitionsSet set = G ? partitionsG[0] : partitionsN[0]; string pattern = @"\{[0-9a-zA-Z^\)]+\}"; int a = Regex.Matches(set.Rows.AsString(), pattern).Count == square.GetRowsNumber() ? 1 : 0; int b = Regex.Matches(set.Columns.AsString(), pattern).Count == square.GetColumnsNumber() ? 1 : 0; int c = Regex.Matches(set.Symbols.AsString(), pattern).Count == square.SymbolCount() ? 1 : 0; return((a + b + c) >= 2); }
private PartitionsSet RefinePartition(PartitionsSet partition) { var triplets = GetTriplietsFromSquareAndPartition(square, partition); var colTriplets = GetTriplietsFromSquareAndPartition( new Cube(square).GetCubeWithColumnsAsRowsTranspose() .toRectangle(square.GetColumnsNumber(), square.GetRowsNumber()), partition); var symTriplets = GetTriplietsFromSquareAndPartition(new Cube(square). GetCubeWithSymbolsAsRowsTranspose().toRectangle(square.SymbolCount(), square.GetColumnsNumber()), partition); PartitionsSet set = new PartitionsSet( GetPartitionsForRows(triplets), GetPartitionsForRows(colTriplets), GetPartitionsForRows(symTriplets)); return(set); }
private string[,] GetTriplietsFromSquareAndPartition(Rectangle square, PartitionsSet partition) { var tripletValues = new string[square.GetRowsNumber(), square.GetColumnsNumber()]; for (int i = 0; i < tripletValues.GetLength(0); i++) { for (int j = 0; j < tripletValues.GetLength(1); j++) { if (square.values[i, j] == Rectangle.EMPTY) { tripletValues[i, j] = " - "; } else { int val = Array.IndexOf(Utils.SYMBOLS, square.values[i, j]); tripletValues[i, j] = "(" + partition.Rows.Groups.FirstOrDefault(x => x.Value.Contains(i)).Key + "," + partition.Columns.Groups.FirstOrDefault(x => x.Value.Contains(j)).Key + "," + partition.Symbols.Groups.FirstOrDefault(x => x.Value.Contains(val)).Key + ")"; } } } return(tripletValues); }
public InvestigationObject(string squareString) { square = ValidateAndReturnSquareString(squareString); if (square == null) { throw new Exception("this square string doesn't represent a valid latin square"); } cube = new Cube(square); comparisonMatrices = new Dictionary <string, string[, ]>(); comparisonMatrices.Add("rows", GetComparisonMatrix(square.values)); comparisonMatrices.Add("cols", GetComparisonMatrix(new Cube(square). GetCubeWithColumnsAsRowsTranspose().toRectangle(square.GetColumnsNumber(), square.GetRowsNumber()).values)); comparisonMatrices.Add("symbols", GetComparisonMatrix(new Cube(square). GetCubeWithSymbolsAsRowsTranspose().toRectangle(square.SymbolCount(), square.GetColumnsNumber()).values)); tripletValues = new List <string[, ]>(); tripletValues.Add(GetTriplietsFromSquare(square)); partitionsN = new List <PartitionsSet>(); partitionsG = new List <PartitionsSet>(); partitionsN.Add(new PartitionsSet( GetPartitionsForRows(tripletValues[0]), GetPartitionsForRows( GetTriplietsFromSquare(new Cube(square). GetCubeWithColumnsAsRowsTranspose().toRectangle(square.GetColumnsNumber(), square.GetRowsNumber()))), GetPartitionsForRows( GetTriplietsFromSquare(new Cube(square). GetCubeWithSymbolsAsRowsTranspose().toRectangle(square.SymbolCount(), square.GetColumnsNumber()))) )); do { var last = partitionsN.Last(); var set = new PartitionsSet( GetPartitionsForRows(tripletValues.Last()), GetPartitionsForRows( GetTriplietsFromSquareAndPartition(new Cube(square). GetCubeWithColumnsAsRowsTranspose().toRectangle(square.GetColumnsNumber(), square.GetRowsNumber()), last.WithNewOrder(1, 0, 2))), GetPartitionsForRows( GetTriplietsFromSquareAndPartition(new Cube(square). GetCubeWithSymbolsAsRowsTranspose().toRectangle(square.SymbolCount(), square.GetColumnsNumber()), last.WithNewOrder(2, 1, 0)))); if (set.AsString() == last.AsString()) { break; } partitionsN.Add(set); tripletValues.Add(GetTriplietsFromSquareAndPartition(square, last)); } while (true); partitionsG.Add(new PartitionsSet( GetPartitionsForRows(comparisonMatrices["rows"]), GetPartitionsForRows(comparisonMatrices["cols"]), GetPartitionsForRows(comparisonMatrices["symbols"]) )); }