- Timestamp:
- 09/21/18 09:18:49 (6 years ago)
- Location:
- branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization/3.3
- Files:
-
- 7 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization/3.3/BasicProblems/BasicProblem.cs
r15583 r16171 30 30 namespace HeuristicLab.Optimization { 31 31 [StorableClass] 32 public abstract class BasicProblem<TEncoding, TEvaluator> : HeuristicOptimizationProblem<TEvaluator, ISolutionCreator>, I ProblemDefinition, IStorableContent32 public abstract class BasicProblem<TEncoding, TEvaluator> : HeuristicOptimizationProblem<TEvaluator, ISolutionCreator>, IBasicProblem 33 33 where TEncoding : class, IEncoding 34 34 where TEvaluator : class, IEvaluator { -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveBasicProblem.cs
r15583 r16171 31 31 namespace HeuristicLab.Optimization { 32 32 [StorableClass] 33 public abstract class MultiObjectiveBasicProblem<TEncoding> : BasicProblem<TEncoding, MultiObjectiveEvaluator>, IMultiObjective HeuristicOptimizationProblem, IMultiObjectiveProblemDefinition33 public abstract class MultiObjectiveBasicProblem<TEncoding> : BasicProblem<TEncoding, MultiObjectiveEvaluator>, IMultiObjectiveBasicProblem 34 34 where TEncoding : class, IEncoding { 35 36 #region Parameternames 37 public const string MaximizationParameterName = "Maximization"; 38 public const string BestKnownFrontParameterName = "BestKnownFront"; 39 public const string ReferencePointParameterName = "ReferencePoint"; 40 #endregion 41 42 #region Parameterproperties 43 public IValueParameter<BoolArray> MaximizationParameter { 44 get { return (IValueParameter<BoolArray>) Parameters[MaximizationParameterName]; } 45 } 46 public IValueParameter<DoubleMatrix> BestKnownFrontParameter { 47 get { return (IValueParameter<DoubleMatrix>)Parameters[BestKnownFrontParameterName]; } 48 } 49 public IValueParameter<DoubleArray> ReferencePointParameter { 50 get { return (IValueParameter<DoubleArray>)Parameters[ReferencePointParameterName]; } 51 } 52 #endregion 53 54 #region Properties 55 56 public abstract bool[] Maximization { get; } 57 58 public DoubleMatrix BestKnownFront { 59 get { return Parameters.ContainsKey(BestKnownFrontParameterName) ? BestKnownFrontParameter.Value : null; } 60 set { BestKnownFrontParameter.Value = value; } 61 } 62 public DoubleArray ReferencePoint { 63 get { return Parameters.ContainsKey(ReferencePointParameterName) ? ReferencePointParameter.Value : null; } 64 set { ReferencePointParameter.Value = value; } 65 } 66 #endregion 67 35 68 [StorableConstructor] 36 69 protected MultiObjectiveBasicProblem(bool deserializing) : base(deserializing) { } … … 43 76 protected MultiObjectiveBasicProblem() 44 77 : base() { 45 Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly())); 46 78 Parameters.Add(new ValueParameter<BoolArray>(MaximizationParameterName, "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly())); 79 Parameters.Add(new OptionalValueParameter<DoubleMatrix>(BestKnownFrontParameterName, "A double matrix representing the best known qualites for this problem (aka points on the Pareto front). Points are to be given in a row-wise fashion.")); 80 Parameters.Add(new OptionalValueParameter<DoubleArray>(ReferencePointParameterName, "The refrence point for hypervolume calculations on this problem")); 47 81 Operators.Add(Evaluator); 48 82 Operators.Add(new MultiObjectiveAnalyzer()); … … 56 90 } 57 91 58 public abstract bool[] Maximization { get; }92 59 93 public abstract double[] Evaluate(Individual individual, IRandom random); 60 94 public virtual void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) { } … … 96 130 } 97 131 98 99 132 #region IMultiObjectiveHeuristicOptimizationProblem Members 100 133 IParameter IMultiObjectiveHeuristicOptimizationProblem.MaximizationParameter { 101 get { return Parameters[ "Maximization"]; }134 get { return Parameters[MaximizationParameterName]; } 102 135 } 103 136 IMultiObjectiveEvaluator IMultiObjectiveHeuristicOptimizationProblem.Evaluator { -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveBasicProblem.cs
r15583 r16171 31 31 namespace HeuristicLab.Optimization { 32 32 [StorableClass] 33 public abstract class SingleObjectiveBasicProblem<TEncoding> : BasicProblem<TEncoding, SingleObjectiveEvaluator>, 34 ISingleObjectiveProblemDefinition, ISingleObjectiveHeuristicOptimizationProblem 33 public abstract class SingleObjectiveBasicProblem<TEncoding> : BasicProblem<TEncoding, SingleObjectiveEvaluator>, ISingleObjectiveBasicProblem 35 34 where TEncoding : class, IEncoding { 36 35 -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
r16123 r16171 41 41 <DebugType>full</DebugType> 42 42 <Optimize>false</Optimize> 43 <OutputPath> $(SolutionDir)\bin\</OutputPath>43 <OutputPath>..\..\..\..\trunk\bin\</OutputPath> 44 44 <DefineConstants>DEBUG;TRACE</DefineConstants> 45 45 <ErrorReport>prompt</ErrorReport> … … 105 105 </PropertyGroup> 106 106 <ItemGroup> 107 <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 108 <SpecificVersion>False</SpecificVersion> 109 <HintPath>..\..\..\..\trunk\bin\ALGLIB-3.7.0.dll</HintPath> 110 </Reference> 111 <Reference Include="HeuristicLab.ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 112 <SpecificVersion>False</SpecificVersion> 113 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.ALGLIB-3.7.0.dll</HintPath> 114 </Reference> 107 115 <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 108 116 <SpecificVersion>False</SpecificVersion> … … 120 128 <SpecificVersion>False</SpecificVersion> 121 129 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Core-3.3.dll</HintPath> 122 </Reference>123 <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">124 <SpecificVersion>False</SpecificVersion>125 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Data-3.3.dll</HintPath>126 130 </Reference> 127 131 <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> … … 162 166 <Compile Include="BasicProblems\Individuals\MultiEncodingIndividual.cs" /> 163 167 <Compile Include="BasicProblems\Individuals\SingleEncodingIndividual.cs" /> 168 <Compile Include="BasicProblems\Interfaces\IBasicProblem.cs" /> 164 169 <Compile Include="BasicProblems\Interfaces\IEncoding.cs" /> 165 170 <Compile Include="BasicProblems\Interfaces\IEncodingOperator.cs" /> 166 171 <Compile Include="BasicProblems\Interfaces\IMultiEncodingOperator.cs" /> 172 <Compile Include="BasicProblems\Interfaces\IMultiObjectiveBasicProblem.cs" /> 167 173 <Compile Include="BasicProblems\Interfaces\IMultiObjectiveProblemDefinition.cs" /> 168 174 <Compile Include="BasicProblems\Interfaces\internal\IMultiObjectiveAnalysisOperator.cs" /> … … 172 178 <Compile Include="BasicProblems\Interfaces\internal\ISingleObjectiveEvaluationOperator.cs" /> 173 179 <Compile Include="BasicProblems\Interfaces\IProblemDefinition.cs" /> 180 <Compile Include="BasicProblems\Interfaces\ISingleObjectiveBasicProblem.cs" /> 174 181 <Compile Include="BasicProblems\Interfaces\ISingleObjectiveMoveOperator.cs" /> 175 182 <Compile Include="BasicProblems\Interfaces\ISingleObjectiveProblemDefinition.cs" /> … … 192 199 <Compile Include="Interfaces\ILocalImprovementAlgorithmOperator.cs" /> 193 200 <Compile Include="Interfaces\IMultiObjectiveOperator.cs" /> 201 <Compile Include="MultiObjective\CrowdingCalculator.cs" /> 194 202 <Compile Include="MultiObjective\DominationCalculator.cs" /> 203 <Compile Include="MultiObjective\GenerationalDistanceCalculator.cs" /> 204 <Compile Include="MultiObjective\HypervolumeCalculator.cs" /> 205 <Compile Include="MultiObjective\SpacingCalculator.cs" /> 195 206 <Compile Include="Results\IResultParameter.cs" /> 196 207 <Compile Include="Interfaces\ISingleObjectiveOperator.cs" /> … … 319 330 </BootstrapperPackage> 320 331 </ItemGroup> 321 <ItemGroup /> 332 <ItemGroup> 333 <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj"> 334 <Project>{bbab9df5-5ef3-4ba8-ade9-b36e82114937}</Project> 335 <Name>HeuristicLab.Data-3.3</Name> 336 </ProjectReference> 337 </ItemGroup> 322 338 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 323 339 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Optimization/3.3/MultiObjective/DominationCalculator.cs
r15583 r16171 24 24 25 25 namespace HeuristicLab.Optimization { 26 26 27 public enum DominationResult { Dominates, IsDominated, IsNonDominated }; 27 28 28 public static class DominationCalculator <T>{29 public static class DominationCalculator { 29 30 /// <summary> 30 31 /// Calculates the best pareto front only. The fast non-dominated sorting algorithm is used … … 43 44 /// <param name="dominateOnEqualQualities">Whether solutions of exactly equal quality should dominate one another.</param> 44 45 /// <returns>The pareto front containing the best solutions and their associated quality resp. fitness.</returns> 45 public static List<Tuple<T, double[]>> CalculateBestParetoFront (T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities = true) {46 intpopulationSize = solutions.Length;46 public static List<Tuple<T, double[]>> CalculateBestParetoFront<T>(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities = true) { 47 var populationSize = solutions.Length; 47 48 48 49 Dictionary<T, List<int>> dominatedIndividuals; … … 69 70 /// <param name="dominateOnEqualQualities">Whether solutions of exactly equal quality should dominate one another.</param> 70 71 /// <returns>A sorted list of the pareto fronts from best to worst.</returns> 71 public static List<List<Tuple<T, double[]>>> CalculateAllParetoFronts (T[] solutions, double[][] qualities, bool[] maximization, out int[] rank, bool dominateOnEqualQualities = true) {72 intpopulationSize = solutions.Length;72 public static List<List<Tuple<T, double[]>>> CalculateAllParetoFronts<T>(T[] solutions, double[][] qualities, bool[] maximization, out int[] rank, bool dominateOnEqualQualities = true) { 73 var populationSize = solutions.Length; 73 74 74 75 Dictionary<T, List<int>> dominatedIndividuals; … … 76 77 var fronts = new List<List<Tuple<T, double[]>>>(); 77 78 fronts.Add(CalculateBestFront(solutions, qualities, maximization, dominateOnEqualQualities, populationSize, out dominatedIndividuals, out dominationCounter, out rank)); 78 inti = 0;79 var i = 0; 79 80 while (i < fronts.Count && fronts[i].Count > 0) { 80 81 var nextFront = new List<Tuple<T, double[]>>(); … … 82 83 List<int> dominatedIndividualsByp; 83 84 if (dominatedIndividuals.TryGetValue(p.Item1, out dominatedIndividualsByp)) { 84 for ( intk = 0; k < dominatedIndividualsByp.Count; k++) {85 intdominatedIndividual = dominatedIndividualsByp[k];85 for (var k = 0; k < dominatedIndividualsByp.Count; k++) { 86 var dominatedIndividual = dominatedIndividualsByp[k]; 86 87 dominationCounter[dominatedIndividual] -= 1; 87 88 if (dominationCounter[dominatedIndividual] == 0) { … … 98 99 } 99 100 100 private static List<Tuple<T, double[]>> CalculateBestFront (T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities, int populationSize, out Dictionary<T, List<int>> dominatedIndividuals, out int[] dominationCounter, out int[] rank) {101 private static List<Tuple<T, double[]>> CalculateBestFront<T>(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities, int populationSize, out Dictionary<T, List<int>> dominatedIndividuals, out int[] dominationCounter, out int[] rank) { 101 102 var front = new List<Tuple<T, double[]>>(); 102 103 dominatedIndividuals = new Dictionary<T, List<int>>(); 103 104 dominationCounter = new int[populationSize]; 104 105 rank = new int[populationSize]; 105 for ( intpI = 0; pI < populationSize - 1; pI++) {106 for (var pI = 0; pI < populationSize - 1; pI++) { 106 107 var p = solutions[pI]; 107 108 List<int> dominatedIndividualsByp; 108 109 if (!dominatedIndividuals.TryGetValue(p, out dominatedIndividualsByp)) 109 110 dominatedIndividuals[p] = dominatedIndividualsByp = new List<int>(); 110 for ( intqI = pI + 1; qI < populationSize; qI++) {111 for (var qI = pI + 1; qI < populationSize; qI++) { 111 112 var test = Dominates(qualities[pI], qualities[qI], maximization, dominateOnEqualQualities); 112 113 if (test == DominationResult.Dominates) { … … 147 148 if (dominateOnEqualQualities) { 148 149 var equal = true; 149 for ( inti = 0; i < left.Length; i++) {150 for (var i = 0; i < left.Length; i++) { 150 151 if (left[i] != right[i]) { 151 152 equal = false; … … 157 158 158 159 bool leftIsBetter = false, rightIsBetter = false; 159 for ( inti = 0; i < left.Length; i++) {160 for (var i = 0; i < left.Length; i++) { 160 161 if (IsDominated(left[i], right[i], maximizations[i])) rightIsBetter = true; 161 162 else if (IsDominated(right[i], left[i], maximizations[i])) leftIsBetter = true;
Note: See TracChangeset
for help on using the changeset viewer.