示例#1
0
 public Matrix01(MatrixSize size)
 {
     Element = new bool[size.linesNumber][];
     for (int i = 0; i < size.linesNumber; i++)
     {
         Element[i] = new bool[size.columnNumber];
     }
 }
示例#2
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];
     }
 }
示例#3
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);
        }
示例#4
0
 public RandomGenerator(MatrixSize size)
 {
     totalLines   = size.linesNumber;
     totalColumns = size.columnNumber;
 }