示例#1
0
        static int GetRateSd(int i, int j, CellType side, CellType[,] board, int size)
        {
            int t = 1, k = 0, p = 1;

            _p1 = 0; _p2 = 0;
            while ((j - t > -1) && (i + t < board.GetLength(0)) && side.Equals(board[i + t, j - t]))
            {
                t++; k++;
            }
            while ((j - t > -1) && (i + t < board.GetLength(0)) && CellType.Free.Equals(board[i + t, j - t]))
            {
                t++; _p1 = 1; p++;
            }
            t = -1;
            while ((j - t < board.GetLength(1)) && (i + t > -1) && side.Equals(board[i + t, j - t]))
            {
                t--; k++;
            }
            while ((j - t < board.GetLength(1)) && (i + t > -1) && CellType.Free.Equals(board[i + t, j - t]))
            {
                t--; _p2 = 1; p++;
            }
            if ((k + p < size))
            {
                k = 0;
            }
            return(k);
        }
        //ResultMatrix with ResultMatrix-cellTypes

        /// <summary>
        /// Compares two footprints and saves the result in ResultMatrix
        /// </summary>
        /// <param name="footprint1">The first footprint</param>
        /// <param name="footprint2">The second footprint</param>
        /// <autor>Andrej Albrecht</autor>
        public ComparingFootprintResultMatrix(ComparingFootprint footprint1, ComparingFootprint footprint2)
        {
            AddEventHeader(footprint1);
            AddEventHeader(footprint2);

            ResultMatrix = new ResultCellType[HeaderWithEventNames.Count, HeaderWithEventNames.Count];

            for (int row = 0; row < HeaderWithEventNames.Count; row++)
            {
                for (int column = 0; column < HeaderWithEventNames.Count; column++)
                {
                    CellType matrix1Cell = footprint1.GetFootprintCellState(HeaderWithEventNames[row], HeaderWithEventNames[column]);
                    CellType matrix2Cell = footprint2.GetFootprintCellState(HeaderWithEventNames[row], HeaderWithEventNames[column]);

                    if (matrix1Cell.Equals(matrix2Cell))
                    {
                        //If the cellstates of the both footprints are equal, then they have no differences
                        ResultMatrix[row, column] = ResultCellType.NoDifferences;
                    }
                    else
                    {
                        // find the right CellState for the differences of both footprints
                        ResultMatrix[row, column] = ComparingFootprintResultMatrixCell.GetResultCellType(matrix1Cell, matrix2Cell);
                    }
                }
            }
        }
        public bool TryChangeCell(int x, int y, CellType newType)
        {
            var canChange = !(x >= _maxX ||
                              y >= _maxY ||
                              x < 0 ||
                              y < 0 ||
                              newType.Equals(_gridCells[x, y]?.Value));

            if (canChange)
            {
                if (_gridCells[x, y] != null)
                {
                    _gridCells[x, y].Value = newType;
                }
                else
                {
                    _gridCells[x, y] = new GridCell(newType);
                }
            }

            return(canChange);
        }
        /// <summary>
        /// Create a footprint for a petrinet
        /// </summary>
        /// <param name="petriNet">Petrinet</param>
        /// <returns>returns a ComparingFootprint</returns>
        /// <autor>Andrej Albrecht</autor>
        public static ComparingFootprint CreateFootprint(PetriNet petriNet)
        {
            ComparingFootprint resultFootprint = new ComparingFootprint(new CellType[petriNet.Transitions.Count, petriNet.Transitions.Count]);

            foreach (Transition transition in petriNet.Transitions)
            {
                if (!transition.IsLoop)
                {
                    resultFootprint.AddEventHeader(transition.Name);
                }
            }

            List <String> transitionLoops = Transition.GetTransitionLoops(petriNet);

            int indexRow = 0;

            foreach (String headerNameRow in resultFootprint.HeaderWithEventNames)
            {
                int indexColumn = 0;
                foreach (String headerNameColumn in resultFootprint.HeaderWithEventNames)
                {
                    CellType transitionRelationship = GetTransitionRelationship(headerNameRow, headerNameColumn, petriNet);

                    //reset the cellstate to nothing, if the cell have no state:
                    resultFootprint.ResultMatrix[indexRow, indexColumn] = CellType.Nothing;

                    //save the found transition relationship to the cell and check parallelism with method checkTransitionParallel:
                    if (headerNameRow.Equals(headerNameColumn) && transitionLoops.Contains(headerNameColumn))
                    {
                        resultFootprint.ResultMatrix[indexRow, indexColumn] = CellType.Loop;
                    }
                    else if (transitionRelationship.Equals(CellType.Parallel))
                    {
                        resultFootprint.ResultMatrix[indexRow, indexColumn] = CellType.Parallel;

                        if (indexRow != indexColumn)
                        {
                            resultFootprint.ResultMatrix[indexColumn, indexRow] = CellType.Parallel;
                        }
                    }
                    else if (transitionRelationship.Equals(CellType.Right))
                    {
                        if (resultFootprint.ResultMatrix[indexRow, indexColumn].Equals(CellType.Left))
                        {
                            resultFootprint.ResultMatrix[indexRow, indexColumn] = CellType.Parallel;
                        }

                        resultFootprint.ResultMatrix[indexRow, indexColumn] = CellType.Right;

                        if (indexRow != indexColumn)
                        {
                            resultFootprint.ResultMatrix[indexColumn, indexRow] = CellType.Left;
                        }
                    }
                    else if (transitionRelationship.Equals(CellType.Left))
                    {
                        if (resultFootprint.ResultMatrix[indexRow, indexColumn].Equals(CellType.Right))
                        {
                            resultFootprint.ResultMatrix[indexRow, indexColumn] = CellType.Parallel;
                        }

                        resultFootprint.ResultMatrix[indexRow, indexColumn] = CellType.Left;
                    }

                    indexColumn++;
                }
                indexRow++;
            }
            return(resultFootprint);
        }