1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2018 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;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Operators;
|
---|
26 | using HeuristicLab.Optimization;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Encodings.RealVectorEncoding {
|
---|
31 | [Item("Particle Creator (SPSO)", "Creates a particle with position, velocity vector and personal best.")]
|
---|
32 | [StorableClass]
|
---|
33 | public class SPSOParticleCreator : AlgorithmOperator, IRealVectorParticleCreator, IStochasticOperator {
|
---|
34 |
|
---|
35 | #region Parameters
|
---|
36 | public ILookupParameter<IRandom> RandomParameter {
|
---|
37 | get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
|
---|
38 | }
|
---|
39 | public IValueLookupParameter<DoubleMatrix> BoundsParameter {
|
---|
40 | get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
|
---|
41 | }
|
---|
42 | public ILookupParameter<RealVector> RealVectorParameter {
|
---|
43 | get { return (ILookupParameter<RealVector>)Parameters["RealVector"]; }
|
---|
44 | }
|
---|
45 | public ILookupParameter<RealVector> PersonalBestParameter {
|
---|
46 | get { return (ILookupParameter<RealVector>)Parameters["PersonalBest"]; }
|
---|
47 | }
|
---|
48 | public ILookupParameter<RealVector> VelocityParameter {
|
---|
49 | get { return (ILookupParameter<RealVector>)Parameters["Velocity"]; }
|
---|
50 | }
|
---|
51 | public ILookupParameter<ISolutionCreator> SolutionCreatorParameter {
|
---|
52 | get { return (ILookupParameter<ISolutionCreator>)Parameters["SolutionCreator"]; }
|
---|
53 | }
|
---|
54 | public IConstrainedValueParameter<SPSOVelocityInitializer> VelocityInitializerParameter {
|
---|
55 | get { return (IConstrainedValueParameter<SPSOVelocityInitializer>)Parameters["VelocityInitializer"]; }
|
---|
56 | }
|
---|
57 | #endregion
|
---|
58 |
|
---|
59 | #region Construction & Cloning
|
---|
60 | [StorableConstructor]
|
---|
61 | protected SPSOParticleCreator(bool deserializing) : base(deserializing) { }
|
---|
62 | protected SPSOParticleCreator(SPSOParticleCreator original, Cloner cloner) : base(original, cloner) { }
|
---|
63 | public SPSOParticleCreator()
|
---|
64 | : base() {
|
---|
65 | Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
|
---|
66 | Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension."));
|
---|
67 | Parameters.Add(new LookupParameter<RealVector>("RealVector", "Particle's current solution"));
|
---|
68 | Parameters.Add(new LookupParameter<RealVector>("PersonalBest", "Particle's personal best solution."));
|
---|
69 | Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity."));
|
---|
70 | Parameters.Add(new LookupParameter<ISolutionCreator>("SolutionCreator", "The operator that creates the initial position."));
|
---|
71 | Parameters.Add(new ConstrainedValueParameter<SPSOVelocityInitializer>("VelocityInitializer", "The initialization of the velocity vector."));
|
---|
72 |
|
---|
73 | VelocityInitializerParameter.ValidValues.Add(new SPSO2011VelocityInitializer());
|
---|
74 | VelocityInitializerParameter.ValidValues.Add(new SPSO2007VelocityInitializer());
|
---|
75 |
|
---|
76 | foreach (var init in VelocityInitializerParameter.ValidValues) {
|
---|
77 | init.BoundsParameter.ActualName = BoundsParameter.Name;
|
---|
78 | init.BoundsParameter.Hidden = true;
|
---|
79 | init.RandomParameter.ActualName = RandomParameter.Name;
|
---|
80 | init.RealVectorParameter.ActualName = RealVectorParameter.Name;
|
---|
81 | init.VelocityParameter.ActualName = VelocityParameter.Name;
|
---|
82 | }
|
---|
83 |
|
---|
84 | Placeholder realVectorCreater = new Placeholder();
|
---|
85 | Assigner personalBestPositionAssigner = new Assigner();
|
---|
86 | Placeholder velocityInitializer = new Placeholder();
|
---|
87 |
|
---|
88 | OperatorGraph.InitialOperator = realVectorCreater;
|
---|
89 |
|
---|
90 | realVectorCreater.OperatorParameter.ActualName = SolutionCreatorParameter.Name;
|
---|
91 | realVectorCreater.Successor = personalBestPositionAssigner;
|
---|
92 |
|
---|
93 | personalBestPositionAssigner.LeftSideParameter.ActualName = PersonalBestParameter.Name;
|
---|
94 | personalBestPositionAssigner.RightSideParameter.ActualName = RealVectorParameter.Name;
|
---|
95 | personalBestPositionAssigner.Successor = velocityInitializer;
|
---|
96 |
|
---|
97 | velocityInitializer.OperatorParameter.ActualName = VelocityInitializerParameter.Name;
|
---|
98 | velocityInitializer.Successor = null;
|
---|
99 | }
|
---|
100 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
101 | return new SPSOParticleCreator(this, cloner);
|
---|
102 | }
|
---|
103 | #endregion
|
---|
104 | }
|
---|
105 | }
|
---|