/// <summary>
        /// Constructor
        /// </summary>
        public BruteOptimizationViewModel(Strategy strategy)
        {
            // Save Dispatcher reference to be used for UI modifications
            _currentDispatcher = Dispatcher.CurrentDispatcher;

            _selectedStrategy                = strategy;
            _bruteForceParameters            = new BruteForceParameters(_selectedStrategy.StrategyType);
            _managerBruteForce               = new OptimizationManagerBruteForce();
            OptimizationStatisticsCollection = new ObservableCollection <OptimizationStatistics>();

            DisplayParameterDetails();

            // Subscribe Event to Update UI for results
            EventSystem.Subscribe <OptimizationStatistics>(DisplayOptimizationStatistics);
        }
예제 #2
0
        /// <summary>
        /// Start Strategy Optimization
        /// </summary>
        /// <param name="optimizationParameters">Contains info for the parameters to be used for optimization</param>
        private void StartOptimization(BruteForceParameters optimizationParameters)
        {
            try
            {
                // Save instance
                _optimizationParameters = optimizationParameters;

                if (_asyncClassLogger.IsInfoEnabled)
                {
                    _asyncClassLogger.Info("Getting argument combinations", _type.FullName, "StartOptimization");
                }

                // Change Status to indicate on UI
                _optimizationParameters.Status = OptimizationStatus.Working;

                // Clear all previous information
                _strategiesCollection.Clear();
                _ctorArguments.Clear();

                // Get Parameter values to be used in the Constructor
                object[] ctorArguments = optimizationParameters.GetParameterValues();

                // Get Conditional Parameter values to be used for creating Iterations
                Tuple <int, object, double>[] conditionalParameters = optimizationParameters.GetConditionalParameters();

                // Save Parameter Details
                _parmatersDetails = optimizationParameters.ParameterDetails;

                // Get all ctor arguments to be used for optimization
                CreateCtorCombinations(ctorArguments, conditionalParameters);

                // Initialize Stratgey for each set of arguments
                foreach (object[] ctorArgumentValues in _ctorArguments)
                {
                    // Get new Key.
                    string key = ApplicationIdGenerator.NextId();

                    var instanceParameterDetails = new Dictionary <string, ParameterDetail>();

                    for (int i = 0; i < ctorArgumentValues.Length; i++)
                    {
                        // Create new parameter details to be when creating Strategy Instance object
                        ParameterDetail tempParameterDetail = new ParameterDetail(_parmatersDetails[i].ParameterType, ctorArgumentValues[i]);

                        instanceParameterDetails.Add(_parmatersDetails[i].Description, tempParameterDetail);
                    }

                    // Create Strategy Instance object
                    var instance = new StrategyInstance(key, instanceParameterDetails, optimizationParameters.StrategyType);

                    // Save Strategy details in new Strategy Executor object
                    var strategyExecutor = new StrategyExecutor(instance, _currentDispatcher);

                    // Register Event
                    strategyExecutor.StatusChanged += OnStrategyExecutorStatusChanged;

                    // Add to local map
                    _strategiesCollection.AddOrUpdate(key, strategyExecutor, (ky, value) => strategyExecutor);

                    StringBuilder parametersInfo = new StringBuilder();
                    foreach (object ctorArgument in strategyExecutor.CtorArguments)
                    {
                        parametersInfo.Append(ctorArgument.ToString());
                        parametersInfo.Append(" | ");
                    }

                    // Create new object to be used with Event Aggregator
                    var optimizationStatistics = new OptimizationStatistics(strategyExecutor.StrategyKey);
                    optimizationStatistics.Description      = parametersInfo.ToString();
                    optimizationStatistics.ExecutionDetails = instance.ExecutionDetails;

                    // Raise event to Bind statistics to UI and will be updated as each instance is executed
                    EventSystem.Publish <OptimizationStatistics>(optimizationStatistics);
                }

                // Save total number of iterations count
                _optimizationParameters.TotalIterations = _strategiesCollection.Count;

                // Start executing each instance
                StartStrategyExecution();
            }
            catch (Exception exception)
            {
                _asyncClassLogger.Error(exception, _type.FullName, "StartOptimization");
            }
        }