Example #1
0
        protected virtual IEnumerable <IDeploymentChromosome> Cross(IEnumerable <IDeploymentChromosome> parents)
        {
            var crossoverParents = new IDeploymentChromosome[CrossoverOperator.ParentsNumber];
            var i = 0;
            List <IDeploymentChromosome> offspring = new List <IDeploymentChromosome>();

            foreach (var parent in parents)
            {
                crossoverParents[i] = parent;
                i++;
                if (i == CrossoverOperator.ParentsNumber)
                {
                    if (RandomProvider.GetRandom() <= CrossoverProbability)
                    {
                        offspring.AddRange(CrossoverOperator.Cross(crossoverParents));
                    }
                    else
                    {
                        offspring.AddRange(crossoverParents);
                    }
                    i = 0;
                }
            }
            if (i != 0)
            {
                offspring.AddRange(crossoverParents.Take(i));
            }
            return(offspring);
        }
        public IDeploymentChromosome Mutate(IDeploymentChromosome deployment)
        {
            var genes           = deployment.Genes;
            var microserviceIds = genes.Select(g => new MicroserviceIdentifier(g.FeatureId.ToString())).ToArray();
            var newGenes        = new List <IDeploymentGene>();

            foreach (var gene in genes)
            {
                var clonedGene = new DeploymentGene(gene.FeatureId, microserviceIds[_randomProvider.GetRandom(0, microserviceIds.Length)]);
                newGenes.Add(clonedGene);
            }
            return(deployment.UpdateGenes(newGenes));
        }
        public double Evaluate(IDeploymentChromosome deployment, SampleWorkload workload)
        {
            var deploymentModel = deployment.ToDeploymentModel();
            var microserviceQueueingTheoryInfo = new List <QueueingTheoryInfo>();

            foreach (var microservice in deploymentModel.Microservices)
            {
                // Get the queueing theory representation for every type of event that this microservice listens to
                var customerTypes = microservice.Select(workload.GetQueueingTheoryInfo);

                // Calculate the summation of this these customer classes
                microserviceQueueingTheoryInfo.Add(customerTypes.Aggregate((result, current) => result + current));
            }
            // In this case we want to minimize the mean sojourn time
            // For real usage you would want more complex calculations here
            return(-microserviceQueueingTheoryInfo.Select(q => q.SojournTime).Average());
        }
        internal IDeploymentChromosome Cross(IDeploymentChromosome firstParent, IDeploymentChromosome secondParent, int firstGeneIndex, int secondGeneIndex)
        {
            var firstParentGenes  = firstParent.Genes.ToArray();
            var secondParentGenes = secondParent.Genes.ToArray();

            if (firstParentGenes.Length != secondParentGenes.Length)
            {
                throw new ArgumentException("Both Chromosomes should have the same length");
            }

            var firstMicroserviceId  = firstParentGenes[firstGeneIndex].MicroserviceId;
            var secondMicroserviceId = secondParentGenes[secondGeneIndex].MicroserviceId;

            var FeatureIdsToBeMovedFromFirstParent  = firstParentGenes.Where(g => g.MicroserviceId == firstMicroserviceId).Select(g => g.FeatureId);
            var FeatureIdsToBeMovedFromSecondParent = secondParentGenes.Where(g => g.MicroserviceId == secondMicroserviceId).Select(g => g.FeatureId);
            var featuresToBeMoved = FeatureIdsToBeMovedFromFirstParent.Union(FeatureIdsToBeMovedFromSecondParent).Distinct();

            // Which microserviceId we use here does not matter, since UpdateGenes will fix them to the correct one
            var newDeploymentGenes = featuresToBeMoved.Select(f => new DeploymentGene(f, firstMicroserviceId)).ToArray();

            return(firstParent.UpdateGenes(newDeploymentGenes));
        }
Example #5
0
 public IPopulation CreateInitialPopulation(IDeploymentChromosome initialDeployment, int minimalSize, int maximalSize)
 {
     return(new Population(Enumerable.Repeat(initialDeployment, minimalSize), minimalSize, maximalSize));
 }
Example #6
0
 public IDeploymentChromosome Mutate(IDeploymentChromosome deployment)
 {
     return(new DeploymentChromosome(deployment.FeatureModel, deployment.Genes.ToArray()));
 }