Changeset 17657 for branches/2825-NSGA3
- Timestamp:
- 07/07/20 21:51:44 (4 years ago)
- Location:
- branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/HeuristicLab.Algorithms.NSGA3-3.3.csproj
r17558 r17657 69 69 <Private>False</Private> 70 70 </Reference> 71 <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec" /> 71 72 <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 72 73 <SpecificVersion>False</SpecificVersion> … … 112 113 <Compile Include="Properties\AssemblyInfo.cs" /> 113 114 <Compile Include="ReferencePoint.cs" /> 115 <Compile Include="SimulatedBinaryCrossover.cs" /> 114 116 <Compile Include="Solution.cs" /> 115 117 <Compile Include="Utility.cs" /> -
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 -
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/Plugin.cs
r17557 r17657 17 17 [PluginDependency("HeuristicLab.Encodings.BinaryVectorEncoding", "3.3")] 18 18 [PluginDependency("HeuristicLab.Encodings.RealVectorEncoding", "3.3")] 19 [PluginDependency("HeuristicLab.Operators", "3.3")] 19 20 [PluginDependency("HeuristicLab.Optimization", "3.3")] 20 21 [PluginDependency("HeuristicLab.Parameters", "3.3")] -
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/Solution.cs
r17618 r17657 3 3 using HeuristicLab.Common; 4 4 using HeuristicLab.Encodings.RealVectorEncoding; 5 using HeuristicLab.Optimization;6 5 7 6 namespace HeuristicLab.Algorithms.NSGA3 8 7 { 9 8 [StorableType("D35C9D79-77DF-4CF3-AB44-FCCC00E44C5F")] 10 public class Solution : I ndividual, IDeepCloneable9 public class Solution : IDeepCloneable 11 10 { 12 11 // Chromosome … … 16 15 public double[] Fitness { get; set; } 17 16 18 public Solution( StorableConstructorFlag _) : base(_)17 public Solution(RealVector chromosome) 19 18 { 19 Chromosome = chromosome; 20 } 21 22 public Solution(Solution solution, Cloner cloner) 23 { 24 Chromosome = cloner.Clone(solution.Chromosome); 25 Fitness = new double[solution.Fitness.Length]; 26 Array.Copy(solution.Fitness, Fitness, solution.Fitness.Length); 20 27 } 21 28 22 29 public IDeepCloneable Clone(Cloner cloner) 23 30 { 24 throw new NotImplementedException();31 return new Solution(this, cloner); 25 32 } 26 33 27 34 public object Clone() 28 35 { 29 throw new NotImplementedException(); 30 } 31 32 public override TEncoding GetEncoding<TEncoding>() 33 { 34 throw new NotImplementedException(); 35 } 36 37 public override Individual Copy() 38 { 39 throw new NotImplementedException(); 36 return new Cloner().Clone(this); 40 37 } 41 38 }
Note: See TracChangeset
for help on using the changeset viewer.