Esempio n. 1
0
 public Context(MatrixSize rndmMatrixSize, Matrix01 PatternMatrix)
 {
     RndmMatrix         = new Matrix01(rndmMatrixSize);
     this.PatternMatrix = PatternMatrix;
     CountingMatrix     = new int[rndmMatrixSize.linesNumber][];
     for (int i = 0; i < rndmMatrixSize.linesNumber; i++)
     {
         CountingMatrix[i] = new int[rndmMatrixSize.columnNumber];
     }
 }
Esempio n. 2
0
 public Matrix01(Matrix01 originalMatrix)
 {
     Element = new bool[originalMatrix.LinesNumber][];
     for (int i = 0; i < LinesNumber; i++)
     {
         Element[i] = new bool[originalMatrix.ColumnNumber];
         for (int j = 0; j < ColumnNumber; j++)
         {
             Element[i][j] = originalMatrix.Element[i][j];
         }
     }
     NumberOf1Elements = originalMatrix.NumberOf1Elements;
 }
Esempio n. 3
0
 public Context(Matrix01 RandomMatrix, Matrix01 PatternMatrix, int[][] CountingMatrix)
 {
     RndmMatrix          = new Matrix01(RandomMatrix);
     this.PatternMatrix  = PatternMatrix;
     this.CountingMatrix = new int[CountingMatrix.Length][];
     for (int i = 0; i < CountingMatrix.Length; i++)
     {
         this.CountingMatrix[i] = new int[CountingMatrix[i].Length];
         for (int j = 0; j < CountingMatrix[i].Length; j++)
         {
             this.CountingMatrix[i][j] = CountingMatrix[i][j];
         }
     }
 }
Esempio n. 4
0
        static void Main(string[] args)
        {
            bool       loadingFromFile = false;
            TextReader reader;

            if (args.Length > 0)
            {
                loadingFromFile = true;
                try
                {
                    reader = new StreamReader(args[0]);
                }
                catch (IOException)
                {
                    ReportError("Error while opening the file.");
                    return;
                }
            }
            else
            {
                reader = Console.In;
            }

            if (!loadingFromFile)
            {
                Console.WriteLine("**Enter \"help\" for illustration of a valid input**");
                Console.WriteLine("Enter sizes of random matrix.");
            }
            string input = reader.ReadLine();

            if (!loadingFromFile && input == "help")
            {
                Console.WriteLine("->Enter sizes of random matrix. (lines \"space\" columns)");
                Console.WriteLine("3 5");
                Console.WriteLine("->Enter sizes of pattern matrix.");
                Console.WriteLine("2 3");
                Console.WriteLine("->Enter pattern 01-matrix of given sizes. (every row on a new line, without spaces)");
                Console.WriteLine("101");
                Console.WriteLine("010");
                Console.WriteLine("->Enter number of random iterations.");
                Console.WriteLine("200");
                Console.WriteLine("**END of the illustration**");
                Console.WriteLine();
                Console.WriteLine("Enter sizes of random matrix.");
                input = reader.ReadLine();
            }
            MatrixSize patternSize;
            MatrixSize rndmMatrixSize;

            if ((rndmMatrixSize = LoadMatrixSize(input)) == null)
            {
                return;
            }

            if (!loadingFromFile)
            {
                Console.WriteLine("Enter sizes of pattern matrix.");
            }

            if ((patternSize = LoadMatrixSize(reader.ReadLine())) == null)
            {
                return;
            }
            else if (patternSize.linesNumber > rndmMatrixSize.linesNumber || patternSize.columnNumber > rndmMatrixSize.columnNumber)
            {
                ReportError("Pattern matrix can't be larger than generating matrix.");
                return;
            }

            Matrix01 patternMatrix = new Matrix01(patternSize);

            if (!loadingFromFile)
            {
                Console.WriteLine("Enter pattern 01-matrix of given sizes.");
            }
            try
            {
                if (!patternMatrix.LoadPattern(reader))
                {
                    ReportError("The matrix must contain only 0 or 1.");
                    return;
                }
            }
            catch (FormatException)
            {
                ReportError("The row is too short.");
                return;
            }

            // transpose matrix in case the pattern has more rows than columns
            if (patternMatrix.LinesNumber > patternMatrix.ColumnNumber)
            {
                MatrixSize transposedSize = new MatrixSize(rndmMatrixSize.columnNumber, rndmMatrixSize.linesNumber);
                patternMatrix.Transpose();
                transpositionNecessary = true;
                rndmMatrixSize         = transposedSize;
            }
            int numberOfIterations;

            if (!loadingFromFile)
            {
                Console.WriteLine("Enter number of random iterations.");
            }
            if (!int.TryParse(reader.ReadLine(), out numberOfIterations) || numberOfIterations < 1)
            {
                ReportError("Wrong format of integer.");
                return;
            }
            Console.WriteLine("**Enter \"end\" to exit or any key to continue**");

            currentContext  = new Context(rndmMatrixSize, patternMatrix);
            randomGenerator = new RandomGenerator(rndmMatrixSize);
            Generate(numberOfIterations);
        }