Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimizationMainLoop.cs @ 3352

Last change on this file since 3352 was 3348, checked in by mkofler, 14 years ago

Added project for particle swarm optimization algorithm #852 (WIP)

File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Operators;
6using HeuristicLab.Core;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8using HeuristicLab.Parameters;
9using HeuristicLab.Data;
10
11namespace 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}
Note: See TracBrowser for help on using the repository browser.