Free cookie consent management tool by TermsFeed Policy Generator

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

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

Worked on particle swarm optimization algorithm #852 (WIP)

File size: 2.7 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    public ValueLookupParameter<IOperator> EvaluatorParameter {
26      get { return (ValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
27    }
28    #endregion
29
30    [StorableConstructor]
31    private ParticleSwarmOptimizationMainLoop(bool deserializing) : base() { }
32    public ParticleSwarmOptimizationMainLoop()
33      : base() {
34      Initialize();
35    }
36
37    private void Initialize() {
38      #region Create parameters
39      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
40      Parameters.Add(new ValueLookupParameter<IOperator>("Encoder", "The encoding operator that maps a solution to a position vector."));
41      Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions."));
42      #endregion
43
44      #region Create operators
45      VariableCreator variableCreator = new VariableCreator();
46      //variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
47      UniformSubScopesProcessor uniformSubScopesProcessor = new UniformSubScopesProcessor();
48      Placeholder encoder = new Placeholder();
49      Placeholder evaluator = new Placeholder();
50
51      encoder.Name = "Encoder (placeholder)";
52      encoder.OperatorParameter.ActualName = EncoderParameter.Name;
53
54      evaluator.Name = "Evaluator (placeholder)";
55      evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name;
56      #endregion
57
58      #region Create operator graph
59      OperatorGraph.InitialOperator = variableCreator;
60      variableCreator.Successor = uniformSubScopesProcessor;
61      uniformSubScopesProcessor.Operator = encoder;
62      uniformSubScopesProcessor.Successor = evaluator;
63      #endregion
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.