public override void CiclicCrossover(IndividualBase parent1, IndividualBase parent2, out IndividualBase child1, out IndividualBase child2) { int[] L1 = (int[])(parent1 as CryptArithmeticSolution).LettersValues.Clone(); int[] L2 = (int[])(parent2 as CryptArithmeticSolution).LettersValues.Clone(); List<int> positionsToShare = new List<int>(); int amountOfChars = charArray.Count(); int itemIdx = Aleatoriety.GetRandomInt(amountOfChars); int tempValue; while (!positionsToShare.Contains(itemIdx)) { positionsToShare.Add(itemIdx); tempValue = L1[itemIdx]; itemIdx = Array.IndexOf(L2, tempValue); } int tempVal; foreach (int position in positionsToShare) { tempVal = L2[position]; L2[position] = L1[position]; L1[position] = tempVal; } child1 = new CryptArithmeticSolution(this, L1); child2 = new CryptArithmeticSolution(this, L2); }
// TODO: Testing public override void ValidateIndividual(IndividualBase individual) { TaskSchedulingSolution schedulingSolution = (individual as TaskSchedulingSolution); List <List <TaskIndexingNode> > TasksGroupedByProcessor = GroupTasksByProcessor(schedulingSolution); for (int processorIdx = 0; processorIdx < ProcessorCount; ++processorIdx) { List <TaskIndexingNode> TasksInProcessor = TasksGroupedByProcessor[processorIdx]; for (int probableDependantIdx = 0; probableDependantIdx < TasksInProcessor.Count; ++probableDependantIdx) { int probableDependantTask = TasksInProcessor[probableDependantIdx].Task; for (int probableDependencyIdx = probableDependantIdx + 1; probableDependencyIdx < TasksInProcessor.Count; ++probableDependencyIdx) { int probableDependencyTask = TasksInProcessor[probableDependencyIdx].Task; if (CommGraph.DependsOn(probableDependantTask, probableDependencyTask)) { schedulingSolution.SwapGenesAt(TasksInProcessor[probableDependantIdx].Index, TasksInProcessor[probableDependencyIdx].Index); TasksInProcessor.Swap(probableDependantIdx, probableDependencyIdx); int Temp = TasksInProcessor[probableDependantIdx].Index; TasksInProcessor[probableDependantIdx].Index = TasksInProcessor[probableDependencyIdx].Index; TasksInProcessor[probableDependencyIdx].Index = Temp; probableDependantIdx = -1; break; } } } } }
public override void EvaluateIndividual(IndividualBase individual) { CryptArithmeticSolution cryptoSolution = (individual as CryptArithmeticSolution); long termsSum = 0; int charValue = -1; foreach (string term in terms) { long termCharSum = 0; long decimalBaseValTerm = 1; foreach (char c in term.ToCharArray().Reverse()) { charValue = cryptoSolution.LettersValues[Array.IndexOf(charArray, c)]; termCharSum += (charValue * decimalBaseValTerm); decimalBaseValTerm *= 10; } termsSum += termCharSum; } long resultCharSum = 0; long decimalBaseValResult = 1; foreach (char c in result.ToCharArray().Reverse()) { charValue = cryptoSolution.LettersValues[Array.IndexOf(charArray, c)]; resultCharSum += (charValue * decimalBaseValResult); decimalBaseValResult *= 10; } long resultValue = resultCharSum; cryptoSolution.DifferenceInExpectedResult = (int)Math.Abs(resultValue - termsSum); individual = cryptoSolution; }
private IndividualBase BestByCrowdedComparison(IndividualBase individual1, IndividualBase individual2) { if (individual1.NonDominationRank < individual2.NonDominationRank) { return(individual1); } if (individual2.NonDominationRank < individual1.NonDominationRank) { return(individual2); } // Se Estão no Mesmo Ranking de Não-Dominância if (individual1.CrowdingDistance > individual2.CrowdingDistance) { return(individual1); } if (individual2.CrowdingDistance > individual1.CrowdingDistance) { return(individual2); } // Se têm a Mesma CrowdingDistance if (Aleatoriety.GetRandomInt(2) == 0) { return(individual1); } else { return(individual2); } }
public override void CiclicCrossover(IndividualBase parent1, IndividualBase parent2, out IndividualBase child1, out IndividualBase child2) { int[] L1 = (int[])(parent1 as CryptArithmeticSolution).LettersValues.Clone(); int[] L2 = (int[])(parent2 as CryptArithmeticSolution).LettersValues.Clone(); List <int> positionsToShare = new List <int>(); int amountOfChars = charArray.Count(); int itemIdx = Aleatoriety.GetRandomInt(amountOfChars); int tempValue; while (!positionsToShare.Contains(itemIdx)) { positionsToShare.Add(itemIdx); tempValue = L1[itemIdx]; itemIdx = Array.IndexOf(L2, tempValue); } int tempVal; foreach (int position in positionsToShare) { tempVal = L2[position]; L2[position] = L1[position]; L1[position] = tempVal; } child1 = new CryptArithmeticSolution(this, L1); child2 = new CryptArithmeticSolution(this, L2); }
//CONFERIR public int finalFitnessComparison(IndividualBase i1, IndividualBase i2) { return(i1.FinalFitness < i2.FinalFitness ? // se i1 for menor 1 : //retorna 1 (i1) i2.FinalFitness < i1.FinalFitness ? //se i2 for menor -1 : //retorna -1 (i2) 0); //se for igual, retorna 0 }
public void RandomInitialize() { // Generate Initial Population for (int idx = 0; idx < this.InitialPopulationSize; ++idx) { IndividualBase individual = problem.CreateRandomSolution(); IndividualEvaluator.Execute(individual, problem); AddIndividual(individual); } }
public IndividualBase Execute(int numberOfExecutions, out string convergenceReport) { int bestResultCount; IndividualBase bestSolutionFound = Execute(numberOfExecutions, out bestResultCount); int bestSolutionOccurencePercentage = (bestResultCount * 100 / numberOfExecutions); convergenceReport = "A melhor solução encontrada foi de valor: " + bestSolutionFound.GetValueForObjective(Problem.MonoObjectiveGoal) + ", tendo ocorrido: " + bestSolutionOccurencePercentage + "% das execuções."; return(bestSolutionFound); }
private double DistanceBetween(IndividualBase i1, IndividualBase i2) { double distance = 0; foreach (Objective objective in i1.Problem.MultiObjectiveGoal) { double difference = i1.GetNormalizedValueForObjective(objective) - i2.GetNormalizedValueForObjective(objective); //calcular a distancia parcial como sendo a diferença distance += Math.Pow(difference, 2); } return(distance); }
private IndividualBase BinaryTournment(Population_MultiObjective_AG population) { IndividualBase[] contestants = new IndividualBase[2]; contestants[0] = population.GetRandomIndividual(); do { contestants[1] = population.GetRandomIndividual(); } while (contestants[0] == contestants[1]); return(BestByCrowdedComparison(contestants[0], contestants[1])); }
public override void MutateIndividual(IndividualBase individual) { TaskSchedulingSolution schedulingSolution = (individual as TaskSchedulingSolution); int indexA = Aleatoriety.GetRandomInt(TaskCount); int indexB; do { indexB = Aleatoriety.GetRandomInt(TaskCount); } while (indexB == indexA); schedulingSolution.SwapGenesAt(indexA, indexB); schedulingSolution.SwapProcessorAt(indexA); }
public static int CrowdedComparison(IndividualBase i1, IndividualBase i2) { int partial = i1.NonDominationRank < i2.NonDominationRank ? // se i1 for de um front menor 1 : //retorna 1 (i1) i2.NonDominationRank < i1.NonDominationRank ? //se i2 for de um front menor -1 : //retorna -1 (i2) 0; //se for igual, retorna a comparação entre as distâncias if (!partial.Equals(0)) { return(partial); } return(i1.CrowdingDistance.CompareTo(i2.CrowdingDistance)); }
public override void PMXCrossover(IndividualBase parent1, IndividualBase parent2, out IndividualBase child1, out IndividualBase child2) { int[,] parent1Scheduling = (parent1 as TaskSchedulingSolution).GeneticMaterial; int[,] parent2Scheduling = (parent2 as TaskSchedulingSolution).GeneticMaterial; int startIdxInclusive = Aleatoriety.GetRandomInt(TaskCount - 1); int endIdxExclusive = Aleatoriety.GetRandomInt(startIdxInclusive + 1, TaskCount + 1); int[,] L1 = new int[2, TaskCount]; int[,] L2 = new int[2, TaskCount]; int L1idx; int L2idx; for (int idx = 0; idx < TaskCount; ++idx) { if ((idx < startIdxInclusive) || (idx >= endIdxExclusive)) { int L1CopyFromTask = parent1Scheduling[0, idx]; int L1CopyFromProcessor = parent1Scheduling[1, idx]; while ((L1idx = IndexOfTaskInInterval(L1CopyFromTask, startIdxInclusive, endIdxExclusive, parent2Scheduling)) != -1) { L1CopyFromTask = parent1Scheduling[0, L1idx]; L1CopyFromProcessor = parent1Scheduling[1, L1idx]; } L1[0, idx] = L1CopyFromTask; L1[1, idx] = L1CopyFromProcessor; int L2CopyFromTask = parent2Scheduling[0, idx]; int L2CopyFromProcessor = parent2Scheduling[1, idx]; while ((L2idx = IndexOfTaskInInterval(L2CopyFromTask, startIdxInclusive, endIdxExclusive, parent1Scheduling)) != -1) { L2CopyFromTask = parent2Scheduling[0, L2idx]; L2CopyFromProcessor = parent2Scheduling[1, L2idx]; } L2[0, idx] = L2CopyFromTask; L2[1, idx] = L2CopyFromProcessor; } else { L1[0, idx] = parent2Scheduling[0, idx]; L1[1, idx] = parent2Scheduling[1, idx]; L2[0, idx] = parent1Scheduling[0, idx]; L2[1, idx] = parent1Scheduling[1, idx]; } } child1 = new TaskSchedulingSolution(this, L1); child2 = new TaskSchedulingSolution(this, L2); }
public void RandomInitialize() { // Generate Initial Population while (IndividualCount < this.InitialPopulationSize) { IndividualBase individual = Problem.CreateRandomSolution(); Problem.ValidateIndividual(individual); IndividualEvaluator.Execute(individual, Problem); if (!Content.Contains(individual)) { AddIndividual(individual); } } }
public static void Execute(IndividualBase individual, ProblemBase problem) { problem.EvaluateIndividual(individual); if (!individual.WasEvaluated) { individual.ObjectivesValuesForMaximization.Add(double.MaxValue); individual.ObjectivesValuesForNormalization.Add(double.MaxValue); } Objective objective = problem.MonoObjectiveGoal; individual.SetFitnessForObjective(objective); individual.WasEvaluated = true; }
protected override void EvaluateObjectiveValues() { // Create Temporary Individuals List <IndividualBase> temporaryList = new List <IndividualBase>(); for (int iCount = 0; iCount < 200; ++iCount) { IndividualBase i = Problem.CreateRandomSolution(); IndividualEvaluator.Execute(i, Problem); temporaryList.Add(i); } double maxValueFound = temporaryList.Max(I => I.GetFitnessForObjective(Problem.MonoObjectiveGoal)); double adaptedMaxValue = Math.Abs(maxValueFound) * 2; Problem.MonoObjectiveGoal.BigValueForMaximization = adaptedMaxValue; }
public override string SerializeIndividual(IndividualBase individual) { StringBuilder SB = new StringBuilder(); SB.AppendLine("Individual:"); SB.AppendLine("\t" + "Value: " + individual.GetValueForObjective(MonoObjectiveGoal)); CryptArithmeticSolution cryptoSolution = (individual as CryptArithmeticSolution); int charValue = -1; for (int idx = 0; idx < charArray.Length; ++idx) { charValue = cryptoSolution.LettersValues[idx]; SB.AppendLine("\t" + charArray[idx] + ": " + charValue); } return(SB.ToString()); }
private Population_MultiObjective_AG Procreate(Population_MultiObjective_AG mating) { int expectedChildCount = InitialPopulationSize; Population_MultiObjective_AG newGeneration = new Population_MultiObjective_AG(Problem, expectedChildCount); while (newGeneration.IndividualCount < expectedChildCount) { // Selection Method IndividualBase parent1 = BinaryTournment(mating); IndividualBase parent2 = BinaryTournment(mating); IndividualBase child1 = null, child2 = null; // Crossover Method Problem.PMXCrossover(parent1, parent2, out child1, out child2); for (int i = 0; i < 10; ++i) { if (!newGeneration.Content.Contains(child1) || i == 9) { newGeneration.AddIndividual(child1); break; } } for (int i = 0; i < 10; ++i) { if (!newGeneration.Content.Contains(child2) || i == 9) { newGeneration.AddIndividual(child2); break; } } } foreach (IndividualBase individual in newGeneration.Content) { int aleatoryPercentage = Aleatoriety.GetRandomInt(100); if (aleatoryPercentage < mutationPct) { Problem.MutateIndividual(individual); } Problem.ValidateIndividual(individual); IndividualEvaluator.Execute(individual, Problem); } return(newGeneration); }
public override string NewSerializeIndividual(IndividualBase individual) { TaskSchedulingSolution schedulingSolution = (individual as TaskSchedulingSolution); List <List <TaskIndexingNode> > tasksGroupedByProcessor = GroupTasksByProcessor(schedulingSolution); StringBuilder sb = new StringBuilder(); sb.Append("MakeSpan: " + individual.GetValueForObjective(MultiObjectiveGoal.First()) + " _ "); sb.Append("Potencia: " + individual.GetValueForObjective(MultiObjectiveGoal.Last()) + " _ "); for (int idx = 0; idx < TaskCount - 1; ++idx) { sb.Append(" " + schedulingSolution.GeneticMaterial[0, idx] + " (" + schedulingSolution.GeneticMaterial[1, idx] + ") -"); } sb.Append(" " + schedulingSolution.GeneticMaterial[0, TaskCount - 1] + " (" + schedulingSolution.GeneticMaterial[1, TaskCount - 1] + ")"); return(sb.ToString()); }
public override void MutateIndividual(IndividualBase individual) { CryptArithmeticSolution cryptoSolution = (individual as CryptArithmeticSolution); int amountOfChars = charArray.Count(); int firstPositionIdx = Aleatoriety.GetRandomInt(amountOfChars); int secondPositionIdx; do { secondPositionIdx = Aleatoriety.GetRandomInt(amountOfChars); } while (secondPositionIdx == firstPositionIdx); int tempValue = cryptoSolution.LettersValues[secondPositionIdx]; cryptoSolution.LettersValues[secondPositionIdx] = cryptoSolution.LettersValues[firstPositionIdx]; cryptoSolution.LettersValues[firstPositionIdx] = tempValue; individual = cryptoSolution; }
public override void Execute(PopulationBase population, out IndividualBase chosenIndividual1, out IndividualBase chosenIndividual2) { IndividualBase[] selectedParents = new IndividualBase[2]; for (int individualIdx = 0; individualIdx < 2; ++individualIdx) { selectedParents[individualIdx] = population.GetRandomIndividual(); for (int selectionIdx = 1; selectionIdx < tourSize; ++selectionIdx) { IndividualBase randomIndividual = population.GetRandomIndividual(); if (randomIndividual.GetFitnessForObjective(Problem.MonoObjectiveGoal) > selectedParents[individualIdx].GetFitnessForObjective(Problem.MonoObjectiveGoal)) { selectedParents[individualIdx] = randomIndividual; } } } chosenIndividual1 = selectedParents[0]; chosenIndividual2 = selectedParents[1]; }
private IndividualBase BinaryTournment(Population_MultiObjective_AG population) { IndividualBase[] contestants = new IndividualBase[2]; contestants[0] = population.GetRandomIndividual(); for (int i = 0; i < 10; ++i) { contestants[1] = population.GetRandomIndividual(); if ((contestants[0] != contestants[1]) || i == 9) { break; } } //do { // contestants[1] = population.GetRandomIndividual(); //} while (contestants[0] == contestants[1]); return(finalFitnessComparison(contestants[0], contestants[1]) >= 0 ? contestants[0] : contestants[1]); }
public void Truncate(int archiveSize) { CalculateSortedDistances(); while (IndividualCount > archiveSize) { double smallestDistanceValue = double.MaxValue; int smallestDistanceIdx = 0; bool IsSmallestDistanceUniqueByIdx = true; for (int distanceIdx = 0; distanceIdx < Content.Count; ++distanceIdx) { IsSmallestDistanceUniqueByIdx = true; foreach (IndividualBase individual in Content) { double distanceForIdx = individual.DistancesToOtherIndividuals[distanceIdx].Item2; if (distanceForIdx < smallestDistanceValue) { IsSmallestDistanceUniqueByIdx = true; smallestDistanceIdx = distanceIdx; smallestDistanceValue = distanceForIdx; } else { IsSmallestDistanceUniqueByIdx = false; if (smallestDistanceValue == 0) { break; } } } if (IsSmallestDistanceUniqueByIdx) { break; } } IndividualBase individualForRemoval = Content[smallestDistanceIdx]; Content.Remove(individualForRemoval); foreach (IndividualBase i in Content) { i.DistancesToOtherIndividuals.RemoveAll(I => I.Item1 == individualForRemoval); } } }
public override string SerializeIndividual(IndividualBase individual) { TaskSchedulingSolution schedulingSolution = (individual as TaskSchedulingSolution); List <List <TaskIndexingNode> > tasksGroupedByProcessor = GroupTasksByProcessor(schedulingSolution); StringBuilder sb = new StringBuilder(); sb.AppendLine("Individual:"); sb.AppendLine("\t" + "Value: " + individual.GetValueForObjective(MonoObjectiveGoal)); for (int processorIdx = 0; processorIdx < ProcessorCount; ++processorIdx) { sb.Append("\t" + "P" + processorIdx + ": " + "["); foreach (int task in tasksGroupedByProcessor[processorIdx].Select(TIN => TIN.Task)) { sb.Append(" " + task + " |"); } sb.Append("| " + schedulingSolution.ProcessorStatus[processorIdx] + " ]"); sb.Append(Environment.NewLine); } return(sb.ToString()); }
private IndividualBase Execute(int numberOfExecutions, out int bestResultCount) { IndividualBase bestIndividual = Execute(); double bestCurrentValue = bestIndividual.GetFitnessForObjective(Problem.MonoObjectiveGoal); bestResultCount = 1; for (int executionCount = 1; executionCount < numberOfExecutions; ++executionCount) { IndividualBase currentIndividual = Execute(); double currentValue = currentIndividual.GetFitnessForObjective(Problem.MonoObjectiveGoal); if (currentValue > bestCurrentValue) { bestIndividual = currentIndividual; bestCurrentValue = currentValue; bestResultCount = 1; } else if (currentValue == bestCurrentValue) { ++bestResultCount; } } return(bestIndividual); }
private Population_MonoObjective_AG RunGeneration(Population_MonoObjective_AG currentGeneration, SelectionMethodBase selectionMethod, CrossoverMethodBase crossoverMethod, /*IReinsertionMethod reinsertionMethod, */ ReinsertionMethodBase reinsertionMethod) { Population_MonoObjective_AG recentlyBorn = new Population_MonoObjective_AG(Problem, InitialPopulationSize); int expectedChildCount = ((InitialPopulationSize * reinsertionMethod.OffspringPercentage) / 100); while (recentlyBorn.IndividualCount < expectedChildCount) { IndividualBase parent1 = null, parent2 = null, child1 = null, child2 = null; selectionMethod.Execute(currentGeneration, out parent1, out parent2); crossoverMethod.Execute(parent1, parent2, out child1, out child2); recentlyBorn.AddIndividual(child1); recentlyBorn.AddIndividual(child2); } int mutatedChildCount = ((recentlyBorn.IndividualCount * mutationPct) / 100); for (int idx = 0; idx < mutatedChildCount; ++idx) { IndividualBase randomIndividual = recentlyBorn.GetRandomIndividual(); Problem.MutateIndividual(randomIndividual); } IndividualBase individual = null; for (int idx = 0; idx < recentlyBorn.IndividualCount; ++idx) { individual = recentlyBorn.Content[idx]; Problem.ValidateIndividual(individual); IndividualEvaluator.Execute(individual, Problem); } Population_MonoObjective_AG newGeneration = reinsertionMethod.Execute(currentGeneration, recentlyBorn); return(newGeneration); }
public override void CiclicCrossover(IndividualBase parent1, IndividualBase parent2, out IndividualBase child1, out IndividualBase child2) { throw new NotImplementedException(); }
// TODO: Testing public override void ValidateIndividual(IndividualBase individual) { TaskSchedulingSolution schedulingSolution = (individual as TaskSchedulingSolution); List<List<TaskIndexingNode>> TasksGroupedByProcessor = GroupTasksByProcessor(schedulingSolution); for (int processorIdx = 0; processorIdx < ProcessorCount; ++processorIdx) { List<TaskIndexingNode> TasksInProcessor = TasksGroupedByProcessor[processorIdx]; for (int probableDependantIdx = 0; probableDependantIdx < TasksInProcessor.Count; ++probableDependantIdx) { int probableDependantTask = TasksInProcessor[probableDependantIdx].Task; for (int probableDependencyIdx = probableDependantIdx + 1; probableDependencyIdx < TasksInProcessor.Count; ++probableDependencyIdx) { int probableDependencyTask = TasksInProcessor[probableDependencyIdx].Task; if(CommGraph.DependsOn(probableDependantTask, probableDependencyTask)) { schedulingSolution.SwapGenesAt(TasksInProcessor[probableDependantIdx].Index, TasksInProcessor[probableDependencyIdx].Index); TasksInProcessor.Swap(probableDependantIdx, probableDependencyIdx); int Temp = TasksInProcessor[probableDependantIdx].Index; TasksInProcessor[probableDependantIdx].Index = TasksInProcessor[probableDependencyIdx].Index; TasksInProcessor[probableDependencyIdx].Index = Temp; probableDependantIdx = -1; break; } } } } }
public override string SerializeIndividual(IndividualBase individual) { TaskSchedulingSolution schedulingSolution = (individual as TaskSchedulingSolution); List<List<TaskIndexingNode>> tasksGroupedByProcessor = GroupTasksByProcessor(schedulingSolution); StringBuilder sb = new StringBuilder(); sb.AppendLine("Individual:"); sb.AppendLine("\t" + "Value: " + individual.GetValueForObjective(MonoObjectiveGoal)); for (int processorIdx = 0; processorIdx < ProcessorCount; ++processorIdx) { sb.Append("\t" + "P" + processorIdx + ": " + "["); foreach (int task in tasksGroupedByProcessor[processorIdx].Select(TIN => TIN.Task)) { sb.Append(" " + task + " |"); } sb.Append("| " + schedulingSolution.ProcessorStatus[processorIdx] + " ]"); sb.Append(Environment.NewLine); } return sb.ToString(); }
public override string NewSerializeIndividual(IndividualBase individual) { TaskSchedulingSolution schedulingSolution = (individual as TaskSchedulingSolution); List<List<TaskIndexingNode>> tasksGroupedByProcessor = GroupTasksByProcessor(schedulingSolution); StringBuilder sb = new StringBuilder(); sb.Append("MakeSpan: " + individual.GetValueForObjective(MultiObjectiveGoal.First()) + " _ "); sb.Append("Potencia: " + individual.GetValueForObjective(MultiObjectiveGoal.Last()) + " _ "); for (int idx = 0; idx < TaskCount - 1; ++idx) sb.Append(" " + schedulingSolution.GeneticMaterial[0, idx] + " (" + schedulingSolution.GeneticMaterial[1, idx] + ") -"); sb.Append(" " + schedulingSolution.GeneticMaterial[0, TaskCount - 1] + " (" + schedulingSolution.GeneticMaterial[1, TaskCount - 1] + ")"); return sb.ToString(); }
public override void EvaluateIndividual(IndividualBase individual) { REDO: TaskSchedulingSolution schedulingSolution = individual as TaskSchedulingSolution; schedulingSolution.SpentPower = 0; double pCommunication = 0; int pTask = 0; bool[] scheduledTasks = new bool[TaskCount]; int remainingTasks = TaskCount; int[] processorsSchedullingTimeForTask = new int[TaskCount]; schedulingSolution.ProcessorStatus = new int[ProcessorCount]; int currentAllocationCost; List<List<TaskIndexingNode>> tasksGroupedByProcessor = GroupTasksByProcessor(schedulingSolution); bool deadLockOcurred; do { for (int currentProcessor = 0; currentProcessor < ProcessorCount; ++currentProcessor) { if (tasksGroupedByProcessor[currentProcessor].Count != 0) { int nextTaskForProcessor = tasksGroupedByProcessor[currentProcessor][0].Task; IEnumerable<int> notScheduledTaskDependencies = CommGraph.GetDirectDependencies(nextTaskForProcessor).Where(Dep => scheduledTasks[Dep] == false); bool readyForScheduling = (notScheduledTaskDependencies.Count() == 0); if (readyForScheduling) { int currentTask = nextTaskForProcessor; currentAllocationCost = schedulingSolution.ProcessorStatus[currentProcessor]; foreach (int dependencyTask in CommGraph.GetDirectDependencies(currentTask)) { int idx = 0; while (schedulingSolution.GeneticMaterial[0, idx] != dependencyTask) ++idx; int dependencyProcessor = schedulingSolution.GeneticMaterial[1, idx]; if (dependencyProcessor != currentProcessor) { pCommunication += Math.Pow(CommGraph.GetCommunicationCost(dependencyTask, currentTask), 2); int dependencyCost = processorsSchedullingTimeForTask[dependencyTask] + CommGraph.GetCommunicationCost(dependencyTask, currentTask); if (dependencyCost > currentAllocationCost) currentAllocationCost = dependencyCost; } } currentAllocationCost += CommGraph.GetEdgeCost(currentTask); schedulingSolution.ProcessorStatus[currentProcessor] = currentAllocationCost; processorsSchedullingTimeForTask[currentTask] = currentAllocationCost; pTask += CommGraph.GetEdgeCost(currentTask); scheduledTasks[currentTask] = true; tasksGroupedByProcessor[currentProcessor].RemoveAt(0); remainingTasks--; currentProcessor = -1; } } } if (remainingTasks != 0) { deadLockOcurred = true; // Tratamento de DeadLock int chosenSourceProcessor; do { chosenSourceProcessor = Aleatoriety.GetRandomInt(ProcessorCount); } while (tasksGroupedByProcessor[chosenSourceProcessor].Count == 0); int chosenDestProcessor; do { chosenDestProcessor = Aleatoriety.GetRandomInt(ProcessorCount); } while (chosenSourceProcessor == chosenDestProcessor); int taskToBeTransfered = tasksGroupedByProcessor[chosenSourceProcessor].First().Task; int idx = 0; while (schedulingSolution.GeneticMaterial[0, idx] != taskToBeTransfered) ++idx; schedulingSolution.GeneticMaterial[1, idx] = chosenDestProcessor; ValidateIndividual(schedulingSolution); goto REDO; } else deadLockOcurred = false; } while (deadLockOcurred); // Houve DeadLock schedulingSolution.MakeSpan = schedulingSolution.ProcessorStatus.Max(); schedulingSolution.SpentPower = (pTask * k1) + (pCommunication * k2); }
public override void Execute(PopulationBase population, out IndividualBase chosenIndividual1, out IndividualBase chosenIndividual2) { throw new NotImplementedException(); }
public override string SerializeIndividual(IndividualBase individual) { StringBuilder SB = new StringBuilder(); SB.AppendLine("Individual:"); SB.AppendLine("\t" + "Value: " + individual.GetValueForObjective(MonoObjectiveGoal)); CryptArithmeticSolution cryptoSolution = (individual as CryptArithmeticSolution); int charValue = -1; for (int idx = 0; idx < charArray.Length; ++idx) { charValue = cryptoSolution.LettersValues[idx]; SB.AppendLine("\t" + charArray[idx] + ": " + charValue); } return SB.ToString(); }
public override void ValidateIndividual(IndividualBase individual) { }
public override void Execute(IndividualBase parent1, IndividualBase parent2, out IndividualBase child1, out IndividualBase child2) { Problem.CiclicCrossover(parent1, parent2, out child1, out child2); }
public abstract void Execute(IndividualBase parent1, IndividualBase parent2, out IndividualBase child1, out IndividualBase child2);
public abstract void Execute(PopulationBase population, out IndividualBase chosenIndividual1, out IndividualBase chosenIndividual2);