Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/28/19 14:23:36 (5 years ago)
Author:
bburlacu
Message:

#2987: Migrate to new persistence. Add support for objective scaling.

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  
    11<?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">
    33  <PropertyGroup>
    44    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     
    1111    <RootNamespace>HeuristicLab.Algorithms.MOEAD</RootNamespace>
    1212    <AssemblyName>HeuristicLab.Algorithms.MOEAD-3.4</AssemblyName>
    13     <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
     13    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
    1414    <FileAlignment>512</FileAlignment>
    1515    <SignAssembly>true</SignAssembly>
     
    9898  </PropertyGroup>
    9999  <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>
    100106    <Reference Include="HeuristicLab.Analysis-3.3">
    101107      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Analysis-3.3.dll</HintPath>
     
    139145      <Private>False</Private>
    140146    </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>
    141157    <Reference Include="HeuristicLab.Random-3.3">
    142158      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Random-3.3.dll</HintPath>
     
    148164    </Reference>
    149165    <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>
    150170    <Reference Include="System.Xml" />
    151171  </ItemGroup>
    152172  <ItemGroup>
    153173    <None Include="HeuristicLab.snk" />
     174    <None Include="packages.config" />
    154175    <None Include="Plugin.cs.frame" />
    155176    <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
     22using HEAL.Attic;
     23using HeuristicLab.Common;
    224using HeuristicLab.Core;
    325using HeuristicLab.Data;
    4 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    526using HeuristicLab.Random;
    627using System.Linq;
     
    930namespace HeuristicLab.Algorithms.MOEAD {
    1031  [Item("Multi-objective Evolutionary Algorithm based on Decomposition (MOEA/D)", "MOEA/D implementation adapted from jMetal.")]
    11   [StorableClass]
    1232  [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 125)]
     33  [StorableType("FE39AD23-B3BF-4368-BB79-FE5BF4C36272")]
    1334  public class MOEADAlgorithm : MOEADAlgorithmBase {
    1435    public MOEADAlgorithm() { }
     
    2142
    2243    [StorableConstructor]
    23     protected MOEADAlgorithm(bool deserializing) : base(deserializing) { }
     44    protected MOEADAlgorithm(StorableConstructorFlag deserializing) : base(deserializing) { }
    2445
    2546    protected override void Run(CancellationToken cancellationToken) {
     
    98119
    99120        UpdateParetoFronts();
     121
     122        Results.AddOrUpdateResult("IdealPoint", new DoubleArray(IdealPoint));
     123        Results.AddOrUpdateResult("NadirPoint", new DoubleArray(NadirPoint));
    100124        Results.AddOrUpdateResult("Evaluated Solutions", new IntValue(evaluatedSolutions));
    101125
  • 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
     22using HEAL.Attic;
     23using HeuristicLab.Analysis;
    224using HeuristicLab.Common;
    325using HeuristicLab.Core;
     
    628using HeuristicLab.Optimization;
    729using HeuristicLab.Parameters;
    8 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Problems.DataAnalysis;
    931using HeuristicLab.Random;
    1032using System;
    1133using System.Collections.Generic;
    1234using System.Linq;
    13 
    1435using CancellationToken = System.Threading.CancellationToken;
    1536
    1637namespace HeuristicLab.Algorithms.MOEAD {
    1738  [Item("MOEADAlgorithmBase", "Base class for all MOEA/D algorithm variants.")]
    18   [StorableClass]
     39  [StorableType("E00BAC79-C6F9-42B6-8468-DEEC7FFCE804")]
    1940  public abstract class MOEADAlgorithmBase : BasicAlgorithm {
    2041    #region data members
     
    6283    [Storable]
    6384    protected ExecutionState previousExecutionState;
     85
     86    [Storable]
     87    protected ExecutionState executionState;
    6488    #endregion
    6589
     
    81105    private const string MaximumNumberOfReplacedSolutionsParameterName = "MaximumNumberOfReplacedSolutions";
    82106    private const string FunctionTypeParameterName = "FunctionType";
     107    private const string NormalizeObjectivesParameterName = "NormalizeObjectives";
    83108
    84109    public IValueParameter<MultiAnalyzer> AnalyzerParameter {
     
    91116    public IFixedValueParameter<IntValue> NeighbourSizeParameter {
    92117      get { return (IFixedValueParameter<IntValue>)Parameters[NeighbourSizeParameterName]; }
     118    }
     119    public IFixedValueParameter<BoolValue> NormalizeObjectivesParameter {
     120      get { return (IFixedValueParameter<BoolValue>)Parameters[NormalizeObjectivesParameterName]; }
    93121    }
    94122    public IFixedValueParameter<IntValue> MaximumNumberOfReplacedSolutionsParameter {
     
    141169      get { return SetSeedRandomlyParameter.Value.Value; }
    142170      set { SetSeedRandomlyParameter.Value.Value = value; }
     171    }
     172    public bool NormalizeObjectives {
     173      get { return NormalizeObjectivesParameter.Value.Value; }
     174      set { NormalizeObjectivesParameter.Value.Value = value; }
    143175    }
    144176    public IntValue PopulationSize {
     
    204236      Parameters.Add(new FixedValueParameter<IntValue>(MaximumNumberOfReplacedSolutionsParameterName, new IntValue(2)));
    205237      Parameters.Add(new FixedValueParameter<DoubleValue>(NeighbourhoodSelectionProbabilityParameterName, new DoubleValue(0.1)));
     238      Parameters.Add(new FixedValueParameter<BoolValue>(NormalizeObjectivesParameterName, new BoolValue(true)));
    206239
    207240      var functionTypeParameter = new ConstrainedValueParameter<StringValue>(FunctionTypeParameterName);
     
    258291    }
    259292
     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
    260301    [StorableConstructor]
    261     protected MOEADAlgorithmBase(bool deserializing) : base(deserializing) { }
     302    protected MOEADAlgorithmBase(StorableConstructorFlag _) : base(_) { }
    262303    #endregion
    263304
     
    292333    }
    293334
    294     public override void Prepare() {
    295       base.Prepare();
    296     }
    297 
    298335    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 lookup
    303       foreach (var parameter in Problem.Parameters.OfType<IValueParameter>()) {
    304         // we need all of these in order for the wiring of the operators to work
    305         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 
    309336      var rand = RandomParameter.Value;
    310337      if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed();
     
    320347      InitializeNeighbourHood(lambda, populationSize, NeighbourSize);
    321348
     349      //IdealPoint = Enumerable.Repeat(double.MaxValue, dimensions).ToArray();
    322350      IdealPoint = new double[dimensions];
    323351      IdealPoint.UpdateIdeal(population);
    324352
     353      //NadirPoint = Enumerable.Repeat(double.MinValue, dimensions).ToArray();
    325354      NadirPoint = new double[dimensions];
    326355      NadirPoint.UpdateNadir(population);
     
    353382      globalScope.Variables.Add(new Variable("Results", Results)); // make results available as a parameter for analyzers etc.
    354383
    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 
    389384      base.Initialize(cancellationToken);
    390385    }
     
    396391    }
    397392
    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
    399394    private double[] GenerateSample(IRandom random, int dim) {
    400395      var sum = 0d;
     
    503498
    504499            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
    511507              if (feval > maxFun) {
    512508                maxFun = feval;
     
    666662
    667663    protected override void OnExecutionStateChanged() {
    668       previousExecutionState = ExecutionState;
     664      previousExecutionState = executionState;
     665      executionState = ExecutionState;
    669666      base.OnExecutionStateChanged();
    670667    }
    671668
    672     protected override void OnStopped() {
     669    public void ClearState() {
    673670      if (solutions != null) {
    674671        solutions.Clear();
     
    683680        jointPopulation.Clear();
    684681      }
    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();
    686691      base.OnStopped();
    687692    }
  • 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
     22using HEAL.Attic;
     23using HeuristicLab.Common;
    224using HeuristicLab.Core;
    3 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    425
    526namespace HeuristicLab.Algorithms.MOEAD {
     27  [StorableType("DFE1AC99-9AEF-4A35-884B-C82E2B3D84F7")]
    628  public interface IMOEADSolution : IItem {
    729    IItem Individual { get; set; }
     
    1234
    1335  [Item("MOEADSolution", "Represents a solution inside the MOEA/D population")]
    14   [StorableClass]
     36  [StorableType("8D7DE459-E6D5-4B74-9135-00E27CF451D3")]
    1537  public class MOEADSolution : Item, IMOEADSolution {
    1638    [Storable]
     
    5577
    5678    [StorableConstructor]
    57     protected MOEADSolution(bool deserializing) : base(deserializing) { }
     79    protected MOEADSolution(StorableConstructorFlag deserializing) : base(deserializing) { }
    5880  }
    5981
    6082  [Item("MOEADSolution", "Represents a solution inside the MOEA/D population")]
    61   [StorableClass]
     83  [StorableType("24B4B79B-5828-4E6B-BE35-452DEA1FF538")]
    6284  public class MOEADSolution<T> : MOEADSolution where T : class, IItem {
    6385    public new T Individual {
     
    7597
    7698    [StorableConstructor]
    77     protected MOEADSolution(bool deserializing) : base(deserializing) { }
     99    protected MOEADSolution(StorableConstructorFlag deserializing) : base(deserializing) { }
    78100  }
    79101}
  • 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
     22using HeuristicLab.Common;
    223using HeuristicLab.Core;
    324using System;
Note: See TracChangeset for help on using the changeset viewer.