Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3057_DynamicALPS/backup/13022020/HeuristicLab.Algorithms.DynamicALPS/3.4/DynamicALPSAlgorithm.cs @ 17479

Last change on this file since 17479 was 17479, checked in by kyang, 4 years ago

#3057

  1. upload the latest version of ALPS with SMS-EMOA
  2. upload the related dynamic test problems (dynamic, single-objective symbolic regression), written by David Daninel.
File size: 7.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Author: Kaifeng Yang
4 *
5 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
6 *
7 * This file is part of HeuristicLab.
8 *\
9 * HeuristicLab is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * HeuristicLab is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23// SMS-EMOA
24/*
25Implemenetation of a real-coded SMS_EMOA algorithm.
26This implementation follows the description of: 'M. Emmerich, N. Beume, and B. Naujoks.
27An EMO Algorithm Using the Hypervolume Measure as Selection Criterion.EMO 2005.'
28*/
29#endregion
30
31using HEAL.Attic;                       
32using HeuristicLab.Common;             
33using HeuristicLab.Core;               
34using HeuristicLab.Data;               
35using HeuristicLab.Random;             
36using System.Linq;                     
37using System;
38using CancellationToken = System.Threading.CancellationToken;
39
40
41/*  This algorithm is SMS-EMOA implementation on HL. The main structure and interfaces with HL are copied from MOEA/D on HL, which was written by Dr. Bogdan Burlacu. The S-metric selection operator was adapted from Kaifeng's MATLAB toolbox in SMS-EMOA. The computational complexity of HVC is AT LEAST $O (n^2 \log n)$ in 2-D and 3-D cases. HVC should definitely be reduced to $\Theta (n \times \log n)$.
42 * 
43 *  This algorithm assumes:
44 *    1. minimization problems. For maximization problems, it is better to add "-" symbol.
45 * 
46 *  This algorithm works on:
47 *    1. continuous, discrete, mixed-integer MOO problems. For different types of problems, the operators should be adjusted accordingly.
48 *    2. both multi-objective and many-objective problems. For many-objective problems, the bottleneck is the computational complexity of HV.
49 *
50 * This algorithm is the basic implementation of SMS-EMOA, proposed by Michael Emmerich et. al. Some potential improvements can be:
51 *    1. Dynamic reference point strategy
52 *    2. Normalized fitness value strategy ---- desirability function. See, Yali, Longmei, Kaifeng, Michael Emmerich CEC paper.
53 *    3. HVC calculation should definitely be improved, at least in the 2D and 3D cases.
54 *    4. multiple point strategy when $\lambda>1$
55 *    5. multiple reference points strategy, in ICNC 2016, Zhiwei Yang et. al.
56 *    6. HVC approximation by R2 for MANY OBJECTIVE cases, by Ishibushi 2019, IEEE TEC 
57 *    7. Maybe: See maps
58 *
59 * Global parameters:
60 *    1. population 
61 *   
62 * Many thanks for Bogdan Burlacu and Johannes Karder, especially Bogdan for his explanation, help, and supports.
63 */
64
65namespace HeuristicLab.Algorithms.DynamicALPS {
66  // Format:
67  // The indexed name of the algorithm/item, Description of the algorithm/item in HL 
68  [Item("DynamicALPS-MainLoop", "DynamicALPS-MainLoop implementation adapted from SMS-EMOA in HL.")]
69
70  // Call "HeuristicLab.Core"
71  // Define the category of this class.
72  [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 125)]
73
74  // Call "HEAL.Attic"
75  // Define GUID for this Class
76  [StorableType("A7F33D16-3495-43E8-943C-8A919123F541")]
77
78  public class DynamicALPSAlgorithm : DynamicALPSAlgorithmBase {
79    public DynamicALPSAlgorithm() { }
80
81    protected DynamicALPSAlgorithm(DynamicALPSAlgorithm original, Cloner cloner) : base(original, cloner) { }
82
83    public override IDeepCloneable Clone(Cloner cloner) {
84      return new DynamicALPSAlgorithm(this, cloner);
85    }
86
87    [StorableConstructor]
88    protected DynamicALPSAlgorithm(StorableConstructorFlag deserializing) : base(deserializing) { }
89
90    protected override void Run(CancellationToken cancellationToken) {
91      if (previousExecutionState != ExecutionState.Paused) { // Call "base" class, DynamicALPSAlgorithmBase
92        InitializeAlgorithm(cancellationToken);
93      }
94
95 
96      var populationSize = PopulationSize.Value;
97      bool[] maximization = ((BoolArray)Problem.MaximizationParameter.ActualValue).CloneAsArray();
98     
99      var crossover = Crossover;
100      var crossoverProbability = CrossoverProbability.Value;
101      var mutator = Mutator;
102      var mutationProbability = MutationProbability.Value;
103      var evaluator = Problem.Evaluator;
104      var analyzer = Analyzer;
105      var rand = RandomParameter.Value;
106     
107
108      var maximumEvaluatedSolutions = MaximumEvaluatedSolutions.Value; 
109
110
111      int lambda = 1;            // the size of offspring
112
113
114      int nLayerALPS = 10000000;
115      int counterLayerALPS = 0;
116      //int indexOffspring = 0;    // the index of offspring to be generated
117      bool[] activeLayer = new bool[ALPSLayers.Value];
118      int[][] ageMatrix = new int[ALPSLayers.Value][];      // layer * population size
119
120
121
122      // cancellation token for the inner operations which should not be immediately cancelled
123      var innerToken = new CancellationToken();
124
125
126      // initilize the offspring population.
127      // offspringPopulation = new IDynamicALPSSolution[lambda];
128
129
130
131
132     
133      //jointPopulation = new IDynamicALPSSolution[lambda + populationSize];
134
135      // 12022020
136      layerPopulation = new IDynamicALPSSolution[nLayerALPS][];
137      layerOffspringPopulation = new IDynamicALPSSolution[nLayerALPS][];
138      layerJointPopulation = new IDynamicALPSSolution[nLayerALPS][];
139
140
141
142      var test = new IDynamicALPSSolution[100, 100];
143      IDynamicALPSSolution[][] test2 = new IDynamicALPSSolution[10000][];
144
145
146
147
148      layerPopulation[counterLayerALPS] = new IDynamicALPSSolution[populationSize];
149      // BUG: The size of offspring should vary in different layers!!!!
150      layerOffspringPopulation[counterLayerALPS] = new IDynamicALPSSolution[lambda];
151      population.CopyTo(layerPopulation[counterLayerALPS], 0);
152      // Mainloop
153      while (evaluatedSolutions < maximumEvaluatedSolutions && !cancellationToken.IsCancellationRequested) {
154
155
156        evaluatedSolutions = SMSEMOA( populationSize,  lambda,  counterLayerALPS);
157
158        if (evaluatedSolutions >= maximumEvaluatedSolutions) {
159          break;
160        }
161
162        layerPopulation[counterLayerALPS].CopyTo(population, 0);  // DEBUG ,DETELE THIS
163
164        // run analyzer
165        var analyze = executionContext.CreateChildOperation(analyzer, globalScope);
166        ExecuteOperation(executionContext, innerToken, analyze);
167        // update Pareto-front approximation sets
168        UpdateParetoFronts();
169        // Show some results in the GUI.
170        Results.AddOrUpdateResult("IdealPoint", new DoubleArray(IdealPoint));
171        Results.AddOrUpdateResult("NadirPoint", new DoubleArray(NadirPoint));
172        Results.AddOrUpdateResult("Evaluated Solutions", new IntValue(evaluatedSolutions));
173
174        // Update globalScope
175        globalScope.SubScopes.Replace(population.Select(x => (IScope)x.Individual));
176
177
178        // intilize the population for the next layer
179        counterLayerALPS += 1;
180        layerPopulation[counterLayerALPS] = new IDynamicALPSSolution[populationSize];
181        layerPopulation[counterLayerALPS-1].CopyTo(layerPopulation[counterLayerALPS], 0); // DETELTE DUBGU
182        // BUG lambda should be different~~~~!!!!
183        layerOffspringPopulation[counterLayerALPS] = new IDynamicALPSSolution[lambda];
184      }
185    }
186
187   
188  }
189}
Note: See TracBrowser for help on using the repository browser.