/// <summary> /// Starts optimization of the startegy using Genetic Algorithm /// </summary> /// <param name="ctrArgs">Arguments to be used to execute strategy</param> private void RunStrategyOptimizationGeneticAlgo(object[] ctrArgs) { // Get View to display details for optimization engine var context = ContextRegistry.GetContext(); _geneticShell = context.GetObject("GeneticAlgoShell") as GeneticShell; if (_geneticShell != null) { _geneticShell.Show(); // Get custom attributes from the given strategy var customAttributes = GetCustomAttributes(_strategyType); if (customAttributes != null) { // Create new object to use with Event Aggregator OptimizationParametersGeneticAlgo optimizeStrategy = new OptimizationParametersGeneticAlgo(ctrArgs, _strategyType, customAttributes); // Publish Event to Notify Listeners EventSystem.Publish <OptimizationParametersGeneticAlgo>(optimizeStrategy); } else { Logger.Info("No Custom Attributes were found for GA optimization", _type.FullName, "RunStrategyOptimizationGeneticAlgo"); } } }
/// <summary> /// Displays available parameters for genetic optimization /// </summary> private void DisplayGeneticParameters(OptimizationParametersGeneticAlgo optimizeStrategyGeneticAlgo) { try { if (Logger.IsDebugEnabled) { Logger.Debug("Displaying the strategy parameters", _type.FullName, "DisplaySelectedStrategy"); } _parameters.Clear(); // Get Strategy Info GaStrategyInfo = LoadCustomStrategy.GetCustomClassSummary(optimizeStrategyGeneticAlgo.StrategyType); // Save Ctor Arguments _ctorArguments = optimizeStrategyGeneticAlgo.CtorArguments; // Save Custom Strategy Type _strategyType = optimizeStrategyGeneticAlgo.StrategyType; int i = 0; // Get all parameters foreach (var parameters in optimizeStrategyGeneticAlgo.GeneticAlgoParameters) { double start = 0; double end = 0; if (i == 0) { start = 1; end = 5; } else if (i == 1) { start = 0.0001; end = 0.011; } else if (i == 2) { start = 0.2; end = 10; } else if (i == 3) { start = 0.002; end = 0.01; } GeneticAlgoParameters parameterInfo = new GeneticAlgoParameters { Index = parameters.Key, Description = parameters.Value.Item1, StartValue = start, EndValue = end, }; i++; // Update UI Element _currentDispatcher.Invoke(DispatcherPriority.Normal, (Action)(() => { // Add to collection _parameters.Add(parameterInfo); })); } } catch (Exception exception) { Logger.Error(exception, _type.FullName, "DisplayGeneticParameters"); } }