[3348] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Operators;
|
---|
| 6 | using HeuristicLab.Core;
|
---|
| 7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 8 | using HeuristicLab.Parameters;
|
---|
| 9 | using HeuristicLab.Data;
|
---|
| 10 |
|
---|
| 11 | namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
|
---|
| 12 | /// <summary>
|
---|
| 13 | /// An operator which represents the main loop of a PSO.
|
---|
| 14 | /// </summary>
|
---|
| 15 | [Item("ParticleSwarmOptimizationMainLoop", "An operator which represents the main loop of a PSO.")]
|
---|
| 16 | [StorableClass]
|
---|
| 17 | public class ParticleSwarmOptimizationMainLoop : AlgorithmOperator {
|
---|
| 18 | #region Parameter properties
|
---|
| 19 | public ValueLookupParameter<VariableCollection> ResultsParameter {
|
---|
| 20 | get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
|
---|
| 21 | }
|
---|
| 22 | public ValueLookupParameter<IOperator> EncoderParameter {
|
---|
| 23 | get { return (ValueLookupParameter<IOperator>)Parameters["Encoder"]; }
|
---|
| 24 | }
|
---|
| 25 | #endregion
|
---|
| 26 |
|
---|
| 27 | [StorableConstructor]
|
---|
| 28 | private ParticleSwarmOptimizationMainLoop(bool deserializing) : base() { }
|
---|
| 29 | public ParticleSwarmOptimizationMainLoop()
|
---|
| 30 | : base() {
|
---|
| 31 | Initialize();
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | private void Initialize() {
|
---|
| 35 | #region Create parameters
|
---|
| 36 | Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
|
---|
| 37 | Parameters.Add(new ValueLookupParameter<IOperator>("Encoder", "The encoding operator that maps a solution to a position vector."));
|
---|
| 38 | #endregion
|
---|
| 39 |
|
---|
| 40 | #region Create operators
|
---|
| 41 | VariableCreator variableCreator = new VariableCreator();
|
---|
| 42 | //variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
|
---|
| 43 | UniformSubScopesProcessor uniformSubScopesProcessor = new UniformSubScopesProcessor();
|
---|
| 44 | Placeholder encoder = new Placeholder();
|
---|
| 45 |
|
---|
| 46 | encoder.Name = "Encoder (placeholder)";
|
---|
| 47 | encoder.OperatorParameter.ActualName = EncoderParameter.Name;
|
---|
| 48 | #endregion
|
---|
| 49 |
|
---|
| 50 | #region Create operator graph
|
---|
| 51 | OperatorGraph.InitialOperator = variableCreator;
|
---|
| 52 | variableCreator.Successor = uniformSubScopesProcessor;
|
---|
| 53 | uniformSubScopesProcessor.Operator = encoder;
|
---|
| 54 | uniformSubScopesProcessor.Successor = null;
|
---|
| 55 | #endregion
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | }
|
---|