annotate Implab/Automaton/RegularExpressions/RegularDFADefinition.cs @ 164:ec35731ae299 ref20160224

Almost complete DFA refactoring
author cin
date Thu, 25 Feb 2016 02:11:13 +0300
parents
children e227e78d72e4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
164
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
1 using System;
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
2
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
3 namespace Implab.Automaton.RegularExpressions {
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
4 public class RegularDFADefinition<TInput, TTag> : DFATransitionTable<TTag>, IDFATransitionTable<TTag> {
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
5
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
6 readonly IAlphabet<TInput> m_alphabet;
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
7 readonly int m_initialState;
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
8
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
9 public RegularDFADefinition(IAlphabet<TInput> alphabet, int initialState) {
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
10 Safe.ArgumentNotNull(alphabet, "aplhabet");
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
11
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
12 m_alphabet = alphabet;
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
13 m_initialState = initialState;
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
14 }
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
15
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
16
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
17 public IAlphabet<TInput> InputAlphabet {
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
18 get {
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
19 return m_alphabet;
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
20 }
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
21 }
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
22
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
23 protected override DFAStateDescriptior<TTag>[] ConstructTransitionTable() {
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
24 if (InputAlphabet.Count != m_alphabet.Count)
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
25 throw new InvalidOperationException("The alphabet doesn't match the transition table");
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
26
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
27 return base.ConstructTransitionTable();
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
28 }
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
29
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
30 /// <summary>
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
31 /// Optimize the specified alphabet.
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
32 /// </summary>
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
33 /// <param name="alphabet">Пустой алфавит, который будет зполнен в процессе оптимизации.</param>
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
34 public RegularDFADefinition<TInput, TTag> Optimize(IAlphabetBuilder<TInput> alphabet) {
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
35 Safe.ArgumentNotNull(alphabet, "alphabet");
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
36
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
37 var optimalDFA = new RegularDFADefinition<TInput,TTag>(alphabet, m_initialState);
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
38
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
39 Optimize(optimalDFA, InputAlphabet, alphabet, new DummyAlphabet(StateCount), new MapAlphabet<int>());
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
40
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
41 }
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
42
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
43
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
44 }
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
45 }
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
46