コード例 #1
0
        /// <summary>
        /// Gets called by the <see cref="GeneticSharp"/> library when a mutation of a solution candidate is performed.
        /// Consists of two mutation operators <see cref="MutateByOne(IChromosome)"/> & <see cref="MutateByCharacterFlip(IChromosome)"/>
        /// </summary>
        /// <param name="chromosome">The solution candidate to mutate.</param>
        /// <param name="probability">The probability of a mutation.</param>
        protected override void PerformMutate(IChromosome chromosome, float probability)
        {
            var genesLength = chromosome.Length;

            if (m_rnd.GetDouble() <= probability)
            {
                MutateByOne(chromosome);
            }
            if (m_rnd.GetDouble() <= probability)
            {
                MutateByCharacterFlip(chromosome);
            }
        }
コード例 #2
0
        /// <summary>
        /// Generates encounter elements for a specified encounter.
        /// </summary>
        /// <param name="encounter">The encounter.</param>
        /// <returns>IEnumerable&lt;EncounterElement&gt;.</returns>
        public IEnumerable <EncounterElement> GenerateElementsForEncounter(EncounterData encounter, IRandomization randomization)
        {
            var elements = new List <EncounterElement>();

            foreach (var contentElement in encounter.Entities)
            {
                decimal chance = contentElement.Chance;

                if (chance < 1.0m && chance < (decimal)randomization.GetDouble())
                {
                    continue;
                }

                // Some encounters can have varying quantities of actors in them.
                var quantity = GetEntityQuantity(randomization, contentElement);

                // Generate the required number of entries
                for (int i = 0; i < quantity; i++)
                {
                    elements.Add(new EncounterElement {
                        ObjectType = GameObjectType.Actor, ObjectId = contentElement.Id
                    });
                }
            }

            return(elements);
        }
コード例 #3
0
        protected override void PerformMutate(IChromosome chromosome, float probability)
        {
            try
            {
                CPChromosome cpChromosome = chromosome as CPChromosome;
                double       rand         = m_rnd.GetDouble();
                if (!(rand <= probability))
                {
                    return;
                }

                int[] genes = cpChromosome.GetValues();

                Graph graph = GraphProvider.Graph;

                foreach (int vertex in graph.Vertexes)
                {
                    IList <int> p = graph.NeighborsList(vertex);
                    if (p.Any(z => genes[z - 1] == genes[vertex - 1]))
                    {
                        genes[vertex - 1] = m_rnd.GetInt(0, chromosome.Length);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
コード例 #4
0
        protected override void PerformMutate(IChromosome chromosome, float probability)
        {
            var genome = chromosome as ThermalGenome;

            if (_random.GetDouble() <= probability)
            {
                var index = _random.GetInt(0, chromosome.Length);
                var bound = genome.Bounds[index];
                genome.ReplaceGene(index, new Gene(_random.GetInt(bound.Min, bound.Max + 1)));
            }
        }
コード例 #5
0
        protected override void PerformMutate(IChromosome chromosome, float probability)
        {
            var cpChromosome = chromosome as CPChromosome;

            if (m_rnd.GetDouble() <= probability)
            {
                var i  = m_rnd.GetInt(0, chromosome.Length);
                var j  = m_rnd.GetInt(0, chromosome.Length);
                var v1 = cpChromosome.GetGene(i);
                var v2 = cpChromosome.GetGene(j);
                cpChromosome.ReplaceGene(i, v2);
                cpChromosome.ReplaceGene(j, v1);
            }
        }
コード例 #6
0
        /// <summary>
        /// Mutate the specified chromosome.
        /// </summary>
        /// <param name="chromosome">The chromosome.</param>
        /// <param name="probability">The probability to mutate each chromosome.</param>
        protected override void PerformMutate(IChromosome chromosome, float probability)
        {
            var binaryChromosome = chromosome as IBinaryChromosome;

            if (binaryChromosome == null)
            {
                throw new MutationException(this, "Needs a binary chromosome that implements IBinaryChromosome.");
            }

            if (m_rnd.GetDouble() <= probability)
            {
                var index = m_rnd.GetInt(0, chromosome.Length);
                binaryChromosome.FlipGene(index);
            }
        }
コード例 #7
0
 private static int CalculateAttackStrength(GameObjectBase attacker, IRandomization random)
 {
     // Actors can attack anywhere from 100% - 150% their base strength
     return((int)Math.Round(attacker.EffectiveStrength * (decimal)random.GetDouble(1, 1.5)));
 }
コード例 #8
0
 private static int CalculateDefenseStrength(GameObjectBase defender, IRandomization random)
 {
     // Actors can defend anywhere from 100% - 250% their base strength
     return((int)Math.Round(defender.EffectiveDefense * (decimal)random.GetDouble(1, 2.5)));
 }