示例#1
0
        private void Stopped(object sender, EventArgs e)
        {
            EngineAlgorithm alg = sender as EngineAlgorithm;

            // only update on certain intervals, so we don't tax the db unnecessarily
            var results = alg.Results.Clone() as ResultCollection;

            foreach (var s in results)
            {
                if (s.Name == "BestQuality")
                {
                    // get algorithm output
                    string bestQuality    = results["BestQuality"].Value.ToString();
                    string generations    = results["Generations"].Value.ToString();
                    string bestSolution   = GetBestSolution(results);
                    string currentResults = GetCurrentResults(results);

                    _run.Generations    = Convert.ToInt32(generations);
                    _run.BestQuality    = bestQuality;
                    _run.BestSolution   = bestSolution;
                    _run.CurrentResults = currentResults;

                    //Console.WriteLine("Thread1 -> Time: " + alg.ExecutionTime + ", Quality: " + alg.Results["BestQuality"].Value.ToString());
                    UpdateRun("Optimization Completed", StrategyState.Stopped);
                }
            }

            DeregisterAlgorithmEventHandlers(alg);

            //UpdateRun("Optimization completed", StrategyState.Stopped);
        }
示例#2
0
        private void Paused(object sender, EventArgs e)
        {
            EngineAlgorithm alg = sender as EngineAlgorithm;

            Console.WriteLine("Execution paused");
            alg.Stop();
        }
示例#3
0
 private void DeregisterAlgorithmEventHandlers(EngineAlgorithm alg)
 {
     //alg.ExecutionStateChanged -= new EventHandler(ExecutionStateChanged);
     alg.ExecutionTimeChanged -= new EventHandler(ExecutionTimeChanged);
     alg.Stopped -= new EventHandler(Stopped);
     //alg.Started += new EventHandler(Started);
     alg.Paused += new EventHandler(Paused);
 }
示例#4
0
        private void ExecutionTimeChanged(object sender, EventArgs e)
        {
            // maybe we should check to see if the execution time has been longer than say 5 secs?
            EngineAlgorithm alg = sender as EngineAlgorithm;

            // only update on certain intervals, so we don't tax the db unnecessarily
            var results = alg.Results.Clone() as ResultCollection;

            try
            {
                foreach (var s in results)
                {
                    if (s.Name == "BestQuality")
                    {
                        // debug
                        //var test = _pi.QualityMatrix;

                        // get algorithm output
                        string bestQuality    = results["BestQuality"].Value.ToString();
                        string generations    = results["Generations"].Value.ToString();
                        string bestSolution   = GetBestSolution(results);
                        string currentResults = GetCurrentResults(results);

                        // only call the database on the last update
                        //if(_run.GenerationsToRun == Convert.ToInt32(generations))
                        //{

                        _run.Generations    = Convert.ToInt32(generations);
                        _run.BestQuality    = bestQuality;
                        _run.BestSolution   = bestSolution;
                        _run.CurrentResults = currentResults;

                        //Console.WriteLine("Thread1 -> Time: " + alg.ExecutionTime + ", Quality: " + alg.Results["BestQuality"].Value.ToString());
                        UpdateRun("Quality: " + alg.Results["BestQuality"].Value.ToString(), StrategyState.Running);

                        //}
                    }
                }
            }
            catch
            {
                //bool ignore = true;
            }
        }