Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/AdaptiveRandomTopologyUpdater.cs @ 17231

Last change on this file since 17231 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 4.2 KB
RevLine 
[5435]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[5435]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;
[5339]23using HeuristicLab.Core;
[5435]24using HeuristicLab.Data;
[5339]25using HeuristicLab.Operators;
[5560]26using HeuristicLab.Optimization;
[5339]27using HeuristicLab.Parameters;
[16565]28using HEAL.Attic;
[5339]29
30namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
[15181]31  [Item("SPSO Adaptive Random Topology Updater", "Each unsuccessful iteration the topology initializer is applied again.")]
[16565]32  [StorableType("F0FC17DF-44B3-4005-9CC3-EDBA7945544A")]
[15181]33  public sealed class SPSOAdaptiveRandomTopologyUpdater : SingleSuccessorOperator, ITopologyUpdater, ISingleObjectiveOperator {
[5592]34
[5435]35    public override bool CanChangeName {
36      get { return false; }
37    }
38
[5339]39    #region Parameters
[15181]40    public ILookupParameter<BoolValue> MaximizationParameter {
41      get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
[5339]42    }
[15181]43    public ILookupParameter<DoubleValue> SwarmBestQualityParameter {
44      get { return (ILookupParameter<DoubleValue>)Parameters["SwarmBestQuality"]; }
[5339]45    }
[15181]46    public ILookupParameter<DoubleValue> PreviousBestQualityParameter {
47      get { return (ILookupParameter<DoubleValue>)Parameters["PreviousBestQuality"]; }
[5339]48    }
[15181]49    public ILookupParameter<ITopologyInitializer> TopologyInitializerParameter {
50      get { return (ILookupParameter<ITopologyInitializer>)Parameters["TopologyInitializer"]; }
51    }
[5560]52    public IScopeTreeLookupParameter<IntArray> NeighborsParameter {
53      get { return (IScopeTreeLookupParameter<IntArray>)Parameters["Neighbors"]; }
[5339]54    }
55    #endregion
56
[5592]57    #region Construction & Cloning
[5435]58    [StorableConstructor]
[16565]59    private SPSOAdaptiveRandomTopologyUpdater(StorableConstructorFlag _) : base(_) { }
[15181]60    private SPSOAdaptiveRandomTopologyUpdater(SPSOAdaptiveRandomTopologyUpdater original, Cloner cloner) : base(original, cloner) { }
61    public SPSOAdaptiveRandomTopologyUpdater()
[5339]62      : base() {
[15181]63      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Whether the problem is to be maximized or not."));
64      Parameters.Add(new LookupParameter<DoubleValue>("SwarmBestQuality", "The swarm's best quality."));
65      Parameters.Add(new LookupParameter<DoubleValue>("PreviousBestQuality", "The best quality of the previous iteration."));
66      Parameters.Add(new LookupParameter<ITopologyInitializer>("TopologyInitializer", "The topology initializer is called again in case no improvement is made."));
[5560]67      Parameters.Add(new ScopeTreeLookupParameter<IntArray>("Neighbors", "The list of neighbors for each particle."));
[5339]68    }
[5435]69    public override IDeepCloneable Clone(Cloner cloner) {
[15181]70      return new SPSOAdaptiveRandomTopologyUpdater(this, cloner);
[5435]71    }
[5592]72    #endregion
[5435]73
[5339]74    public override IOperation Apply() {
[15181]75      var swarmBest = SwarmBestQualityParameter.ActualValue;
76      if (swarmBest == null) return base.Apply();
[5339]77
[15181]78      var previousBest = PreviousBestQualityParameter.ActualValue;
79      if (previousBest == null) {
80        PreviousBestQualityParameter.ActualValue = new DoubleValue(swarmBest.Value);
81        return base.Apply();
82      };
[5339]83
[15181]84      var successor = new OperationCollection(new[] { base.Apply() });
85      var max = MaximizationParameter.ActualValue.Value;
[15214]86      if (max && swarmBest.Value <= previousBest.Value
87        || !max && swarmBest.Value >= previousBest.Value)
[15181]88        successor.Insert(0, ExecutionContext.CreateOperation(TopologyInitializerParameter.ActualValue));
[5339]89
[15181]90      previousBest.Value = swarmBest.Value;
91      return successor;
[5339]92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.