17 using System.Collections.Generic;
18 using System.Globalization;
78 throw new InvalidOperationException($
"GridSearchOptimizationStrategy.Initialize: can not be re-initialized.");
89 if (!optimizationParameter.Step.HasValue)
92 if (stepSettings ==
null)
94 throw new ArgumentException($
"OptimizationStrategySettings is not of {nameof(StepBaseOptimizationStrategySettings)} type", nameof(settings));
96 CalculateStep(optimizationParameter, stepSettings.DefaultSegmentAmount);
118 total *= Estimate(arg);
135 if (stepParameter ==
null)
137 throw new InvalidOperationException($
"Cannot estimate parameter of type {parameter.GetType().FullName}");
140 if (!stepParameter.Step.HasValue)
142 throw new InvalidOperationException(
"Optimization parameter cannot be estimated due to step value is not initialized");
145 return (
int)Math.Floor((stepParameter.MaxValue - stepParameter.MinValue) / stepParameter.Step.Value) + 1;
178 protected IEnumerable<ParameterSet>
Step(HashSet<OptimizationParameter> args)
180 foreach (var step
in Recursive(
new Queue<OptimizationParameter>(args)))
184 step.ToDictionary(kvp => kvp.Key, kvp => kvp.Value));
193 if (defaultSegmentAmount < 1)
195 throw new ArgumentException($
"Number of segments should be positive number, but specified '{defaultSegmentAmount}'", nameof(defaultSegmentAmount));
202 private IEnumerable<Dictionary<string, string>> Recursive(Queue<OptimizationParameter> args)
206 var optimizationParameterLast = args.Dequeue();
207 using (var optimizationParameterLastEnumerator = GetEnumerator(optimizationParameterLast))
209 while (optimizationParameterLastEnumerator.MoveNext())
211 yield
return new Dictionary<string, string>()
213 {optimizationParameterLast.Name, optimizationParameterLastEnumerator.Current}
221 var optimizationParameter = args.Dequeue();
222 using (var optimizationParameterEnumerator = GetEnumerator(optimizationParameter))
224 while (optimizationParameterEnumerator.MoveNext())
226 foreach (var inner
in Recursive(
new Queue<OptimizationParameter>(args)))
228 inner.Add(optimizationParameter.Name, optimizationParameterEnumerator.Current);
239 if (staticOptimizationParameter !=
null)
241 return new List<string> { staticOptimizationParameter.
Value }.GetEnumerator();
245 if (stepParameter ==
null)
247 throw new InvalidOperationException(
"");