Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3629 was 3415, checked in by mkofler, 15 years ago

Worked on particle swarm optimization algorithm #852 (WIP)

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