Exemplo n.º 1
0
 private void Bg_DoWork(object sender, DoWorkEventArgs e)
 {
     _ar = e.Argument as Argument;
     _errorNumbers = (int)(((double)_error / 100) * (_ar.Words.Length * _ar.Words.Length - 1));
     if (_ar != null)
         e.Result = Pso.ApproximateAutomaton(_ar.Swarm, _ar.GlobalBest, _fileAutomata, _fileAutomata.MaxNumberOfStates, _ar.Minutes, _errorNumbers, _ar.Words, _ar.Alpahbet, ref _bg, _iterationsCount, _c1, _c2, _c3);
 }
Exemplo n.º 2
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            labelErrorsTest.Text = "100%";
            labelErrorsTrening.Text = "100%";
            labelProgress.Text = "Generowanie zbiorów testowych...";
            labelProgress.Refresh();

            _minutes = int.Parse(textBoxTime.Text);
            _error = int.Parse(textBoxError.Text);

            if (!_isFile) return;
            _fileAutomata.MaxNumberOfStates = _maxState;

            var numberofsymbols = _fileAutomata.NumberOfSymbols;
            var alphabet = Utils.GenerateAlphabeth(numberofsymbols);
            var swarm = Utils.GenerateRandomSwarm(_swarmSize, _fileAutomata.NumberOfSymbols, _fileAutomata.MaxNumberOfStates);

            var gbeststates = r.Next(1, _fileAutomata.MaxNumberOfStates);
            var tab2 = new int[gbeststates * _fileAutomata.NumberOfSymbols];
            for (int j = 0; j < tab2.Length; j++)
            {
                r = new Random(j * DateTime.Now.Millisecond);
                tab2[j] = r.Next(1, gbeststates);
            }
            Particle gbest = new Particle(new Automata { NumberOfStates = gbeststates, NumberOfSymbols = _fileAutomata.NumberOfSymbols, StateTable = tab2, MaxNumberOfStates = _fileAutomata.MaxNumberOfStates }, null);

            List<string> trainingDictionary = new List<string>();
            List<string> testDictionary = new List<string>();

            if (checkBoxOwnTrainingDictionary.Checked)
            {
                string wordsString = richTextBoxTrainingDictionary.Text;
                string[]  words = wordsString.Split('\n');

                if (words.Length == 0 || (words.Length == 1 && words[0] == ""))
                {
                    labelProgress.Text = "Niepoprawny zbiór treningowy!";
                    MessageBox.Show("Zbiór treningowy nie może być pusty!");
                    return;
                }

                foreach (var word in words)
                {
                    for (int i = 0; i < word.Length; i++)
                        if (!alphabet.Contains(word[i]))
                        {
                            labelProgress.Text = "Niepoprawny zbiór treningowy!";
                            MessageBox.Show("Jedno ze słów w zbiorze treningowym zawiera niedozwolony znak!");
                            return;
                        }
                    trainingDictionary.Add(word);
                }
            }
            else
                Utils.GenerateTrainingDictionary(ref trainingDictionary, alphabet, _fileAutomata.MaxNumberOfStates, _wordLength);

            if(checkBoxOwnTestDictionary.Checked)
            {
                string wordsString = richTextBoxTestDictionary.Text;
                string[] words = wordsString.Split('\n');

                if (words.Length == 0 || (words.Length == 1 && words[0] == ""))
                {
                    labelProgress.Text = "Niepoprawny zbiór testowy!";
                    MessageBox.Show("Zbiór testowy nie może być pusty!");
                    return;
                }

                foreach (var word in words)
                {
                    for (int i = 0; i < word.Length; i++)
                        if (!alphabet.Contains(word[i]))
                        {
                            labelProgress.Text = "Niepoprawny zbiór testowy!";
                            MessageBox.Show("Jedno ze słów w zbiorze testowym zawiera niedozwolony znak!");
                            return;
                        }
                    testDictionary.Add(word);
                }
            }
            else
                Utils.GenerateTestDictionary(ref testDictionary, alphabet, _maxState);

            _ar = new Argument
            {
                Alpahbet = alphabet,
                GlobalBest = gbest,
                Minutes = _minutes,
                Swarm = swarm,
                Words = trainingDictionary.ToArray(),
                TestWords = testDictionary.ToArray()
            };
            buttonFileOpen.Enabled = false;
            buttonStart.Enabled = false;
            labelProgress.Text = "Trwa rekonstrukcja automatu...";

            _bg.RunWorkerAsync(_ar);
        }