public static Automata Random(int numStates, int numLetters) { Random rand = new Random(); var flags = new List <int>(); flags.Add(rand.Next(0, numLetters - 1)); for (int i = 1, n = numStates - 1; i < n; ++i) { flags.Add(rand.Next(flags[i - 1] + 1, (i + 1) * numLetters - 1)); } var str = new List <int>(); for (int i = 0, n = numStates * numLetters, k = 0; i < n; ++i) { if (k < numStates - 1 && i == flags[k]) { str.Add(++k); } else { str.Add(rand.Next(0, k)); } } var states = new List <int>(); for (int i = 0; i < numStates; ++i) { states.Add(i); } var letters = String.Empty; for (int i = 0; i < numLetters; ++i) { letters += Convert.ToChar(Convert.ToInt32('a') + i); } var transitions = new Dictionary <int, Dictionary <char, int> >(); for (int i = 0; i < numStates; ++i) { var temp = new Dictionary <char, int>(); transitions.Add(i, temp); for (int j = 0; j < numLetters; ++j) { transitions[i].Add(letters[j], str[i * numLetters + j]); } } var a = new Automata(states, letters, transitions); return(a); }
/// <summary> /// Подтверждение заполнения /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonCreateConfirm_Click(object sender, EventArgs e) { tabControlMain.Enabled = true; automata = new Automata(dataTable); buttonCreateTable.Visible = true; buttonCreateConfirm.Visible = false; labelCreateInfo.Text = "Select size, then push \"Create Table\""; ActivateUI(); }
/// <summary> /// Нажатие клавиши генерации нового автомата /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonGenerate_Click(object sender, EventArgs e) { RightPanel(deactivate); automata = Automata.Random( Convert.ToInt32(numericUpDownStates.Value), Convert.ToInt32(numericUpDownAlphabet.Value)); dataTable = automata.OutputToDataTable(); dataGridViewAutomata.DataSource = dataTable; RightPanel(activate); }
/// <summary> /// Нажатие клавиши генерации нового автомата /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonGenerate_Click(object sender, EventArgs e) { // Сброс интерфейса, т.к. создается новый автомат ResetUI(); automata = Automata.Random( Convert.ToInt32(numericUpDownStates.Value), Convert.ToInt32(numericUpDownAlphabet.Value)); dataTable = automata.OutputToDataTable(); ActivateUI(); }
public Generator(int n, int k) { numStates = n; numLetters = k; for (int i = 0; i < n - 1; ++i) { flags.Add(0); } for (int i = 0, j = n * k; i < j; ++i) { sequence.Add(0); } for (int i = 1; i < n; ++i) { flags[i - 1] = k * i - 1; } resetSequences(); var states = new List <int>(numStates); for (int i = 0; i < numStates; ++i) { states.Add(i); } var letters = String.Empty; for (int i = 0; i < numLetters; ++i) { letters += Convert.ToChar('a' + i); } Dictionary <int, Dictionary <char, int> > transitions = new Dictionary <int, Dictionary <char, int> >(); for (int i = 0, l = numStates; i < l; ++i) { Dictionary <char, int> temp = new Dictionary <char, int>(numStates); transitions.Add(i, temp); for (int j = 0, m = numLetters; j < m; ++j) { temp.Add(Convert.ToChar('a' + j), sequence[i * numLetters + j]); } } automata = new Automata(states, letters, transitions); }
private void buttonOpen_Click(object sender, EventArgs e) { RightPanel(deactivate); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.DefaultExt = "automata"; openFileDialog.AddExtension = true; if (openFileDialog.ShowDialog(this) == DialogResult.OK) { StreamReader stream = new StreamReader(openFileDialog.OpenFile()); var rawInput = stream.ReadToEnd(); stream.Close(); var lines = rawInput.Split('\n'); int states = Convert.ToInt32(lines[0]); int alphabet = Convert.ToInt32(lines[1]); dataTable = new DataTable(); dataTable.Columns.Add("State"); for (int i = 0; i < alphabet; ++i) { dataTable.Columns.Add($"by {Convert.ToChar('a' + i)}"); } for (int i = 0; i < states; ++i) { dataTable.Rows.Add(); } var rows = lines[2].Split(';'); // Разбиваем таблицу на строки for (int i = 0; i < states; ++i) { var temp = rows[i].Split(',');// И на отдельные клетки текущей строки dataTable.Rows[i][0] = i; for (int j = 1; j <= alphabet; ++j) { dataTable.Rows[i][j] = temp[j - 1]; } } automata = new Automata(dataTable); dataGridViewAutomata.DataSource = dataTable; RightPanel(activate); } }
/// <summary> /// Подтверждение заполнения /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonCreateConfirm_Click(object sender, EventArgs e) { if (dataGridAutomataVerificate()) { dataGridViewAutomata.ReadOnly = true; tabControlMain.Enabled = true; automata = new Automata(dataTable); buttonCreateTable.Visible = true; buttonCreateConfirm.Visible = false; labelCreateInfo.Text = "Select size, then push \"Create Table\""; RightPanel(activate); } else { DialogResult dialogResult = MessageBox.Show("Wrong input", "Input", MessageBoxButtons.OK); } }