Exemple #1
0
        static LTS ChessBoard(int boardSize)
        {
            // this procedure outputs a board of size boardSize x boardSize in aldebaran format
            var lts      = new LTS();
            var board    = new LTSState[boardSize, boardSize];
            int stateNum = 0;
            var initial  = new LTSState(stateNum++.ToString(), lts);

            lts.InitialState = initial;
            for (int i = 0; i < boardSize; i++)
            {
                for (int j = 0; j < boardSize; j++)
                {
                    var cell = new LTSState(stateNum++.ToString(), lts);
                    board[i, j] = cell;
                    lts.States.Add(cell);
                }
            }

            lts.States.Add(initial);
            for (int i = 0; i < boardSize; i++)
            {
                lts.Transitions.Add(new LTSTransition(initial, board[boardSize - 1, i], "start(" + (boardSize - 1) + "," + i + ")"));
                if (i != boardSize - 1)                 // don't want 2 transitions to same init
                {
                    lts.Transitions.Add(new LTSTransition(initial, board[i, boardSize - 1], "start(" + i + "," + (boardSize - 1) + ")"));
                }
            }

            for (int y = boardSize - 1; y >= 0; y--)
            {
                for (int x = boardSize - 1; x >= 0; x--)
                {
                    var thisCell = board[x, y];
                    // horizontal moves
                    for (int i = x - 1; i >= 0; i--)
                    {
                        lts.Transitions.Add(new LTSTransition(thisCell, string.Format("to({0},{1})", i, y), board[i, y]));
                    }
                    // vertical moves
                    for (int j = y - 1; j >= 0; j--)
                    {
                        lts.Transitions.Add(new LTSTransition(thisCell, string.Format("to({0},{1})", x, j), board[x, j]));
                    }
                    // diagonal moves
                    int k = x - 1, l = y - 1;
                    while (k >= 0 && l >= 0)
                    {
                        lts.Transitions.Add(new LTSTransition(thisCell, string.Format("to({0},{1})", k, l), board[k--, l--]));
                    }
                }
            }

            return(lts);
        }
Exemple #2
0
		private static LTSState GetState(string stateName, LTS lts) {
			LTSState state;
			if (lts.StatesMap.TryGetValue(stateName, out state))
				return state;
			else {
				state = new LTSState(stateName, lts);
				lts.StatesMap[stateName] = state;
				lts.States.Add(state);
			}
			return state;
		}
Exemple #3
0
        private static LTSState GetState(string stateName, LTS lts)
        {
            LTSState state;

            if (lts.StatesMap.TryGetValue(stateName, out state))
            {
                return(state);
            }
            else
            {
                state = new LTSState(stateName, lts);
                lts.StatesMap[stateName] = state;
                lts.States.Add(state);
            }
            return(state);
        }
Exemple #4
0
        public static LTS Parse(string file)
        {
            // parse aldebran format
            var    ret     = new LTS();
            var    sr      = new StreamReader(file, Encoding.Default);
            var    lineRE  = new Regex(@"\((\w+)\s*,\s*""([^\""]+?)""\s*,\s*(\w+)\s*\)");
            string initial = string.Empty;

            while (!sr.EndOfStream)
            {
                var line = sr.ReadLine();
                if (line.StartsWith("des"))
                {
                    var m = Regex.Match(line, @"des\s*\((\w+?),(\w+?),(\w+?)\)");
                    if (m.Success)
                    {
                        initial = m.Groups[1].Captures[0].Value;
                    }
                    continue;
                }

                var match = lineRE.Match(line);
                if (match.Success)
                {
                    string start = match.Groups[1].Captures[0].Value;
                    string label = match.Groups[2].Captures[0].Value;
                    string end   = match.Groups[3].Captures[0].Value;

                    LTSState      startState = GetState(start, ret);
                    LTSState      endState   = GetState(end, ret);
                    LTSTransition trans      = new LTSTransition(startState, label, endState);

                    ret.Actions.Add(label);
                    ret.Transitions.Add(trans);
                    startState.AddOutTransition(trans);
                    //endState.AddInTransition(trans);
                }
                else
                {
                    int i = 0;
                }
            }

            ret.InitialState = GetState(initial, ret);
            return(ret);
        }
Exemple #5
0
        static LTS ChessBoard(int boardSize)
        {
            // this procedure outputs a board of size boardSize x boardSize in aldebaran format
            var lts = new LTS();
            var board = new LTSState[boardSize, boardSize];
            int stateNum = 0;
            var initial = new LTSState(stateNum++.ToString(), lts);
            lts.InitialState = initial;
            for (int i = 0; i < boardSize; i++) {
                for (int j = 0; j < boardSize; j++) {
                    var cell = new LTSState(stateNum++.ToString(), lts);
                    board[i, j] = cell;
                    lts.States.Add(cell);
                }
            }

            lts.States.Add(initial);
            for (int i = 0; i < boardSize; i++) {
                lts.Transitions.Add(new LTSTransition(initial, board[boardSize - 1, i], "start(" + (boardSize - 1) + "," + i + ")"));
                if (i != boardSize - 1) // don't want 2 transitions to same init
                    lts.Transitions.Add(new LTSTransition(initial, board[i, boardSize - 1], "start(" + i + "," + (boardSize - 1) + ")"));
            }

            for (int y = boardSize - 1; y >= 0; y--) {
                for (int x = boardSize - 1; x >= 0; x--) {
                    var thisCell = board[x, y];
                    // horizontal moves
                    for (int i = x - 1; i >= 0; i--)
                        lts.Transitions.Add(new LTSTransition(thisCell, string.Format("to({0},{1})", i, y), board[i, y]));
                    // vertical moves
                    for (int j = y - 1; j >= 0; j--)
                        lts.Transitions.Add(new LTSTransition(thisCell, string.Format("to({0},{1})", x, j), board[x, j]));
                    // diagonal moves
                    int k = x - 1, l = y - 1;
                    while (k >= 0 && l >= 0)
                        lts.Transitions.Add(new LTSTransition(thisCell, string.Format("to({0},{1})", k, l), board[k--, l--]));
                }
            }

            return lts;
        }