@@ -1,33 +1,33 | |||
|
1 | 1 | using System; |
|
2 | 2 | |
|
3 | 3 | namespace Implab.Automaton { |
|
4 | struct AutomatonTransition : IEquatable<AutomatonTransition> { | |
|
4 | public struct AutomatonTransition : IEquatable<AutomatonTransition> { | |
|
5 | 5 | public readonly int s1; |
|
6 | 6 | public readonly int s2; |
|
7 | 7 | public readonly int edge; |
|
8 | 8 | |
|
9 | 9 | public AutomatonTransition(int s1, int s2, int edge) { |
|
10 | 10 | this.s1 = s1; |
|
11 | 11 | this.s2 = s2; |
|
12 | 12 | this.edge = edge; |
|
13 | 13 | } |
|
14 | 14 | |
|
15 | 15 | |
|
16 | 16 | #region IEquatable implementation |
|
17 | 17 | public bool Equals(AutomatonTransition other) { |
|
18 | 18 | return other.s1 == s1 && other.s2 == s2 && other.edge == edge ; |
|
19 | 19 | } |
|
20 | 20 | #endregion |
|
21 | 21 | |
|
22 | 22 | public override bool Equals(object obj) { |
|
23 | 23 | if (obj is AutomatonTransition) |
|
24 | 24 | return Equals((AutomatonTransition)obj); |
|
25 | 25 | return base.Equals(obj); |
|
26 | 26 | } |
|
27 | 27 | |
|
28 | 28 | public override int GetHashCode() { |
|
29 | 29 | return s1 + s2 + edge; |
|
30 | 30 | } |
|
31 | 31 | } |
|
32 | 32 | } |
|
33 | 33 |
@@ -1,59 +1,59 | |||
|
1 | 1 | using System.Collections.Generic; |
|
2 | 2 | |
|
3 | 3 | |
|
4 | 4 | namespace Implab.Automaton { |
|
5 | 5 | /// <summary> |
|
6 | 6 | /// Полностью описывает DFA автомат, его поведение, состояние и входные символы. |
|
7 | 7 | /// </summary> |
|
8 | 8 | /// <example> |
|
9 | 9 | /// class MyAutomaton { |
|
10 | 10 | /// int m_current; |
|
11 | 11 | /// readonly DFAStateDescriptor<string>[] m_automaton; |
|
12 | 12 | /// readonly IAlphabet<MyCommands> m_commands; |
|
13 | 13 | /// |
|
14 | 14 | /// public MyAutomaton(IDFADefinition<MyCommands,MyStates,string> definition) { |
|
15 | 15 | /// m_current = definition.StateAlphabet.Translate(MyStates.Initial); |
|
16 | 16 | /// m_automaton = definition.GetTransitionTable(); |
|
17 | 17 | /// m_commands = definition.InputAlphabet; |
|
18 | 18 | /// } |
|
19 | 19 | /// |
|
20 | 20 | /// // defined a method which will move the automaton to the next state |
|
21 | 21 | /// public void Move(MyCommands cmd) { |
|
22 | 22 | /// // use transition map to determine the next state |
|
23 | 23 | /// var next = m_automaton[m_current].transitions[m_commands.Translate(cmd)]; |
|
24 | 24 | /// |
|
25 | 25 | /// // validate that we aren't in the unreachable state |
|
26 | 26 | /// if (next == DFAConst.UNREACHABLE_STATE) |
|
27 | 27 | /// throw new InvalidOperationException("The specified command is invalid"); |
|
28 | 28 | /// |
|
29 | 29 | /// // if everything is ok |
|
30 | 30 | /// m_current = next; |
|
31 | 31 | /// } |
|
32 | 32 | /// } |
|
33 | 33 | /// </example> |
|
34 | public interface IDFATable { | |
|
34 | public interface IDFATable : IEnumerable<AutomatonTransition> { | |
|
35 | 35 | /// <summary> |
|
36 | 36 | /// Таблица переходов состояний автомата |
|
37 | 37 | /// </summary> |
|
38 | 38 | /// <returns>The transition table.</returns> |
|
39 | 39 | DFAStateDescriptior[] GetTransitionTable(); |
|
40 | 40 | |
|
41 | 41 | int StateCount { |
|
42 | 42 | get; |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | int AlphabetSize { |
|
46 | 46 | get; |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | int InitialState { |
|
50 | 50 | get; |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | bool IsFinalState(int s); |
|
54 | 54 | |
|
55 | 55 | IEnumerable<int> FinalStates { |
|
56 | 56 | get; |
|
57 | 57 | } |
|
58 | 58 | } |
|
59 | 59 | } |
General Comments 0
You need to be logged in to leave comments.
Login now