public AIInstance(InstanceSelector instanceSelector, int instanceNumber, Queue decisionRequestQueue, AIRandomControl aiRandomControl) { taskTrees = new Dictionary <RequestedInfoKey, InfoProviderTaskTree>(); this.instanceSelector = instanceSelector; this.instanceNumber = instanceNumber; this.decisionRequestQueue = decisionRequestQueue; this.decisionInProgress = new object(); //Setup the AI's and providers here infoStore = new InfoCollection(); infoProviderDictList = new Dictionary <InfoProviderType, InfoProviderBase>(); aiDictList = new Dictionary <AIGeneration, AIBase>(); //Setup the 1st infostore instance var GP = new GameProvider(infoStore, infoProviderDictList, aiRandomControl); var WRP = new ProviderWinRatio.WinRatioProvider(infoStore, infoProviderDictList, aiRandomControl); var BP = new BetsProvider(infoStore, infoProviderDictList, aiRandomControl); var CP = new CardsProvider(infoStore, infoProviderDictList, aiRandomControl); var AP = new AggressionProvider(infoStore, infoProviderDictList, aiRandomControl); var PAPP = new PlayerActionPredictionProvider(infoStore, infoProviderDictList, aiRandomControl); //Hard lock the infostore collection preventing any further changes. infoStore.HardLockInfoList(); //Setup the AI list //We are going to lock the AI's into random mode. aiDictList.Add(AIGeneration.SimpleV1, new SimpleAIV1(aiRandomControl)); aiDictList.Add(AIGeneration.SimpleV2, new SimpleAIV2(aiRandomControl)); aiDictList.Add(AIGeneration.NeuralV1, new NeuralAIv1(aiRandomControl)); aiDictList.Add(AIGeneration.SimpleV3, new SimpleAIV3(aiRandomControl)); aiDictList.Add(AIGeneration.NeuralV2, new NeuralAIv2(aiRandomControl)); aiDictList.Add(AIGeneration.SimpleV4AggressionTrack, new SimpleAIV4AggTrack(aiRandomControl)); aiDictList.Add(AIGeneration.NeuralV3, new NeuralAIv3(aiRandomControl)); aiDictList.Add(AIGeneration.NeuralV4, new NeuralAIv4(aiRandomControl)); aiDictList.Add(AIGeneration.SimpleV5, new SimpleAIv5(aiRandomControl)); aiDictList.Add(AIGeneration.SimpleV6, new SimpleAIv6(aiRandomControl)); aiDictList.Add(AIGeneration.NeuralV5, new NeuralAIv5(aiRandomControl)); aiDictList.Add(AIGeneration.NeuralV6, new NeuralAIv6(aiRandomControl)); aiDictList.Add(AIGeneration.SimpleV7, new SimpleAIv7(aiRandomControl)); aiDictList.Add(AIGeneration.CheatV1, new CheatV1(aiRandomControl)); aiDictList.Add(AIGeneration.NeuralV7, new NeuralAIv7(aiRandomControl)); if (ConcurrencyMode.Concurrency == ConcurrencyMode.ConcurencyModel.MultiCore) { providerTasks = new Dictionary <InfoProviderType, Task>(); } else { providerActions = new Dictionary <InfoProviderType, Action>(); } }
protected void InitTargets() { int length = TargetLength; Targets = new List <InstanceSelector>(length); For (length, (i) => { var newSelector = new InstanceSelector (TargetObjects[i], TargetNames[i]); Targets.Add(newSelector); }); }
private void AIManagerConstructor(int numInstances, AIRandomControl aiRandomControl, bool runInSafeMode, Object jobToRun) { RunInSafeMode = runInSafeMode; InfoProviderBase.CurrentJob = jobToRun; this.decisionRequestQueue = new Queue(); instanceSelector = new InstanceSelector(); aiInstanceList = new List <AIInstance>(); //Setup the instances for (int i = 0; i < numInstances; i++) { aiInstanceList.Add(new AIInstance(instanceSelector, i, decisionRequestQueue, aiRandomControl)); } for (int i = 0; i < numInstances; i++) { instanceSelector.instancesIdle = instanceSelector.instancesIdle | (1 << i); } }
/// <summary> /// Initializes a new instance of the <see cref="AlgorithmTuner{TTargetAlgorithm,TInstance,TResult,TModelLearner,TPredictorModel,TSamplingStrategy}"/> class. /// </summary> /// <param name="targetAlgorithmFactory"> /// Produces configured instances of the algorithm to tune. /// </param> /// <param name="runEvaluator"> /// Object for evaluating target algorithm runs. /// </param> /// <param name="trainingInstances"> /// The set of instances used for tuning. /// </param> /// <param name="parameterTree"> /// Provides the tunable parameters. /// </param> /// <param name="configuration"> /// Algorithm tuner configuration parameters. /// </param> /// <param name="genomeBuilder"> /// Responsible for creation, modification and crossover of genomes. /// Needs to be compatible with the given parameter tree and configuration. /// This parameter can be left out if an ordinary <see cref="GenomeBuilder"/> should be used. /// </param> public AlgorithmTuner( ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, IRunEvaluator <TResult> runEvaluator, IEnumerable <TInstance> trainingInstances, ParameterTree parameterTree, AlgorithmTunerConfiguration configuration, GenomeBuilder genomeBuilder) { ValidateParameters(targetAlgorithmFactory, runEvaluator, trainingInstances, parameterTree, configuration, genomeBuilder); LoggingHelper.WriteLine( VerbosityLevel.Info, $"Tuning target algorithm with {parameterTree.GetParameters().Count()} parameters."); this._configuration = configuration; this._runEvaluator = runEvaluator; this.GeneticEngineering = new GeneticEngineering <TModelLearner, TPredictorModel, TSamplingStrategy>(parameterTree, this._configuration); this.IncumbentQuality = new List <double>(); this._trainingInstances = trainingInstances.ToList(); this._instanceSelector = new InstanceSelector <TInstance>(this._trainingInstances, configuration); this._parameterTree = parameterTree; this._genomeBuilder = genomeBuilder; this._targetAlgorithmRunActors = ActorSystem.Create(AkkaNames.ActorSystemName, configuration.AkkaConfiguration); this._targetRunResultStorage = this._targetAlgorithmRunActors.ActorOf( Props.Create(() => new ResultStorageActor <TInstance, TResult>()), AkkaNames.ResultStorageActor); this._genomeSorter = this._targetAlgorithmRunActors.ActorOf( Props.Create(() => new GenomeSorter <TInstance, TResult>(runEvaluator)), AkkaNames.GenomeSorter); this._logWriter = new LogWriter <TInstance, TResult>(parameterTree, configuration); this._populationUpdateStrategyManager = new PopulationUpdateStrategyManager <TInstance, TResult>( this.CreatePopulationUpdateStrategies(targetAlgorithmFactory, runEvaluator).ToList(), configuration); }