ApproximateOptimization/OptimizerFactory.cs
/// <summary>
/// Main factory method creating the composite of all optimizers defined in this project.
/// </summary>
/// <param name="optimizerParams">Problem definition.</param>
/// <param name="threads">Number of threads to run.</param>
/// <param name="rangeDiscovery">Range discovery (by default it's disabled).
/// Please be aware that it may be misleading;
/// it's better to give the expected range in the beginning because range discovery is very simple
/// and only widens the range when the maximum is found at the end of the range; 
/// you may accidentally have a local maximum inside of the range and range discovery
/// will not trigger range widening, potentially missing global maximum).
/// </param>
/// <param name="rangeDiscoveryMaxAttempts">Maximum number of times the optimizer will be run
/// with widening solution range. Parameter only works when rangeDiscovery is passed as true.</param>
/// <returns>An optimizer employing MultithreadedOptimizer to run SimulatedAnnealingWithGradientAscent</returns>
Main factory method creating the composite of all optimizers defined in this project.
Main factory method creating the composite of all optimizers defined in this project .
public static IOptimizer GetCompositeOptimizer(
            SimulatedAnnealingWithGradientAscentOptimizerParams optimizerParams, int threads = 8, bool rangeDiscovery = false, int rangeDiscoveryMaxAttempts=50)
        {
            if (!rangeDiscovery)
            {
                return new ConcreteCompositeOptimizer(
                    new ConcreteMultiThreadedOptimizerParams(
                    optimizerParams)
                    {
                        ThreadCount = threads
                    });
            }
            return
                new ConcreteOptimizerWithRangeDiscovery(new ConcreteOptimizerWithRangeDiscoveryParams
            {
                MaxAttempts = rangeDiscoveryMaxAttempts,
                Dimension = optimizerParams.Dimension,
                OptimizerFactoryMethod = (solutionRange) =>
                {
                    optimizerParams.SolutionRange = solutionRange;
                    return new ConcreteCompositeOptimizer(
                    new ConcreteMultiThreadedOptimizerParams(optimizerParams)
                    {
                        ThreadCount = threads,
                    });
                }
            });
        }
public static IOptimizer GetCompositeOptimizer ( SimulatedAnnealingWithGradientAscentOptimizerParams optimizerParams , int threads = 8 , bool rangeDiscovery = false , int rangeDiscoveryMaxAttempts = 50 ) { if ( ! rangeDiscovery ) { return new ConcreteCompositeOptimizer ( new ConcreteMultiThreadedOptimizerParams ( optimizerParams ) { ThreadCount = threads } ) ; } return new ConcreteOptimizerWithRangeDiscovery ( new ConcreteOptimizerWithRangeDiscoveryParams { MaxAttempts = rangeDiscoveryMaxAttempts , Dimension = optimizerParams . Dimension , OptimizerFactoryMethod = ( solutionRange ) => { optimizerParams . SolutionRange = solutionRange ; return new ConcreteCompositeOptimizer ( new ConcreteMultiThreadedOptimizerParams ( optimizerParams ) { ThreadCount = threads , } ) ; } } ) ; }
Main factory method creating the composite of all optimizers defined in this project.
Main factory method creating the composite of all optimizers defined in this project .
An optimizer employing MultithreadedOptimizer to run SimulatedAnnealingWithGradientAscent
An optimizer employing MultithreadedOptimizer to run SimulatedAnnealingWithGradientAscent
optimizerParams
SimulatedAnnealingWithGradientAscentOptimizerParams
None
threads
int
Number of threads to run.
Number of threads to run .
rangeDiscovery
bool
Range discovery (by default it's disabled).
Please be aware that it may be misleading;
it's better to give the expected range in the beginning because range discovery is very simple
and only widens the range when the maximum is found at the end of the range;
you may accidentally have a local maximum inside of the range and range discovery
will not trigger range widening, potentially missing global maximum).
Range discovery ( by default it ' s disabled ) . Please be aware that it may be misleading ; it ' s better to give the expected range in the beginning because range discovery is very simple and only widens the range when the maximum is found at the end of the range ; you may accidentally have a local maximum inside of the range and range discovery will not trigger range widening potentially missing global maximum ) .
rangeDiscoveryMaxAttempts
int
Maximum number of times the optimizer will be run
with widening solution range. Parameter only works when rangeDiscovery is passed as true.
Maximum number of times the optimizer will be run with widening solution range . Parameter only works when rangeDiscovery is passed as true .