Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleCreator.cs @ 17226

Last change on this file since 17226 was 17226, checked in by mkommend, 5 years ago

#2521: Merged trunk changes into problem refactoring branch.

File size: 4.9 KB
RevLine 
[5560]1#region License Information
2/* HeuristicLab
[17226]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[5560]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
[16692]22using System;
[5592]23using HeuristicLab.Common;
[5560]24using HeuristicLab.Core;
25using HeuristicLab.Data;
[5592]26using HeuristicLab.Operators;
[16692]27using HeuristicLab.Optimization;
[5560]28using HeuristicLab.Parameters;
[16723]29using HEAL.Attic;
[16692]30using HeuristicLab.PluginInfrastructure;
[5560]31
32namespace HeuristicLab.Encodings.RealVectorEncoding {
33  [Item("RealVectorParticleCreator", "Creates a particle with position, zero velocity vector and personal best.")]
[16723]34  [StorableType("C2C2600B-BB18-4A97-960C-74C9303D2A33")]
[16692]35  [NonDiscoverableType]
36  [Obsolete("Use SPSOParticleCreator")]
37  internal class RealVectorParticleCreator : AlgorithmOperator, IRealVectorParticleCreator {
[5592]38
39    #region Parameters
[5560]40    public ILookupParameter<IntValue> ProblemSizeParameter {
[5592]41      get { return (ILookupParameter<IntValue>)Parameters["ProblemSize"]; }
[5560]42    }
[5592]43    public IValueLookupParameter<DoubleMatrix> BoundsParameter {
44      get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
45    }
[5560]46    public ILookupParameter<RealVector> RealVectorParameter {
47      get { return (ILookupParameter<RealVector>)Parameters["RealVector"]; }
48    }
49    public ILookupParameter<RealVector> PersonalBestParameter {
50      get { return (ILookupParameter<RealVector>)Parameters["PersonalBest"]; }
51    }
52    public ILookupParameter<RealVector> VelocityParameter {
53      get { return (ILookupParameter<RealVector>)Parameters["Velocity"]; }
54    }
[16692]55    public ILookupParameter<ISolutionCreator> SolutionCreatorParameter {
56      get { return (ILookupParameter<ISolutionCreator>)Parameters["SolutionCreator"]; }
57    }
[5592]58    #endregion
[5560]59
[5592]60    #region Parameter Values
61    protected int ProblemSize {
62      get { return ProblemSizeParameter.ActualValue.Value; }
63    }
64    protected RealVector Velocity {
65      set { VelocityParameter.ActualValue = value; }
66    }
[5560]67    #endregion
68
[5592]69    #region Construction & Cloning
70    [StorableConstructor]
[16723]71    protected RealVectorParticleCreator(StorableConstructorFlag _) : base(_) { }
[5592]72    protected RealVectorParticleCreator(RealVectorParticleCreator original, Cloner cloner) : base(original, cloner) { }
73    public RealVectorParticleCreator()
74      : base() {
[5560]75      Parameters.Add(new LookupParameter<IntValue>("ProblemSize", "The dimension of the problem."));
76      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension."));
77      Parameters.Add(new LookupParameter<RealVector>("RealVector", "Particle's current solution"));
78      Parameters.Add(new LookupParameter<RealVector>("PersonalBest", "Particle's personal best solution."));
[5592]79      Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity."));
[16692]80      Parameters.Add(new LookupParameter<ISolutionCreator>("SolutionCreator", "The operator that creates the initial position."));
[5560]81
[5592]82      UniformRandomRealVectorCreator realVectorCreater = new UniformRandomRealVectorCreator();
[5560]83      Assigner personalBestPositionAssigner = new Assigner();
84
[5592]85      OperatorGraph.InitialOperator = realVectorCreater;
[5560]86
[5592]87      realVectorCreater.RealVectorParameter.ActualName = RealVectorParameter.Name;
[5560]88      realVectorCreater.LengthParameter.ActualName = ProblemSizeParameter.Name;
[5592]89      realVectorCreater.BoundsParameter.ActualName = BoundsParameter.Name;
[5560]90      realVectorCreater.Successor = personalBestPositionAssigner;
91
[5592]92      personalBestPositionAssigner.LeftSideParameter.ActualName = PersonalBestParameter.Name;
93      personalBestPositionAssigner.RightSideParameter.ActualName = RealVectorParameter.Name;
94      personalBestPositionAssigner.Successor = null;
[5560]95    }
96    public override IDeepCloneable Clone(Cloner cloner) {
97      return new RealVectorParticleCreator(this, cloner);
98    }
[5592]99    #endregion
[5560]100
[5592]101    public override IOperation Apply() {
102      Velocity = new RealVector(ProblemSize);
103      return base.Apply();
[5560]104    }
[16692]105   
106    [StorableHook(HookType.AfterDeserialization)]
107    private void AfterDeserialization() {
108      if (!Parameters.ContainsKey("SolutionCreator"))
109        Parameters.Add(new LookupParameter<ISolutionCreator>("SolutionCreator", "The operator that creates the initial position."));
110    }
[5560]111  }
112}
Note: See TracBrowser for help on using the repository browser.