Exemplo n.º 1
0
 /// <summary>
 /// Construct with the provided IGenomeDecoder, IPhenomeEvaluator and ParalleOptions.
 /// Phenome caching is enabled by default.
 /// The number of parallel threads defaults to Environment.ProcessorCount.
 /// </summary>
 public ParallelGenomeListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
                                    IPhenomeEvaluator <TPhenome> phenomeEvaluator,
                                    ParallelOptions options)
 //: this(genomeDecoder, phenomeEvaluator, options, true)
     : this(genomeDecoder, phenomeEvaluator, options, false)
 {
 }
Exemplo n.º 2
0
 /// <summary>
 /// Construct with the provided IGenomeDecoder and IPhenomeEvaluator.
 /// Phenome caching is enabled by default.
 /// </summary>
 public SerialGenomeListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeEvaluator <TPhenome> phenomeEvaluator)
 {
     _genomeDecoder        = genomeDecoder;
     _phenomeEvaluator     = phenomeEvaluator;
     _enablePhenomeCaching = true;
     _evaluationMethod     = Evaluate_Caching;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Construct with the provided genome decoder and phenome evaluator.
        /// </summary>
        /// <param name="genomeDecoder">Genome decoder.</param>
        /// <param name="phenomeEvaluationScheme">Phenome evaluation scheme.</param>
        /// <param name="degreeOfParallelism">The desired degree of parallelism.</param>
        public ParallelGenomeListEvaluatorStateless(
            IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
            IPhenomeEvaluationScheme <TPhenome> phenomeEvaluationScheme,
            int degreeOfParallelism)
        {
            // This class can only accept an evaluation scheme that uses a stateless evaluator.
            if (phenomeEvaluationScheme.EvaluatorsHaveState)
            {
                throw new ArgumentException(nameof(phenomeEvaluationScheme));
            }

            // Reject degreeOfParallelism values less than 2. -1 should have been resolved to an actual number by the time
            // this constructor is invoked, and 1 is nonsensical for a parallel evaluator.
            if (degreeOfParallelism < 2)
            {
                throw new ArgumentException(nameof(degreeOfParallelism));
            }

            _genomeDecoder           = genomeDecoder;
            _phenomeEvaluationScheme = phenomeEvaluationScheme;
            _phenomeEvaluator        = phenomeEvaluationScheme.CreateEvaluator();
            _parallelOptions         = new ParallelOptions {
                MaxDegreeOfParallelism = degreeOfParallelism
            };
        }
 /// <summary>
 /// Construct with the provided <see cref="IGenomeDecoder"/> and <see cref="IPhenomeEvaluator"/>.
 /// Phenome caching is enabled by default.
 /// </summary>
 public SerialGenomeListEvaluator(
     IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
     IPhenomeEvaluator <TPhenome> phenomeEvaluator)
 {
     _genomeDecoder    = genomeDecoder;
     _phenomeEvaluator = phenomeEvaluator;
 }
 /// <summary>
 /// Construct with the provided IGenomeDecoder and IPhenomeEvaluator.
 /// </summary>
 public UnityParallelListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
                                   IPhenomeEvaluator <TPhenome> phenomeEvaluator,
                                   NEATController neController)
 {
     _genomeDecoder    = genomeDecoder;
     _phenomeEvaluator = phenomeEvaluator;
     this.neController = neController;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Construct with the provided IGenomeDecoder and IPhenomeEvaluator.
 /// </summary>
 public CoroutinedListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
                                IPhenomeEvaluator <TPhenome> phenomeEvaluator,
                                NeatSupervisor neatSupervisor)
 {
     _genomeDecoder    = genomeDecoder;
     _phenomeEvaluator = phenomeEvaluator;
     _neatSupervisor   = neatSupervisor;
 }
 /// <summary>
 /// Constructor taking a genomedecoder and phenomeEvaluator.
 /// </summary>
 public UnityParallelListEvaluatorOrganism(IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
                                           IPhenomeEvaluator <TPhenome> phenomeEvaluator,
                                           NEATControllerOrg controller)
 {
     _genomeDecoder    = genomeDecoder;
     _phenomeEvaluator = phenomeEvaluator;
     this.controller   = controller;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Construct with the provided IGenomeDecoder and IPhenomeEvaluator.
 /// </summary>
 public UnityParallelListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
                                   IPhenomeEvaluator <TPhenome> phenomeEvaluator,
                                   Optimizer opt)
 {
     _genomeDecoder    = genomeDecoder;
     _phenomeEvaluator = phenomeEvaluator;
     _optimizer        = opt;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Construct with the provided IGenomeDecoder and IPhenomeEvaluator.
 /// </summary>
 public UnityAstroidEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
                              IPhenomeEvaluator <TPhenome> phenomeEvaluator,
                              Optimizer opt)
 {
     _genomeDecoder    = genomeDecoder;
     _phenomeEvaluator = phenomeEvaluator;
     _optimizer        = opt;
 }
 /// <summary>
 /// Construct with the provided IGenomeDecoder, IPhenomeEvaluator and ParalleOptions.
 /// Phenome caching is enabled by default.
 /// The number of parallel threads defaults to Environment.ProcessorCount.
 /// </summary>
 public CacheFirstParallelGenomeListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
                                              IPhenomeEvaluator <TPhenome> phenomeEvaluator,
                                              ParallelOptions options)
 {
     _genomeDecoder    = genomeDecoder;
     _phenomeEvaluator = phenomeEvaluator;
     _parallelOptions  = options;
 }
Exemplo n.º 11
0
 public BraidListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
                           IPhenomeEvaluator <TPhenome> phenomeEvaluator,
                           Optimizer opt)
 {
     m_genomeDecoder    = genomeDecoder;
     m_phenomeEvaluator = phenomeEvaluator;
     m_optimizer        = opt;
 }
 /// <summary>
 /// Construct with the provided IGenomeDecoder and IPhenomeEvaluator.
 /// </summary>
 public UnityMultiLayerEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
                                 IPhenomeEvaluator <TPhenome> phenomeEvaluator,
                                 Optimizer opt, AgarEvaluator agar)
 {
     _genomeDecoder    = genomeDecoder;
     _phenomeEvaluator = phenomeEvaluator;
     _optimizer        = opt;
     _agar             = agar;
 }
        /// <summary>
        /// Construct with the provided <see cref="IGenomeDecoder{TGenome,TPhenome}"/> and <see cref="IPhenomeEvaluator{TPhenome}"/>.
        /// Phenome caching is enabled by default.
        /// </summary>
        public SerialGenomeListEvaluator(
            IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
            IPhenomeEvaluationScheme <TPhenome> phenomeEvaluationScheme)
        {
            _genomeDecoder           = genomeDecoder;
            _phenomeEvaluationScheme = phenomeEvaluationScheme;

            // Note. SerialGenomeListEvaluator will only evaluate on one thread therefore only ever requires a single evaluator.
            _phenomeEvaluator = phenomeEvaluationScheme.CreateEvaluator();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Construct with the provided IGenomeDecoder, IPhenomeEvaluator and enablePhenomeCaching flag.
        /// </summary>
        public SerialGenomeListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeEvaluator <TPhenome> phenomeEvaluator, bool enablePhenomeCaching)
        {
            _genomeDecoder        = genomeDecoder;
            _phenomeEvaluator     = phenomeEvaluator;
            _enablePhenomeCaching = enablePhenomeCaching;

            if (_enablePhenomeCaching)
            {
                _evaluationMethod = Evaluate_Caching;
            }
            else
            {
                _evaluationMethod = Evaluate_NonCaching;
            }
        }
        /// <summary>
        /// Construct with the provided IGenomeDecoder, IPhenomeEvaluator and ParallelOptions.
        /// </summary>
        public ParallelGenomeListEvaluatorStateless(
            IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
            IPhenomeEvaluationScheme <TPhenome> phenomeEvaluatorScheme,
            ParallelOptions parallelOptions)
        {
            // This class can only accept an evaluation scheme that uses a stateless evaluator.
            if (phenomeEvaluatorScheme.EvaluatorsHaveState)
            {
                throw new ArgumentException(nameof(phenomeEvaluatorScheme));
            }

            _genomeDecoder           = genomeDecoder;
            _phenomeEvaluationScheme = phenomeEvaluatorScheme;
            _phenomeEvaluator        = phenomeEvaluatorScheme.CreateEvaluator();
            _parallelOptions         = parallelOptions;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Construct with the provided IGenomeDecoder, IPhenomeEvaluator, ParalleOptions and enablePhenomeCaching flag.
        /// </summary>
        public ParallelGenomeListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeEvaluator <TPhenome> phenomeEvaluator, ParallelOptions options, bool enablePhenomeCaching)
        {
            _genomeDecoder        = genomeDecoder;
            _phenomeEvaluator     = phenomeEvaluator;
            _parallelOptions      = options;
            _enablePhenomeCaching = enablePhenomeCaching;

            // Determine the appropriate evaluation method.
            if (_enablePhenomeCaching)
            {
                _evalMethod = Evaluate_Caching;
            }
            else
            {
                _evalMethod = Evaluate_NonCaching;
            }
        }
Exemplo n.º 17
0
        public NeuromonExperiment(ExperimentSettings experimentSettings, NeatEvolutionAlgorithmParameters evolutionAlgorithmParameters, IPhenomeEvaluator<IBlackBox> neuromonPhenomeEvaluator, NeatGenomeParameters genomeParameters)
        {
            Name = experimentSettings.ExperimentName;
            Description = experimentSettings.Description;
            InputCount = experimentSettings.InputCount;
            OutputCount = experimentSettings.OutputCount;
            DefaultPopulationSize = experimentSettings.PopulationSize;

            _neuromonPhenomeEvaluator = neuromonPhenomeEvaluator;
            _complexityRegulationStrategy = experimentSettings.ComplexityRegulationStrategy;
            _complexityThreshold = experimentSettings.ComplexityThreshold;

            // Removed from .xml configuration. TODO: Possibly make configurable via json config
            _networkActivationScheme = NetworkActivationScheme.CreateCyclicFixedTimestepsScheme(1);

            NeatEvolutionAlgorithmParameters = evolutionAlgorithmParameters;
            NeatGenomeParameters = genomeParameters;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Construct with the provided IGenomeDecoder, IPhenomeEvaluator, enablePhenomeCaching flag
        /// and thread count.
        /// </summary>
        /// <param name="genomeDecoder"></param>
        /// <param name="phenomeEvaluator"></param>
        /// <param name="enablePhenomeCaching"></param>
        /// <param name="threadCount"></param>
        public ParallelGenomeListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
                                           IPhenomeEvaluator <TPhenome> phenomeEvaluator,
                                           bool enablePhenomeCaching,
                                           int threadCount)
        {
            _genomeDecoder        = genomeDecoder;
            _phenomeEvaluator     = phenomeEvaluator;
            _enablePhenomeCaching = enablePhenomeCaching;

            // Determine the appropriate worker-thread method.
            Action <object> workerThreadmethod;

            if (_enablePhenomeCaching)
            {
                workerThreadmethod = WorkerThreadMethod_Caching;
            }
            else
            {
                workerThreadmethod = WorkerThreadMethod_NonCaching;
            }

            _infoArr = new WorkerThreadInfo[threadCount];
            _completedWorkEventArr = new ManualResetEvent[threadCount];
            _threadArr             = new Thread[threadCount];
            for (int i = 0; i < threadCount; i++)
            {
                // Create thread and its own info object.
                WorkerThreadInfo info   = new WorkerThreadInfo();
                Thread           thread = new Thread(new ParameterizedThreadStart(workerThreadmethod));
                thread.IsBackground = true;
                thread.Priority     = ThreadPriority.BelowNormal;

                // Store the thread and it's info object in arrays.
                // Also store references to all of the created _completedWorkEvent objects in an array,
                // this allows to wait for all of them together (WaitHandle.WaitAny/All).
                _threadArr[i]             = thread;
                _infoArr[i]               = info;
                _completedWorkEventArr[i] = info._completedWorkEvent;

                // Start the thread and pass the info object to this invocation of the thread method.
                thread.Start(info);
            }
        }
        /// <summary>
        /// Releases an evaluator back into the pool.
        /// </summary>
        /// <param name="evaluator">The evaluator to release.</param>
        public void ReleaseEvaluator(IPhenomeEvaluator <TPhenome> evaluator)
        {
            bool lockTaken = false;

            try
            {
                // Wait for the sync lock.
                _spinLock.Enter(ref lockTaken);

                // Put the evaluator into the pool.
                _evaluatorStack.Push(evaluator);
            }
            finally
            {
                // Release the sync lock.
                if (lockTaken)
                {
                    _spinLock.Exit(false);
                }
            }
        }
 /// <summary>
 /// Construct with the provided IGenomeDecoder and IPhenomeEvaluator.
 /// Phenome caching is enabled by default.
 /// The number of parallel threads defaults to Environment.ProcessorCount.
 /// </summary>
 public ParallelGenomeListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
                                    IPhenomeEvaluator <TPhenome> phenomeEvaluator)
     : this(genomeDecoder, phenomeEvaluator, new ParallelOptions(), true)
 {
 }
Exemplo n.º 21
0
 /// <summary>
 /// Construct with the provided IGenomeDecoder and IPhenomeEvaluator.
 /// Phenome caching is enabled by default.
 /// </summary>
 public SerialGenomeListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
                                  IPhenomeEvaluator <TPhenome> phenomeEvaluator)
     : this(genomeDecoder, phenomeEvaluator, true)
 {
 }
Exemplo n.º 22
0
        /// <summary>
        /// This is my implementation that takes in a base args class instead of xml
        /// </summary>
        /// <remarks>
        /// Initialize must be called after the constructor.  After that, NeatEvolutionAlgorithmParameters and NeatGenomeParameters will be
        /// instantiated, and can be tweaked
        ///
        /// Once all the properties are set the way you want, call CreateEvolutionAlgorithm():
        ///
        ///     _experiment = new ExperimentBase_NEAT()     // or something that derives from this base
        ///     _experiment.Initialize(args, evaluator);
        ///
        ///     _experiment.NeatGenomeParameters.??? = ???
        ///     _experiment.NeatEvolutionAlgorithmParameters.??? = ???
        ///
        ///     _ea = _experiment.CreateEvolutionAlgorithm();
        /// </remarks>
        public void Initialize(string name, ExperimentInitArgs args, IPhenomeEvaluator <IBlackBox> phenomeEvaluator)
        {
            _phenomeEvaluator = phenomeEvaluator;

            Initialize_private(name, args);
        }
Exemplo n.º 23
0
 public SineExperiment(bool evaluateParents, IPhenomeEvaluator<IBlackBox> phenomeEvaluator)
 {
     EvaluateParents = evaluateParents;
     PhenomeEvaluator = phenomeEvaluator;
 }
Exemplo n.º 24
0
 private void GetPhenomeEvaluator()
 {
     _PhenomeEvaluator = PhenomeEvaluator();
 }
Exemplo n.º 25
0
 public SimpleGenomeListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeEvaluator <TPhenome> phenomeEvaluator)
 {
     this.genomeDecoder    = genomeDecoder;
     this.phenomeEvaluator = phenomeEvaluator;
 }
Exemplo n.º 26
0
 /// <summary>
 /// Construct with the provided IGenomeDecoder and IPhenomeEvaluator.
 /// Phenome caching is enabled by default.
 /// The number of parallel threads defaults to Environment.ProcessorCount.
 /// </summary>
 /// <param name="genomeDecoder"></param>
 /// <param name="phenomeEvaluator"></param>
 public ParallelGenomeListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
                                    IPhenomeEvaluator <TPhenome> phenomeEvaluator)
     : this(genomeDecoder, phenomeEvaluator, true, Environment.ProcessorCount)
 {
 }
Exemplo n.º 27
0
 /// <summary>
 /// Construct with the provided IGenomeDecoder, IPhenomeEvaluator and enablePhenomeCaching flag.
 /// The number of parallel threads defaults to Environment.ProcessorCount.
 /// </summary>
 /// <param name="genomeDecoder"></param>
 /// <param name="phenomeEvaluator"></param>
 /// <param name="enablePhenomeCaching"></param>
 public ParallelGenomeListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder,
                                    IPhenomeEvaluator <TPhenome> phenomeEvaluator,
                                    bool enablePhenomeCaching)
     : this(genomeDecoder, phenomeEvaluator, enablePhenomeCaching, Environment.ProcessorCount)
 {
 }