Пример #1
0
        private void Routing_StatusUpdate(object sender, EventArgs e)
        {
            EvoStrat.StatusUpdateEventArgs evt = (EvoStrat.StatusUpdateEventArgs)e;

            // Note: Both methods below work, we just need to determine which we want to use
            // Update: looks like the EF version isn't as stable, since it's holding on to contexts and such, use SP version.
            try
            {
                // Stored ProcVersion
                if (evt.State == EvoStrat.StrategyState.Completed || evt.State == EvoStrat.StrategyState.Stopped)
                {
                    //UpdateVrpRun(evt.Run.ID, evt.Run.Generations, evt.Run.BestQuality, evt.Run.BestSolution, evt.Run.CurrentResults, evt.Message);
                    PublishVrpRunMessage(evt.Run.ID, evt.Run.Generations, evt.Run.BestQuality, evt.Run.BestSolution, evt.Run.CurrentResults, evt.Message);

                    // now restart the listener
                    if (evt.State == EvoStrat.StrategyState.Stopped)
                    {
                        StartOptimization();
                    }
                }
                else if (evt.Run.Generations != _generation)                // only update status once per generation
                {
                    _generation = evt.Run.Generations;

                    //UpdateVrpRun(evt.Run.ID, evt.Run.Generations, evt.Run.BestQuality, evt.Run.BestSolution, evt.Run.CurrentResults, evt.Message);
                    PublishVrpRunMessage(evt.Run.ID, evt.Run.Generations, evt.Run.BestQuality, evt.Run.BestSolution, evt.Run.CurrentResults, evt.Message);

                    switch (evt.State)
                    {
                    case EvoStrat.StrategyState.Completed:
                        _ready = true;
                        Console.WriteLine("[" + string.Format("{0:d/M/yyyy HH:mm:ss}", evt.UpdateTime) + "] Thread " + _threadID + " completed. (" + evt.Run.Generations + ")");
                        break;

                    case EvoStrat.StrategyState.Paused:
                        Console.WriteLine("[" + string.Format("{0:d/M/yyyy HH:mm:ss}", evt.UpdateTime) + "] Thread " + _threadID + " paused. (" + evt.Run.Generations + ")");
                        break;

                    case EvoStrat.StrategyState.Running:
                        Console.WriteLine("[" + string.Format("{0:d/M/yyyy HH:mm:ss}", evt.UpdateTime) + "] Thread " + _threadID + ": " + evt.Message + " (" + evt.Run.Generations + ")");
                        break;

                    case EvoStrat.StrategyState.Stopped:
                        _ready = true;
                        Console.WriteLine("[" + string.Format("{0:d/M/yyyy HH:mm:ss}", evt.UpdateTime) + "] Thread " + _threadID + ": Optimization job " + evt.Run.ID + " completed. (" + evt.Run.Generations + ")");
                        break;
                    }
                }
            }
            catch
            {
                //var ignore = true;
            }
        }
Пример #2
0
        private void Routing_StatusUpdate(object sender, EventArgs e)
        {
            EvoStrat.StatusUpdateEventArgs evt = (EvoStrat.StatusUpdateEventArgs)e;

            // Note: Both methods below work, we just need to determine which we want to use
            // Update: looks like the EF version isn't as stable, since it's holding on to contexts and such, use SP version.
            try
            {
                // Entity Framework version
                //_routingUnitOfWork.OptimizationRunRepository.Update(evt.Run);
                // _routingUnitOfWork.Save();

                // Stored ProcVersion
                UpdateVrpRun(evt.Run.ID, evt.Run.Generations, evt.Run.BestQuality, evt.Run.BestSolution, evt.Run.CurrentResults, evt.Message);

                switch (evt.State)
                {
                case EvoStrat.StrategyState.Completed:
                    _ready = true;
                    Console.WriteLine("[" + string.Format("{0:d/M/yyyy HH:mm:ss}", evt.UpdateTime) + "] Thread " + _threadID + " completed.");
                    break;

                case EvoStrat.StrategyState.Paused:
                    Console.WriteLine("[" + string.Format("{0:d/M/yyyy HH:mm:ss}", evt.UpdateTime) + "] Thread " + _threadID + " paused.");
                    break;

                case EvoStrat.StrategyState.Running:
                    Console.WriteLine("[" + string.Format("{0:d/M/yyyy HH:mm:ss}", evt.UpdateTime) + "] Thread " + _threadID + ": " + evt.Message);
                    break;

                case EvoStrat.StrategyState.Stopped:
                    _ready = true;
                    Console.WriteLine("[" + string.Format("{0:d/M/yyyy HH:mm:ss}", evt.UpdateTime) + "] Thread " + _threadID + ": Optimization job " + evt.Run.ID + " completed.");
                    StartOptimization();
                    break;
                }
            }
            catch (Exception exc)
            {
                var ignore = true;
            }
            //TODO: Add switch() statement to handle all StrategyState states
        }