/// <summary> /// Gets the harmony searcher instance. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="type">The type.</param> /// <param name="generator">The generator.</param> /// <param name="harmonyMemorySize">Size of the harmony memory.</param> /// <param name="maxImprovisationCount">The maximum improvisation count.</param> /// <param name="harmonyMemoryConsiderationRatio">The harmony memory consideration ratio.</param> /// <param name="pitchAdjustmentRatio">The pitch adjustment ratio.</param> /// <param name="minPitchAdjustmentRatio">The minimum pitch adjustment ratio.</param> /// <param name="maxPitchAdjustmentRatio">The maximum pitch adjustment ratio.</param> /// <param name="antColonyOptimizer">The ant colony optimizer.</param> /// <returns>Harmony searcher</returns> public static IHarmonySearcher <T> GetInstance <T>(HarmonySearchType type, IHarmonyGenerator <T> generator, int harmonyMemorySize, long maxImprovisationCount, double harmonyMemoryConsiderationRatio, double pitchAdjustmentRatio, double minPitchAdjustmentRatio, double maxPitchAdjustmentRatio, IAntColonyOptimizer <T> antColonyOptimizer = null) { switch (type) { default: { var parameterProvider = new ConstantParameterProvider(harmonyMemoryConsiderationRatio, pitchAdjustmentRatio); return(new HarmonySearcher <T>(generator, parameterProvider, harmonyMemorySize, maxImprovisationCount)); } case HarmonySearchType.Improved: { var parameterProvider = new DynamicPitchAdjustmentRatioProvider(harmonyMemoryConsiderationRatio, maxPitchAdjustmentRatio, minPitchAdjustmentRatio, maxImprovisationCount); return(new HarmonySearcher <T>(generator, parameterProvider, harmonyMemorySize, maxImprovisationCount)); } case HarmonySearchType.Dynamic: { var parameterProvider = new DynamicParameterProvider(harmonyMemorySize * 10); return(new HarmonySearcher <T>(generator, parameterProvider, harmonyMemorySize, maxImprovisationCount)); } case HarmonySearchType.AntColony: { var parameterProvider = new ConstantParameterProvider(harmonyMemoryConsiderationRatio, pitchAdjustmentRatio); return(new AntColonyHarmonySearcher <T>(generator, parameterProvider, antColonyOptimizer, harmonyMemorySize / 20, maxImprovisationCount / 20)); } case HarmonySearchType.Divided: { var parameterProvider = new ConstantParameterProvider(harmonyMemoryConsiderationRatio, pitchAdjustmentRatio); return(new DividedHarmonySearcher <T>(generator, parameterProvider, harmonyMemorySize, maxImprovisationCount)); } case HarmonySearchType.ImprovedDivided: { var parameterProvider = new DynamicPitchAdjustmentRatioProvider(harmonyMemoryConsiderationRatio, maxPitchAdjustmentRatio, minPitchAdjustmentRatio, maxImprovisationCount); return(new DividedHarmonySearcher <T>(generator, parameterProvider, harmonyMemorySize, maxImprovisationCount)); } case HarmonySearchType.DynamicDivided: { var parameterProvider = new DynamicParameterProvider(harmonyMemorySize * 10); return(new DividedHarmonySearcher <T>(generator, parameterProvider, harmonyMemorySize, maxImprovisationCount)); } } }
/// <summary> /// Initializes a new instance of the <see cref="AntColonyHarmonySearcher{T}"/> class. /// </summary> /// <param name="harmonyGenerator">The harmony generator.</param> /// <param name="parameterProvider">The parameter provider.</param> /// <param name="antColonyOptimizer">The ant colony optimizer.</param> /// <param name="harmonyMemorySize">Size of the harmony memory.</param> /// <param name="maxImprovisationCount">The maximum improvisation count.</param> /// <exception cref="ArgumentNullException">antColonyOptimizer</exception> public AntColonyHarmonySearcher(IHarmonyGenerator <T> harmonyGenerator, IParameterProvider parameterProvider, IAntColonyOptimizer <T> antColonyOptimizer, int harmonyMemorySize = HarmonySearchConstants.DefaultHarmonyMemorySize, long maxImprovisationCount = HarmonySearchConstants.DefaultMaxImprovisationCount) : base(harmonyGenerator, parameterProvider, harmonyMemorySize, maxImprovisationCount) { _antColonyOptimizer = antColonyOptimizer ?? throw new ArgumentNullException(nameof(antColonyOptimizer)); MaxImprovisationCountWithTheSameBestValue = (int)(maxImprovisationCount / 20); }
/// <summary> /// The constructor /// </summary> /// <param name="harmonyGenerator">Harmony generator</param> /// <param name="parameterProvider"></param> /// <param name="harmonyMemorySize">Harmony memory size</param> /// <param name="maxImprovisationCount">Maximal improvisation count</param> public HarmonySearcher(IHarmonyGenerator <T> harmonyGenerator, IParameterProvider parameterProvider, int harmonyMemorySize = DefaultHarmonyMemorySize, long maxImprovisationCount = DefaultMaxImprovisationCount) { MaxImprovisationCount = maxImprovisationCount; HarmonyGenerator = harmonyGenerator ?? throw new ArgumentNullException(nameof(harmonyGenerator)); ParameterProvider = parameterProvider ?? throw new ArgumentNullException(nameof(parameterProvider)); HarmonyMemory = new HarmonyMemory <T>(harmonyMemorySize); HarmonyGenerator.HarmonyMemory = HarmonyMemory; BestHarmonyObjectiveValue = double.PositiveInfinity; MaxImprovisationCountWithTheSameBestValue = (int)(maxImprovisationCount / 10); }
/// <summary> /// Initializes a new instance of the <see cref="DividedHarmonySearcher{T}"/> class. /// </summary> /// <param name="harmonyGenerator">Harmony generator</param> /// <param name="parameterProvider"></param> /// <param name="harmonyMemorySize">Harmony memory size</param> /// <param name="maxImprovisationCount">Maximal improvisation count</param> public DividedHarmonySearcher(IHarmonyGenerator <T> harmonyGenerator, IParameterProvider parameterProvider, int harmonyMemorySize = DefaultHarmonyMemorySize, long maxImprovisationCount = DefaultMaxImprovisationCount) : base(harmonyGenerator, parameterProvider, harmonyMemorySize, maxImprovisationCount) { }