public BetterFoundInfo(DateTime currentTime, KeyboardEPAlgorithm algorithm, KeyboardLayout current, double currentScore)
 {
     this.currentTime = currentTime;
     this.algorithm = algorithm;
     this.current = current;
     this.currentScore = currentScore;
 }
        void StartButtonClick(object sender, EventArgs e)
        {
            if (!Settings.CanStartWithKnownLayout)
                return;

            var algorithm = new KeyboardEPAlgorithm(Settings.CurrentCorpus.FromJust, mainControl.settings.CurrentTimes.FromJust.Times,
                mainControl.Logger);
            var layout = Settings.CurrentLayout.FromJust;
            algorithm.SetLayout(layout);

            ConsoleTextBox.AppendText(startingNew);
            ConsoleTextBox.AppendText(MainControl.PrintLayoutWithScore(layout, algorithm.CurrentScore));

            mainControl.Start(algorithm);
        }
        public void Start(KeyboardEPAlgorithm algorithm)
        {
            Algorithm = algorithm;
            ThreadStart work = () =>
            {
                while (State == MainControl.States.Running)
                {
                    if (mainControl.UntilBetter(Algorithm))
                        continue;

                    Invoke(new Action(() => { mainControl.State = MainControl.States.Stopped; }));
                    break;
                }
            };
            State = MainControl.States.Running;
            workingThread = new Thread(work);
            workingThread.Start();
        }
 public void Start(KeyboardEPAlgorithm algorithm)
 {
     runningControlBar1.Start(algorithm);
 }
 public bool UntilBetter(KeyboardEPAlgorithm algorithm)
 {
     var startingSolution = algorithm.Current;
     while (IsRunning && algorithm.Current.Equals(startingSolution))
     {
         if (!algorithm.MoveNext())
             return false;
     }
     return true;
 }
 void InvokeBetterSampleFound(KeyboardEPAlgorithm algorithm)
 {
     innerWorker.AddWorkItem(() => BetterSampleFound(new BetterFoundInfo(DateTime.Now, algorithm, algorithm.Current, algorithm.CurrentScore)));
 }
        KeyboardEPAlgorithm GetTestAlgorithm()
        {
            const int width = 3;
            const int height = 3;
            const int keyboardKeyCount = width * height;
            var keyboard = new Keyboard(Enumerable.Range(0, height).Select(_ => width).ToArray(),
                Keyboard.StandardKeyboard.AllChars.Take(keyboardKeyCount).ToHashSet());
            var timeBuilder = TransitionTimeBuilder.GetEmpty(keyboard);
            var fractions = new double[keyboardKeyCount, keyboardKeyCount];
            for (var i = 0; i < keyboardKeyCount; i++)
            {
                for (var j = i; j < keyboardKeyCount; j++)
                {
                    var miliseconds = i + j * keyboardKeyCount;
                    timeBuilder[i, j].AddMeasurement(miliseconds);
                    fractions[i, j] = miliseconds;
                }
            }

            var corpus = new Corpus(fractions, keyboardKeyCount, keyboard);
            var algorithm = new KeyboardEPAlgorithm(corpus, timeBuilder.Times, GetLogger());
            algorithm.SetLayout(KeyboardLayout.Random(keyboard));
            return algorithm;
        }
 KeyboardEPAlgorithm GetStandardWithCurrentSettings()
 {
     var corpus = Settings.CurrentCorpus.FromJust;
     var style = Settings.CurrentTimes.FromJust.Times;
     var algorithm = new KeyboardEPAlgorithm(corpus, style, GetLogger());
     algorithm.SetLayout(KeyboardLayout.Random(Keyboard.StandardKeyboard));
     return algorithm;
 }
        void StartRandomButtonClick(object sender, EventArgs e)
        {
            if (Settings.CanStart)
            {
                mainControl.consoleTextBox.Clear();
                var layout = KeyboardLayout.Random(Keyboard.StandardKeyboard);
                ConsoleTextBox.AppendText("Starting algorithm with a random layout." + Environment.NewLine);
                var algorithm = new KeyboardEPAlgorithm(Settings.CurrentCorpus.FromJust, Settings.CurrentTimes.FromJust.Times,
                    mainControl.Logger);
                algorithm.SetLayout(layout);

                ConsoleTextBox.AppendText(startingNew);
                ConsoleTextBox.AppendText(MainControl.PrintLayoutWithScore(layout, algorithm.CurrentScore));

                mainControl.Start(algorithm);
            }
            else
                ConsoleTextBox.AppendText(inComplete);
        }