[5225] | 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.Data;
|
---|
| 8 | using HeuristicLab.Parameters;
|
---|
| 9 | using HeuristicLab.Common;
|
---|
| 10 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 11 | using HeuristicLab.PluginInfrastructure;
|
---|
| 12 | using HeuristicLab.Optimization;
|
---|
| 13 |
|
---|
| 14 | namespace 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 | }
|
---|