Exemplo n.º 1
0
        private List <Individual> CrossOverIndividuals(Individual mutatedMother, Individual mutatedFather)
        {
            // Descendants are created by randomly switching a randomly generated amount of hours
            // Only corresponding hours may be switched and only when both individuals have the same machines running
            Individual fatherClone = Individual.CloneRepresentation(mutatedFather);
            Individual motherClone = Individual.CloneRepresentation(mutatedMother);

            Random random = new Random();
            double chance = random.NextDouble();

            for (int i = 0; i < fatherClone.Schedule.Count; i++)
            {
                double value = random.NextDouble();
                if (value >= chance)
                {
                    if (IsCrossOverApplicable(fatherClone.Schedule[i], motherClone.Schedule[i]))
                    {
                        List <Machine> temp = fatherClone.Schedule[i];
                        fatherClone.Schedule[i] = motherClone.Schedule[i];
                        motherClone.Schedule[i] = temp;
                    }
                }
            }

            ReviseMachineStatus(fatherClone);
            ReviseMachineStatus(motherClone);
            List <Individual> descendants = new List <Individual>();

            if (StaticOperations.ValidateIndividual(motherClone) == false)
            {
                descendants.Add(mutatedMother);
            }
            else
            {
                descendants.Add(motherClone);
            }

            if (StaticOperations.ValidateIndividual(fatherClone) == false)
            {
                descendants.Add(mutatedFather);
            }
            else
            {
                descendants.Add(fatherClone);
            }

            return(descendants);
        }
Exemplo n.º 2
0
        public List <Individual> GenerateDescendants(Individual mother, Individual father)
        {
            Individual motherClone = Individual.CloneRepresentation(mother);
            Individual fatherClone = Individual.CloneRepresentation(father);

            Individual mutatedMother = MutateIndividual(motherClone);
            Individual mutatedFather = MutateIndividual(fatherClone);

            if (StaticOperations.ValidateIndividual(mutatedMother) == false)
            {
                mutatedMother = Individual.CloneRepresentation(mother);
            }

            if (StaticOperations.ValidateIndividual(mutatedFather) == false)
            {
                mutatedFather = Individual.CloneRepresentation(father);
            }

            List <Individual> descendants = CrossOverIndividuals(mutatedMother, mutatedFather);

            return(descendants);
        }
Exemplo n.º 3
0
        private Individual MutateIndividual(Individual individual)
        {
            Individual individualClone = Individual.CloneRepresentation(individual);
            // Every hour needs to be mutated separately
            // after mutating one of the hours, values for
            // turned on time on machines need to be revised
            // Revision is needed only if start/terminate operators are used
            Random random = new Random();

            for (int i = 0; i < individualClone.Schedule.Count; i++)
            {
                double mutationChange = random.NextDouble();
                if (mutationChange <= 0.25)
                {
                    int mutationEffect = random.Next(0, 3);

                    // Increase mutation
                    if (mutationEffect == 0)
                    {
                        individualClone.Schedule[i] = IncreaseMutation(individualClone.Schedule[i],
                                                                       i == 0 ? null : individualClone.Schedule[i - 1], random);
                        if (StaticOperations.ValidateIndividual(individualClone) == false)
                        {
                            individualClone.Schedule[i] = StaticOperations.CloneMachineList(individual.Schedule[i]);
                        }
                    }
                    // Decrease mutation
                    if (mutationEffect == 1)
                    {
                        individualClone.Schedule[i] = DecreaseMutation(individualClone.Schedule[i],
                                                                       i == 0 ? null : individualClone.Schedule[i - 1], random);
                        if (StaticOperations.ValidateIndividual(individualClone) == false)
                        {
                            individualClone.Schedule[i] = StaticOperations.CloneMachineList(individual.Schedule[i]);
                        }
                    }
                    // Start mutation
                    if (mutationEffect == 2)
                    {
                        individualClone.Schedule[i] = StartMutation(individualClone.Schedule[i],
                                                                    i == 0 ? null : individualClone.Schedule[i - 1], random);
                        if (StaticOperations.ValidateIndividual(individualClone) == false)
                        {
                            individualClone.Schedule[i] = StaticOperations.CloneMachineList(individual.Schedule[i]);
                        }

                        ReviseMachineStatus(individualClone);
                    }
                    // Terminate mutation
                    if (mutationEffect == 3)
                    {
                        individualClone.Schedule[i] = TerminateMutation(individualClone.Schedule[i],
                                                                        i == 0 ? null : individualClone.Schedule[i - 1], random);
                        if (StaticOperations.ValidateIndividual(individualClone) == false)
                        {
                            individualClone.Schedule[i] = StaticOperations.CloneMachineList(individual.Schedule[i]);
                        }

                        ReviseMachineStatus(individualClone);
                    }
                }
            }

            return(individualClone);
        }