Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/WeightedValueModifierSelector.cs @ 5299

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

#852: Added two parameter updaters (for omega and the velocity bounds)

File size: 2.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Operators;
6using HeuristicLab.Core;
7using HeuristicLab.Data;
8using HeuristicLab.Parameters;
9using HeuristicLab.Common;
10using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
11using HeuristicLab.PluginInfrastructure;
12using HeuristicLab.Optimization;
13
14namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
15  public class WeightedValueModifierSelector : SingleSuccessorOperator {
16    public IValueParameter<DoubleValue> ScaleParameter {
17      get { return (IValueParameter<DoubleValue>)Parameters["Scale"]; }
18    }
19
20    public ILookupParameter<DoubleMatrix> ValueParameter {
21      get { return (ILookupParameter<DoubleMatrix>)Parameters["Matrix"]; }
22    }
23
24    public ConstrainedValueParameter<IOperator> ModifierParameter {
25      get { return (ConstrainedValueParameter<IOperator>)Parameters["Modifier"]; }
26    }
27
28    public WeightedValueModifierSelector() : base() {
29      Parameters.Add(new LookupParameter<DoubleMatrix>("Matrix", "The double matrix to scale."));
30      Parameters.Add(new ValueParameter<DoubleValue>("Scale", "The double value to modify.", new DoubleValue(1)));
31      Parameters.Add(new ConstrainedValueParameter<IOperator>("Modifier", "Modifies the value", new ItemSet<IOperator>()));
32    }
33
34    public override IDeepCloneable Clone(Cloner cloner) {
35      return new WeightedValueModifierSelector(this, cloner);
36    }
37
38    protected WeightedValueModifierSelector(WeightedValueModifierSelector original, Cloner cloner)
39      : base(original, cloner) {
40    }
41
42    [StorableConstructor]
43    protected WeightedValueModifierSelector(bool deserializing) : base(deserializing) { }
44
45    public override IOperation Apply() {
46      OperationCollection next = new OperationCollection();
47      DoubleMatrix matrix = ValueParameter.ActualValue;
48      for (int i = 0; i < matrix.Rows; i++) {
49        for (int j = 0; j < matrix.Columns; j++) {
50          ValueParameter.ActualValue[i, j] *= ScaleParameter.Value.Value;
51        }
52      }
53      next.Add(ExecutionContext.CreateChildOperation(this.ModifierParameter.Value));
54      next.Add(base.Apply());
55      return next;
56    }
57  }
58}
Note: See TracBrowser for help on using the repository browser.