using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Operators; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HeuristicLab.Common; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.PluginInfrastructure; using HeuristicLab.Optimization; namespace HeuristicLab.Algorithms.ParticleSwarmOptimization { public class WeightedValueModifierSelector : SingleSuccessorOperator { public IValueParameter ScaleParameter { get { return (IValueParameter)Parameters["Scale"]; } } public ILookupParameter ValueParameter { get { return (ILookupParameter)Parameters["Matrix"]; } } public ConstrainedValueParameter ModifierParameter { get { return (ConstrainedValueParameter)Parameters["Modifier"]; } } public WeightedValueModifierSelector() : base() { Parameters.Add(new LookupParameter("Matrix", "The double matrix to scale.")); Parameters.Add(new ValueParameter("Scale", "The double value to modify.", new DoubleValue(1))); Parameters.Add(new ConstrainedValueParameter("Modifier", "Modifies the value", new ItemSet())); } public override IDeepCloneable Clone(Cloner cloner) { return new WeightedValueModifierSelector(this, cloner); } protected WeightedValueModifierSelector(WeightedValueModifierSelector original, Cloner cloner) : base(original, cloner) { } [StorableConstructor] protected WeightedValueModifierSelector(bool deserializing) : base(deserializing) { } public override IOperation Apply() { OperationCollection next = new OperationCollection(); DoubleMatrix matrix = ValueParameter.ActualValue; for (int i = 0; i < matrix.Rows; i++) { for (int j = 0; j < matrix.Columns; j++) { ValueParameter.ActualValue[i, j] *= ScaleParameter.Value.Value; } } next.Add(ExecutionContext.CreateChildOperation(this.ModifierParameter.Value)); next.Add(base.Apply()); return next; } } }