- Timestamp:
- 07/07/20 21:51:44 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/NSGA3.cs
r17619 r17657 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Diagnostics; 3 4 using System.Linq; 4 5 using System.Threading; … … 64 65 private const string SetSeedRandomlyName = "SetSeedRandomly"; 65 66 private const string PopulationSizeName = "PopulationSize"; 66 private const string CrossoverProbabilityName = "CrossOverProbability"; 67 private const string CrossoverProbabilityName = "CrossoverProbability"; 68 private const string CrossoverContiguityName = "CrossoverContiguity"; 67 69 private const string MutationProbabilityName = "MutationProbability"; 68 70 private const string MaximumGenerationsName = "MaximumGenerations"; … … 98 100 } 99 101 102 private IFixedValueParameter<DoubleValue> CrossoverContiguityParameter 103 { 104 get { return (IFixedValueParameter<DoubleValue>)Parameters[CrossoverContiguityName]; } 105 } 106 100 107 private IFixedValueParameter<PercentValue> MutationProbabilityParameter 101 108 { … … 124 131 125 132 public PercentValue CrossoverProbability => CrossoverProbabilityParameter.Value; 133 134 public DoubleValue CrossoverContiguity => CrossoverContiguityParameter.Value; 126 135 127 136 public PercentValue MutationProbability => MutationProbabilityParameter.Value; … … 159 168 Parameters.Add(new FixedValueParameter<IntValue>(SeedName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 160 169 Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 161 Parameters.Add(new FixedValueParameter<IntValue>(PopulationSizeName, "The size of the population of Individuals.", new IntValue( 100)));170 Parameters.Add(new FixedValueParameter<IntValue>(PopulationSizeName, "The size of the population of Individuals.", new IntValue(200))); 162 171 Parameters.Add(new FixedValueParameter<PercentValue>(CrossoverProbabilityName, "The probability that the crossover operator is applied on two parents.", new PercentValue(0.9))); 172 Parameters.Add(new FixedValueParameter<DoubleValue>(CrossoverContiguityName, "The contiguity value for the Simulated Binary Crossover that specifies how close a child should be to its parents (larger value means closer). The value must be greater than or equal than 0. Typical values are in the range [2;5].")); 163 173 Parameters.Add(new FixedValueParameter<PercentValue>(MutationProbabilityName, "The probability that the mutation operator is applied on a Individual.", new PercentValue(0.05))); 164 174 Parameters.Add(new FixedValueParameter<IntValue>(MaximumGenerationsName, "The maximum number of generations which should be processed.", new IntValue(1000))); … … 195 205 196 206 InitFields(); 207 InitResults(); 197 208 InitReferencePoints(); 198 InitResults();199 209 Analyze(); 200 210 } … … 218 228 RealVector randomRealVector = new RealVector(Problem.Encoding.Length, random, minBound, maxBound); 219 229 220 solutions.Add(new Solution(StorableConstructorFlag.Default) 221 { 222 Chromosome = randomRealVector 223 }); 230 solutions.Add(new Solution(randomRealVector)); 224 231 solutions[i].Fitness = Evaluate(solutions[i].Chromosome); 225 232 } … … 236 243 private void InitResults() 237 244 { 238 Results.Add(new Result(GeneratedReferencePointsResultName, "The initially generated reference points", Utility.ConvertToDoubleMatrix(ReferencePoints)));245 Results.Add(new Result(GeneratedReferencePointsResultName, "The initially generated reference points", new DoubleMatrix())); 239 246 Results.Add(new Result(CurrentFrontResultName, "The Pareto Front", new DoubleMatrix())); 240 247 } … … 288 295 289 296 // Do non-dominated sort 290 var qualities = Utility.ToFitnessMatrix( solutions);297 var qualities = Utility.ToFitnessMatrix(rt); 291 298 // compute the pareto fronts using the DominationCalculator and discard the qualities 292 299 // part in the inner tuples … … 578 585 private List<Solution> Recombine(List<Solution> solutions) 579 586 { 580 throw new NotImplementedException(); 587 List<Solution> childSolutions = new List<Solution>(); 588 589 for (int i = 0; i < solutions.Count; i += 2) 590 { 591 int parentIndex1 = random.Next(solutions.Count); 592 int parentIndex2 = random.Next(solutions.Count); 593 // ensure that the parents are not the same object 594 if (parentIndex1 == parentIndex2) parentIndex2 = (parentIndex2 + 1) % solutions.Count; 595 var parent1 = solutions[parentIndex1]; 596 var parent2 = solutions[parentIndex2]; 597 598 // Do crossover with crossoverProbabilty == 1 in order to guarantee that a crossover happens 599 var children = SimulatedBinaryCrossover.Apply(random, Problem.Encoding.Bounds, parent1.Chromosome, parent2.Chromosome, 1); 600 Debug.Assert(children != null); 601 602 var child1 = new Solution(children.Item1); 603 var child2 = new Solution(children.Item2); 604 child1.Fitness = Evaluate(child1.Chromosome); 605 child2.Fitness = Evaluate(child1.Chromosome); 606 607 childSolutions.Add(child1); 608 childSolutions.Add(child2); 609 } 610 611 return childSolutions; 581 612 } 582 613 583 614 private List<Solution> Mutate(List<Solution> solutions) 584 615 { 585 throw new NotImplementedException(); 616 foreach (var solution in solutions) 617 { 618 UniformOnePositionManipulator.Apply(random, solution.Chromosome, Problem.Encoding.Bounds); 619 } 620 return solutions; 586 621 } 587 622
Note: See TracChangeset
for help on using the changeset viewer.