Changeset 16630 for branches/2987_MOEAD_Algorithm
- Timestamp:
- 02/28/19 14:23:36 (6 years ago)
- Location:
- branches/2987_MOEAD_Algorithm/HeuristicLab.Algorithms.MOEAD/3.4
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2987_MOEAD_Algorithm/HeuristicLab.Algorithms.MOEAD/3.4/HeuristicLab.Algorithms.MOEAD-3.4.csproj
r16560 r16630 1 1 <?xml version="1.0" encoding="utf-8"?> 2 <Project ToolsVersion=" 4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">2 <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 3 <PropertyGroup> 4 4 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> … … 11 11 <RootNamespace>HeuristicLab.Algorithms.MOEAD</RootNamespace> 12 12 <AssemblyName>HeuristicLab.Algorithms.MOEAD-3.4</AssemblyName> 13 <TargetFrameworkVersion>v4. 5</TargetFrameworkVersion>13 <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> 14 14 <FileAlignment>512</FileAlignment> 15 15 <SignAssembly>true</SignAssembly> … … 98 98 </PropertyGroup> 99 99 <ItemGroup> 100 <Reference Include="Google.Protobuf, Version=3.6.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL"> 101 <HintPath>..\..\packages\Google.Protobuf.3.6.1\lib\net45\Google.Protobuf.dll</HintPath> 102 </Reference> 103 <Reference Include="HEAL.Attic, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 104 <HintPath>..\..\packages\HEAL.Attic.1.0.0-pre03\lib\net461\HEAL.Attic.dll</HintPath> 105 </Reference> 100 106 <Reference Include="HeuristicLab.Analysis-3.3"> 101 107 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Analysis-3.3.dll</HintPath> … … 139 145 <Private>False</Private> 140 146 </Reference> 147 <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 148 <SpecificVersion>False</SpecificVersion> 149 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath> 150 <Private>False</Private> 151 </Reference> 152 <Reference Include="HeuristicLab.Problems.TestFunctions.MultiObjective-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 153 <SpecificVersion>False</SpecificVersion> 154 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Problems.TestFunctions.MultiObjective-3.3.dll</HintPath> 155 <Private>False</Private> 156 </Reference> 141 157 <Reference Include="HeuristicLab.Random-3.3"> 142 158 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Random-3.3.dll</HintPath> … … 148 164 </Reference> 149 165 <Reference Include="System.Data" /> 166 <Reference Include="System.Drawing" /> 167 <Reference Include="System.Drawing.Common, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> 168 <HintPath>..\..\packages\System.Drawing.Common.4.6.0-preview.19073.11\lib\net461\System.Drawing.Common.dll</HintPath> 169 </Reference> 150 170 <Reference Include="System.Xml" /> 151 171 </ItemGroup> 152 172 <ItemGroup> 153 173 <None Include="HeuristicLab.snk" /> 174 <None Include="packages.config" /> 154 175 <None Include="Plugin.cs.frame" /> 155 176 <Compile Include="MOEADAlgorithm.cs" /> -
branches/2987_MOEAD_Algorithm/HeuristicLab.Algorithms.MOEAD/3.4/MOEADAlgorithm.cs
r16583 r16630 1 using HeuristicLab.Common; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using HEAL.Attic; 23 using HeuristicLab.Common; 2 24 using HeuristicLab.Core; 3 25 using HeuristicLab.Data; 4 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;5 26 using HeuristicLab.Random; 6 27 using System.Linq; … … 9 30 namespace HeuristicLab.Algorithms.MOEAD { 10 31 [Item("Multi-objective Evolutionary Algorithm based on Decomposition (MOEA/D)", "MOEA/D implementation adapted from jMetal.")] 11 [StorableClass]12 32 [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 125)] 33 [StorableType("FE39AD23-B3BF-4368-BB79-FE5BF4C36272")] 13 34 public class MOEADAlgorithm : MOEADAlgorithmBase { 14 35 public MOEADAlgorithm() { } … … 21 42 22 43 [StorableConstructor] 23 protected MOEADAlgorithm( booldeserializing) : base(deserializing) { }44 protected MOEADAlgorithm(StorableConstructorFlag deserializing) : base(deserializing) { } 24 45 25 46 protected override void Run(CancellationToken cancellationToken) { … … 98 119 99 120 UpdateParetoFronts(); 121 122 Results.AddOrUpdateResult("IdealPoint", new DoubleArray(IdealPoint)); 123 Results.AddOrUpdateResult("NadirPoint", new DoubleArray(NadirPoint)); 100 124 Results.AddOrUpdateResult("Evaluated Solutions", new IntValue(evaluatedSolutions)); 101 125 -
branches/2987_MOEAD_Algorithm/HeuristicLab.Algorithms.MOEAD/3.4/MOEADAlgorithmBase.cs
r16583 r16630 1 using HeuristicLab.Analysis; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using HEAL.Attic; 23 using HeuristicLab.Analysis; 2 24 using HeuristicLab.Common; 3 25 using HeuristicLab.Core; … … 6 28 using HeuristicLab.Optimization; 7 29 using HeuristicLab.Parameters; 8 using HeuristicLab.P ersistence.Default.CompositeSerializers.Storable;30 using HeuristicLab.Problems.DataAnalysis; 9 31 using HeuristicLab.Random; 10 32 using System; 11 33 using System.Collections.Generic; 12 34 using System.Linq; 13 14 35 using CancellationToken = System.Threading.CancellationToken; 15 36 16 37 namespace HeuristicLab.Algorithms.MOEAD { 17 38 [Item("MOEADAlgorithmBase", "Base class for all MOEA/D algorithm variants.")] 18 [Storable Class]39 [StorableType("E00BAC79-C6F9-42B6-8468-DEEC7FFCE804")] 19 40 public abstract class MOEADAlgorithmBase : BasicAlgorithm { 20 41 #region data members … … 62 83 [Storable] 63 84 protected ExecutionState previousExecutionState; 85 86 [Storable] 87 protected ExecutionState executionState; 64 88 #endregion 65 89 … … 81 105 private const string MaximumNumberOfReplacedSolutionsParameterName = "MaximumNumberOfReplacedSolutions"; 82 106 private const string FunctionTypeParameterName = "FunctionType"; 107 private const string NormalizeObjectivesParameterName = "NormalizeObjectives"; 83 108 84 109 public IValueParameter<MultiAnalyzer> AnalyzerParameter { … … 91 116 public IFixedValueParameter<IntValue> NeighbourSizeParameter { 92 117 get { return (IFixedValueParameter<IntValue>)Parameters[NeighbourSizeParameterName]; } 118 } 119 public IFixedValueParameter<BoolValue> NormalizeObjectivesParameter { 120 get { return (IFixedValueParameter<BoolValue>)Parameters[NormalizeObjectivesParameterName]; } 93 121 } 94 122 public IFixedValueParameter<IntValue> MaximumNumberOfReplacedSolutionsParameter { … … 141 169 get { return SetSeedRandomlyParameter.Value.Value; } 142 170 set { SetSeedRandomlyParameter.Value.Value = value; } 171 } 172 public bool NormalizeObjectives { 173 get { return NormalizeObjectivesParameter.Value.Value; } 174 set { NormalizeObjectivesParameter.Value.Value = value; } 143 175 } 144 176 public IntValue PopulationSize { … … 204 236 Parameters.Add(new FixedValueParameter<IntValue>(MaximumNumberOfReplacedSolutionsParameterName, new IntValue(2))); 205 237 Parameters.Add(new FixedValueParameter<DoubleValue>(NeighbourhoodSelectionProbabilityParameterName, new DoubleValue(0.1))); 238 Parameters.Add(new FixedValueParameter<BoolValue>(NormalizeObjectivesParameterName, new BoolValue(true))); 206 239 207 240 var functionTypeParameter = new ConstrainedValueParameter<StringValue>(FunctionTypeParameterName); … … 258 291 } 259 292 293 294 [StorableHook(HookType.AfterDeserialization)] 295 private void AfterDeserialization() { 296 if (!Parameters.ContainsKey(NormalizeObjectivesParameterName)) { 297 Parameters.Add(new FixedValueParameter<BoolValue>(NormalizeObjectivesParameterName, new BoolValue(true))); 298 } 299 } 300 260 301 [StorableConstructor] 261 protected MOEADAlgorithmBase( bool deserializing) : base(deserializing) { }302 protected MOEADAlgorithmBase(StorableConstructorFlag _) : base(_) { } 262 303 #endregion 263 304 … … 292 333 } 293 334 294 public override void Prepare() {295 base.Prepare();296 }297 298 335 protected void InitializeAlgorithm(CancellationToken cancellationToken) { 299 globalScope = new Scope("Global Scope");300 executionContext = new ExecutionContext(null, this, globalScope);301 302 // set the execution context for parameters to allow lookup303 foreach (var parameter in Problem.Parameters.OfType<IValueParameter>()) {304 // we need all of these in order for the wiring of the operators to work305 globalScope.Variables.Add(new Variable(parameter.Name, parameter.Value));306 }307 globalScope.Variables.Add(new Variable("Results", Results)); // make results available as a parameter for analyzers etc.308 309 336 var rand = RandomParameter.Value; 310 337 if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed(); … … 320 347 InitializeNeighbourHood(lambda, populationSize, NeighbourSize); 321 348 349 //IdealPoint = Enumerable.Repeat(double.MaxValue, dimensions).ToArray(); 322 350 IdealPoint = new double[dimensions]; 323 351 IdealPoint.UpdateIdeal(population); 324 352 353 //NadirPoint = Enumerable.Repeat(double.MinValue, dimensions).ToArray(); 325 354 NadirPoint = new double[dimensions]; 326 355 NadirPoint.UpdateNadir(population); … … 353 382 globalScope.Variables.Add(new Variable("Results", Results)); // make results available as a parameter for analyzers etc. 354 383 355 var rand = RandomParameter.Value;356 if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed();357 rand.Reset(Seed);358 359 bool[] maximization = ((BoolArray)Problem.MaximizationParameter.ActualValue).CloneAsArray();360 var dimensions = maximization.Length;361 362 var populationSize = PopulationSize.Value;363 364 InitializePopulation(executionContext, cancellationToken, rand, maximization);365 InitializeUniformWeights(rand, populationSize, dimensions);366 InitializeNeighbourHood(lambda, populationSize, NeighbourSize);367 368 IdealPoint = new double[dimensions];369 IdealPoint.UpdateIdeal(population);370 371 NadirPoint = new double[dimensions];372 NadirPoint.UpdateNadir(population);373 374 var functionTypeString = FunctionTypeParameter.Value.Value;375 switch (functionTypeString) {376 case "Chebyshev":377 functionType = FunctionType.TCHE;378 break;379 case "PBI":380 functionType = FunctionType.PBI;381 break;382 case "Weighted Sum":383 functionType = FunctionType.AGG;384 break;385 }386 387 evaluatedSolutions = populationSize;388 389 384 base.Initialize(cancellationToken); 390 385 } … … 396 391 } 397 392 398 // implements random number generation from https://en.wikipedia.org/wiki/Dirichlet_distribution#Random_number_generation 393 // implements random number generation from https://en.wikipedia.org/wiki/Dirichlet_distribution#Random_number_generation 399 394 private double[] GenerateSample(IRandom random, int dim) { 400 395 var sum = 0d; … … 503 498 504 499 for (int n = 0; n < dim; n++) { 505 double diff = Math.Abs(qualities[n] - IdealPoint[n]); 506 507 var l = lambda[n].IsAlmost(0) ? 0.0001 : lambda[n]; 508 //var feval = l * diff; 509 // introduce objective scaling 510 var feval = l * (qualities[n] - IdealPoint[n]) / (NadirPoint[n] - IdealPoint[n]); 500 var diff = qualities[n] - IdealPoint[n]; 501 if (NormalizeObjectives) { 502 diff /= NadirPoint[n] - IdealPoint[n]; 503 } 504 var l = lambda[n].IsAlmost(0) ? 1e-4 : lambda[n]; 505 var feval = l * Math.Abs(diff); 506 511 507 if (feval > maxFun) { 512 508 maxFun = feval; … … 666 662 667 663 protected override void OnExecutionStateChanged() { 668 previousExecutionState = ExecutionState; 664 previousExecutionState = executionState; 665 executionState = ExecutionState; 669 666 base.OnExecutionStateChanged(); 670 667 } 671 668 672 p rotected override void OnStopped() {669 public void ClearState() { 673 670 if (solutions != null) { 674 671 solutions.Clear(); … … 683 680 jointPopulation.Clear(); 684 681 } 685 executionContext.Scope.SubScopes.Clear(); 682 lambda = null; 683 neighbourhood = null; 684 if (executionContext != null && executionContext.Scope != null) { 685 executionContext.Scope.SubScopes.Clear(); 686 } 687 } 688 689 protected override void OnStopped() { 690 ClearState(); 686 691 base.OnStopped(); 687 692 } -
branches/2987_MOEAD_Algorithm/HeuristicLab.Algorithms.MOEAD/3.4/MOEADSolution.cs
r16560 r16630 1 using HeuristicLab.Common; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using HEAL.Attic; 23 using HeuristicLab.Common; 2 24 using HeuristicLab.Core; 3 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;4 25 5 26 namespace HeuristicLab.Algorithms.MOEAD { 27 [StorableType("DFE1AC99-9AEF-4A35-884B-C82E2B3D84F7")] 6 28 public interface IMOEADSolution : IItem { 7 29 IItem Individual { get; set; } … … 12 34 13 35 [Item("MOEADSolution", "Represents a solution inside the MOEA/D population")] 14 [Storable Class]36 [StorableType("8D7DE459-E6D5-4B74-9135-00E27CF451D3")] 15 37 public class MOEADSolution : Item, IMOEADSolution { 16 38 [Storable] … … 55 77 56 78 [StorableConstructor] 57 protected MOEADSolution( booldeserializing) : base(deserializing) { }79 protected MOEADSolution(StorableConstructorFlag deserializing) : base(deserializing) { } 58 80 } 59 81 60 82 [Item("MOEADSolution", "Represents a solution inside the MOEA/D population")] 61 [Storable Class]83 [StorableType("24B4B79B-5828-4E6B-BE35-452DEA1FF538")] 62 84 public class MOEADSolution<T> : MOEADSolution where T : class, IItem { 63 85 public new T Individual { … … 75 97 76 98 [StorableConstructor] 77 protected MOEADSolution( booldeserializing) : base(deserializing) { }99 protected MOEADSolution(StorableConstructorFlag deserializing) : base(deserializing) { } 78 100 } 79 101 } -
branches/2987_MOEAD_Algorithm/HeuristicLab.Algorithms.MOEAD/3.4/MOEADUtil.cs
r16560 r16630 1 using HeuristicLab.Common; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using HeuristicLab.Common; 2 23 using HeuristicLab.Core; 3 24 using System;
Note: See TracChangeset
for help on using the changeset viewer.