Ignore:
Timestamp:
11/25/15 23:24:01 (4 years ago)
Author:
abeham
Message:

#2521:

  • Adapted single-objective test function problem to new problem infrastructure
  • Added additional interfaces to RealVectorEncoding
  • Fixed IParticleUpdater interface (must implement IStochasticOperator if it contains a Random parameter)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r13361 r13403  
    3232using HeuristicLab.Parameters;
    3333using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    34 using HeuristicLab.PluginInfrastructure;
    3534using HeuristicLab.Problems.Instances;
    3635
     
    4039  [Creatable(CreatableAttribute.Categories.Problems, Priority = 90)]
    4140  public sealed class SingleObjectiveTestFunctionProblem :
    42     SingleObjectiveHeuristicOptimizationProblem<ISingleObjectiveTestFunctionProblemEvaluator, IRealVectorCreator>,
    43     ISingleObjectiveProblem<RealVectorEncoding, RealVector>, IStorableContent, IProblemInstanceConsumer<SOTFData> {
    44     public string Filename { get; set; }
    45 
    46     [Storable]
    47     private StdDevStrategyVectorCreator strategyVectorCreator;
    48     [Storable]
    49     private StdDevStrategyVectorCrossover strategyVectorCrossover;
    50     [Storable]
    51     private StdDevStrategyVectorManipulator strategyVectorManipulator;
     41    SingleObjectiveProblem<RealVectorEncoding, RealVector>,
     42    IProblemInstanceConsumer<SOTFData> {
     43
     44    public override bool Maximization {
     45      get { return Parameters.ContainsKey("TestFunction") && TestFunction.Maximization; }
     46    }
    5247
    5348    #region Parameter Properties
    54     public ValueParameter<DoubleMatrix> BoundsParameter {
    55       get { return (ValueParameter<DoubleMatrix>)Parameters["Bounds"]; }
    56     }
    57     public ValueParameter<IntValue> ProblemSizeParameter {
    58       get { return (ValueParameter<IntValue>)Parameters["ProblemSize"]; }
     49    private IFixedValueParameter<IntValue> ProblemSizeParameter {
     50      get { return (IFixedValueParameter<IntValue>)Parameters["ProblemSize"]; }
     51    }
     52    private IValueParameter<DoubleMatrix> BoundsParameter {
     53      get { return (IValueParameter<DoubleMatrix>)Parameters["Bounds"]; }
    5954    }
    6055    public OptionalValueParameter<RealVector> BestKnownSolutionParameter {
    6156      get { return (OptionalValueParameter<RealVector>)Parameters["BestKnownSolution"]; }
    6257    }
     58    public IValueParameter<ISingleObjectiveTestFunction> TestFunctionParameter {
     59      get { return (IValueParameter<ISingleObjectiveTestFunction>)Parameters["TestFunction"]; }
     60    }
    6361    #endregion
    6462
    6563    #region Properties
     64    public int ProblemSize {
     65      get { return ProblemSizeParameter.Value.Value; }
     66      set { ProblemSizeParameter.Value.Value = value; }
     67    }
    6668    public DoubleMatrix Bounds {
    6769      get { return BoundsParameter.Value; }
    6870      set { BoundsParameter.Value = value; }
    6971    }
    70     public IntValue ProblemSize {
    71       get { return ProblemSizeParameter.Value; }
    72       set { ProblemSizeParameter.Value = value; }
    73     }
     72    public ISingleObjectiveTestFunction TestFunction {
     73      get { return TestFunctionParameter.Value; }
     74      set { TestFunctionParameter.Value = value; }
     75    }
     76
    7477    private BestSingleObjectiveTestFunctionSolutionAnalyzer BestSingleObjectiveTestFunctionSolutionAnalyzer {
    7578      get { return Operators.OfType<BestSingleObjectiveTestFunctionSolutionAnalyzer>().FirstOrDefault(); }
    76     }
    77     #endregion
    78 
    79     // BackwardsCompatibility3.3
    80     #region Backwards compatible code, remove with 3.4
    81     [Obsolete]
    82     [Storable(Name = "operators")]
    83     private IEnumerable<IOperator> oldOperators {
    84       get { return null; }
    85       set {
    86         if (value != null && value.Any())
    87           Operators.AddRange(value);
    88       }
    8979    }
    9080    #endregion
     
    9484    private SingleObjectiveTestFunctionProblem(SingleObjectiveTestFunctionProblem original, Cloner cloner)
    9585      : base(original, cloner) {
    96       strategyVectorCreator = cloner.Clone(original.strategyVectorCreator);
    97       strategyVectorCrossover = cloner.Clone(original.strategyVectorCrossover);
    98       strategyVectorManipulator = cloner.Clone(original.strategyVectorManipulator);
    9986      RegisterEventHandlers();
    10087    }
    10188    public SingleObjectiveTestFunctionProblem()
    102       : base(new AckleyEvaluator(), new UniformRandomRealVectorCreator()) {
    103       Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.", Evaluator.Bounds));
    104       Parameters.Add(new ValueParameter<IntValue>("ProblemSize", "The dimension of the problem.", new IntValue(2)));
     89      : base(new RealVectorEncoding("Point")) {
     90      Parameters.Add(new FixedValueParameter<IntValue>("ProblemSize", "The dimensionality of the problem instance (number of variables in the function).", new IntValue(2)));
     91      Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The bounds of the solution given as either one line for all variables or a line for each variable. The first column specifies lower bound, the second upper bound.", new DoubleMatrix(new double[,] { { -100, 100 } })));
    10592      Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The best known solution for this test function instance."));
    106 
    107       Maximization.Value = Evaluator.Maximization;
    108       BestKnownQuality = new DoubleValue(Evaluator.BestKnownQuality);
    109 
    110       strategyVectorCreator = new StdDevStrategyVectorCreator();
    111       strategyVectorCreator.LengthParameter.ActualName = ProblemSizeParameter.Name;
    112       strategyVectorCrossover = new StdDevStrategyVectorCrossover();
    113       strategyVectorManipulator = new StdDevStrategyVectorManipulator();
    114       strategyVectorManipulator.LearningRateParameter.Value = new DoubleValue(0.5);
    115       strategyVectorManipulator.GeneralLearningRateParameter.Value = new DoubleValue(0.5);
    116 
    117       SolutionCreator.RealVectorParameter.ActualName = "Point";
    118       ParameterizeSolutionCreator();
    119       ParameterizeEvaluator();
     93      Parameters.Add(new ValueParameter<ISingleObjectiveTestFunction>("TestFunction", "The function that is to be optimized.", new Ackley()));
     94
     95      Encoding.LengthParameter = ProblemSizeParameter;
     96      Encoding.BoundsParameter = BoundsParameter;
     97      BestKnownQuality = TestFunction.BestKnownQuality;
    12098
    12199      InitializeOperators();
    122100      RegisterEventHandlers();
    123       UpdateStrategyVectorBounds();
    124101    }
    125102
     
    128105    }
    129106
     107    [StorableHook(HookType.AfterDeserialization)]
     108    private void AfterDeserialization() {
     109      RegisterEventHandlers();
     110    }
     111
     112    private void RegisterEventHandlers() {
     113      Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
     114      TestFunctionParameter.ValueChanged += TestFunctionParameterOnValueChanged;
     115      ProblemSizeParameter.Value.ValueChanged += ProblemSizeOnValueChanged;
     116      BoundsParameter.ValueChanged += BoundsParameterOnValueChanged;
     117    }
     118
     119    public override double Evaluate(RealVector individual, IRandom random) {
     120      return TestFunction.Evaluate(individual);
     121    }
     122
    130123    #region Events
    131     protected override void OnSolutionCreatorChanged() {
    132       base.OnSolutionCreatorChanged();
    133       ParameterizeSolutionCreator();
    134       ParameterizeAnalyzers();
    135       SolutionCreator.RealVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_RealVectorParameter_ActualNameChanged);
    136       SolutionCreator_RealVectorParameter_ActualNameChanged(null, EventArgs.Empty);
     124    protected override void OnEncodingChanged() {
     125      base.OnEncodingChanged();
     126      Parameterize();
    137127    }
    138128    protected override void OnEvaluatorChanged() {
    139129      base.OnEvaluatorChanged();
    140       bool problemSizeChange = ProblemSize.Value < Evaluator.MinimumProblemSize
    141         || ProblemSize.Value > Evaluator.MaximumProblemSize;
     130      Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
     131      Parameterize();
     132    }
     133    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
     134      Parameterize();
     135    }
     136    private void TestFunctionParameterOnValueChanged(object sender, EventArgs eventArgs) {
     137      var problemSizeChange = ProblemSize < TestFunction.MinimumProblemSize
     138                              || ProblemSize > TestFunction.MaximumProblemSize;
    142139      if (problemSizeChange) {
    143         ProblemSize.Value = Math.Max(Evaluator.MinimumProblemSize, Math.Min(ProblemSize.Value, Evaluator.MaximumProblemSize));
    144       } else {
    145         ParameterizeEvaluator();
    146       }
    147       UpdateMoveEvaluators();
    148       ParameterizeAnalyzers();
    149       Maximization.Value = Evaluator.Maximization;
    150       BoundsParameter.Value = Evaluator.Bounds;
    151       BestKnownQuality = new DoubleValue(Evaluator.BestKnownQuality);
    152       Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    153       Evaluator_QualityParameter_ActualNameChanged(null, EventArgs.Empty);
     140        ProblemSize = Math.Max(TestFunction.MinimumProblemSize, Math.Min(ProblemSize, TestFunction.MaximumProblemSize));
     141      }
     142      BestKnownQuality = TestFunction.BestKnownQuality;
     143      Bounds = (DoubleMatrix)TestFunction.Bounds.Clone();
     144      var bestSolution = TestFunction.GetBestKnownSolution(ProblemSize);
     145      BestKnownSolutionParameter.Value = bestSolution;
     146
    154147      OnReset();
    155148    }
    156     private void ProblemSizeParameter_ValueChanged(object sender, EventArgs e) {
    157       ProblemSize.ValueChanged += new EventHandler(ProblemSize_ValueChanged);
    158       ProblemSize_ValueChanged(null, EventArgs.Empty);
    159     }
    160     private void ProblemSize_ValueChanged(object sender, EventArgs e) {
    161       if (ProblemSize.Value < 1) ProblemSize.Value = 1;
    162       ParameterizeSolutionCreator();
    163       ParameterizeEvaluator();
    164       strategyVectorManipulator.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * ProblemSize.Value));
    165       strategyVectorManipulator.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(ProblemSize.Value)));
    166       OnReset();
    167     }
    168     private void SolutionCreator_RealVectorParameter_ActualNameChanged(object sender, EventArgs e) {
    169       ParameterizeEvaluator();
    170       ParameterizeOperators();
    171       ParameterizeAnalyzers();
    172     }
    173     private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    174       ParameterizeOperators();
    175     }
    176     private void BoundsParameter_ValueChanged(object sender, EventArgs e) {
    177       Bounds.ToStringChanged += new EventHandler(Bounds_ToStringChanged);
    178       Bounds_ToStringChanged(null, EventArgs.Empty);
    179     }
    180     private void Bounds_ToStringChanged(object sender, EventArgs e) {
    181       if (Bounds.Columns != 2 || Bounds.Rows < 1)
    182         Bounds = new DoubleMatrix(1, 2);
    183       ParameterizeOperators();
    184       UpdateStrategyVectorBounds();
    185     }
    186     private void Bounds_ItemChanged(object sender, EventArgs<int, int> e) {
    187       if (e.Value2 == 0 && Bounds[e.Value, 1] <= Bounds[e.Value, 0])
    188         Bounds[e.Value, 1] = Bounds[e.Value, 0] + 0.1;
    189       if (e.Value2 == 1 && Bounds[e.Value, 0] >= Bounds[e.Value, 1])
    190         Bounds[e.Value, 0] = Bounds[e.Value, 1] - 0.1;
    191       ParameterizeOperators();
    192       UpdateStrategyVectorBounds();
    193     }
    194     private void MoveGenerator_AdditiveMoveParameter_ActualNameChanged(object sender, EventArgs e) {
    195       string name = ((ILookupParameter<AdditiveMove>)sender).ActualName;
    196       foreach (IAdditiveRealVectorMoveOperator op in Operators.OfType<IAdditiveRealVectorMoveOperator>()) {
    197         op.AdditiveMoveParameter.ActualName = name;
    198       }
    199     }
    200     private void SphereEvaluator_Parameter_ValueChanged(object sender, EventArgs e) {
    201       SphereEvaluator eval = (Evaluator as SphereEvaluator);
    202       if (eval != null) {
    203         foreach (ISphereMoveEvaluator op in Operators.OfType<ISphereMoveEvaluator>()) {
    204           op.C = eval.C;
    205           op.Alpha = eval.Alpha;
    206         }
    207       }
    208     }
    209     private void RastriginEvaluator_Parameter_ValueChanged(object sender, EventArgs e) {
    210       RastriginEvaluator eval = (Evaluator as RastriginEvaluator);
    211       if (eval != null) {
    212         foreach (IRastriginMoveEvaluator op in Operators.OfType<IRastriginMoveEvaluator>()) {
    213           op.A = eval.A;
    214         }
    215       }
    216     }
    217     private void strategyVectorCreator_BoundsParameter_ValueChanged(object sender, EventArgs e) {
    218       strategyVectorManipulator.BoundsParameter.Value = (DoubleMatrix)strategyVectorCreator.BoundsParameter.Value.Clone();
    219     }
    220     private void strategyVectorCreator_StrategyParameterParameter_ActualNameChanged(object sender, EventArgs e) {
    221       string name = strategyVectorCreator.StrategyParameterParameter.ActualName;
    222       strategyVectorCrossover.ParentsParameter.ActualName = name;
    223       strategyVectorCrossover.StrategyParameterParameter.ActualName = name;
    224       strategyVectorManipulator.StrategyParameterParameter.ActualName = name;
     149    private void ProblemSizeOnValueChanged(object sender, EventArgs eventArgs) {
     150      if (ProblemSize < TestFunction.MinimumProblemSize
     151        || ProblemSize > TestFunction.MaximumProblemSize)
     152        ProblemSize = Math.Min(TestFunction.MaximumProblemSize, Math.Max(TestFunction.MinimumProblemSize, ProblemSize));
     153    }
     154    private void BoundsParameterOnValueChanged(object sender, EventArgs eventArgs) {
     155      Parameterize();
    225156    }
    226157    #endregion
    227158
    228159    #region Helpers
    229     [StorableHook(HookType.AfterDeserialization)]
    230     private void AfterDeserialization() {
    231       // BackwardsCompatibility3.3
    232       #region Backwards compatible code (remove with 3.4)
    233       if (Operators.Count == 0) InitializeOperators();
    234       #endregion
    235       RegisterEventHandlers();
    236     }
    237 
    238     private void RegisterEventHandlers() {
    239       ProblemSizeParameter.ValueChanged += new EventHandler(ProblemSizeParameter_ValueChanged);
    240       ProblemSize.ValueChanged += new EventHandler(ProblemSize_ValueChanged);
    241       BoundsParameter.ValueChanged += new EventHandler(BoundsParameter_ValueChanged);
    242       Bounds.ToStringChanged += new EventHandler(Bounds_ToStringChanged);
    243       Bounds.ItemChanged += new EventHandler<EventArgs<int, int>>(Bounds_ItemChanged);
    244       SolutionCreator.RealVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_RealVectorParameter_ActualNameChanged);
    245       Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    246       strategyVectorCreator.BoundsParameter.ValueChanged += new EventHandler(strategyVectorCreator_BoundsParameter_ValueChanged);
    247       strategyVectorCreator.StrategyParameterParameter.ActualNameChanged += new EventHandler(strategyVectorCreator_StrategyParameterParameter_ActualNameChanged);
    248     }
    249     private void ParameterizeAnalyzers() {
    250       if (BestSingleObjectiveTestFunctionSolutionAnalyzer != null) {
    251         BestSingleObjectiveTestFunctionSolutionAnalyzer.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    252         BestSingleObjectiveTestFunctionSolutionAnalyzer.ResultsParameter.ActualName = "Results";
    253         BestSingleObjectiveTestFunctionSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    254         BestSingleObjectiveTestFunctionSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
    255         BestSingleObjectiveTestFunctionSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
    256         BestSingleObjectiveTestFunctionSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
    257         BestSingleObjectiveTestFunctionSolutionAnalyzer.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
    258         BestSingleObjectiveTestFunctionSolutionAnalyzer.BoundsParameter.ActualName = BoundsParameter.Name;
    259       }
    260     }
    261160    private void InitializeOperators() {
    262161      Operators.Add(new SingleObjectiveTestFunctionImprovementOperator());
     
    265164      Operators.Add(new QualitySimilarityCalculator());
    266165      Operators.Add(new NoSimilarityCalculator());
     166      Operators.Add(new AdditiveMoveEvaluator());
    267167
    268168      Operators.Add(new BestSingleObjectiveTestFunctionSolutionAnalyzer());
    269169      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
    270       ParameterizeAnalyzers();
    271       Operators.AddRange(ApplicationManager.Manager.GetInstances<IRealVectorOperator>().Cast<IOperator>());
    272       Operators.Add(strategyVectorCreator);
    273       Operators.Add(strategyVectorCrossover);
    274       Operators.Add(strategyVectorManipulator);
    275       UpdateMoveEvaluators();
    276       ParameterizeOperators();
    277       InitializeMoveGenerators();
    278     }
    279     private void InitializeMoveGenerators() {
    280       foreach (IAdditiveRealVectorMoveOperator op in Operators.OfType<IAdditiveRealVectorMoveOperator>()) {
    281         if (op is IMoveGenerator) {
    282           op.AdditiveMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_AdditiveMoveParameter_ActualNameChanged);
    283         }
    284       }
    285     }
    286     private void UpdateMoveEvaluators() {
    287       foreach (ISingleObjectiveTestFunctionMoveEvaluator op in Operators.OfType<ISingleObjectiveTestFunctionMoveEvaluator>().ToList())
    288         Operators.Remove(op);
    289       foreach (ISingleObjectiveTestFunctionMoveEvaluator op in ApplicationManager.Manager.GetInstances<ISingleObjectiveTestFunctionMoveEvaluator>())
    290         if (op.EvaluatorType == Evaluator.GetType()) {
    291           Operators.Add(op);
    292           #region Synchronize evaluator specific parameters with the parameters of the corresponding move evaluators
    293           if (op is ISphereMoveEvaluator) {
    294             SphereEvaluator e = (Evaluator as SphereEvaluator);
    295             e.AlphaParameter.ValueChanged += new EventHandler(SphereEvaluator_Parameter_ValueChanged);
    296             e.CParameter.ValueChanged += new EventHandler(SphereEvaluator_Parameter_ValueChanged);
    297             ISphereMoveEvaluator em = (op as ISphereMoveEvaluator);
    298             em.C = e.C;
    299             em.Alpha = e.Alpha;
    300           } else if (op is IRastriginMoveEvaluator) {
    301             RastriginEvaluator e = (Evaluator as RastriginEvaluator);
    302             e.AParameter.ValueChanged += new EventHandler(RastriginEvaluator_Parameter_ValueChanged);
    303             IRastriginMoveEvaluator em = (op as IRastriginMoveEvaluator);
    304             em.A = e.A;
    305           }
    306           #endregion
    307         }
    308       ParameterizeOperators();
    309       OnOperatorsChanged();
    310     }
    311     private void ParameterizeSolutionCreator() {
    312       SolutionCreator.LengthParameter.Value = new IntValue(ProblemSize.Value);
    313       SolutionCreator.LengthParameter.Hidden = true;
    314       SolutionCreator.BoundsParameter.ActualName = BoundsParameter.Name;
    315       SolutionCreator.BoundsParameter.Hidden = true;
    316     }
    317     private void ParameterizeEvaluator() {
    318       Evaluator.PointParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    319       Evaluator.PointParameter.Hidden = true;
    320       try {
    321         BestKnownSolutionParameter.Value = Evaluator.GetBestKnownSolution(ProblemSize.Value);
    322       }
    323       catch (ArgumentException e) {
    324         ErrorHandling.ShowErrorDialog(e);
    325         ProblemSize.Value = Evaluator.MinimumProblemSize;
    326       }
    327     }
    328     private void ParameterizeOperators() {
    329       foreach (var op in Operators.OfType<IRealVectorCrossover>()) {
    330         op.ParentsParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    331         op.ParentsParameter.Hidden = true;
    332         op.ChildParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    333         op.ChildParameter.Hidden = true;
    334         op.BoundsParameter.ActualName = BoundsParameter.Name;
    335         op.BoundsParameter.Hidden = true;
    336       }
    337       foreach (var op in Operators.OfType<IRealVectorManipulator>()) {
    338         op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    339         op.RealVectorParameter.Hidden = true;
    340         op.BoundsParameter.ActualName = BoundsParameter.Name;
    341         op.BoundsParameter.Hidden = true;
    342       }
    343       foreach (var op in Operators.OfType<IRealVectorMoveOperator>()) {
    344         op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    345         op.RealVectorParameter.Hidden = true;
    346       }
    347       foreach (var op in Operators.OfType<IRealVectorMoveGenerator>()) {
    348         op.BoundsParameter.ActualName = BoundsParameter.Name;
    349         op.BoundsParameter.Hidden = true;
     170      Parameterize();
     171    }
     172
     173    private void Parameterize() {
     174      var operators = new List<IItem>();
     175      if (BestSingleObjectiveTestFunctionSolutionAnalyzer != null) {
     176        operators.Add(BestSingleObjectiveTestFunctionSolutionAnalyzer);
     177        BestSingleObjectiveTestFunctionSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     178        BestSingleObjectiveTestFunctionSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
     179        BestSingleObjectiveTestFunctionSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
     180        BestSingleObjectiveTestFunctionSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
     181        BestSingleObjectiveTestFunctionSolutionAnalyzer.TestFunctionParameter.ActualName = TestFunctionParameter.Name;
    350182      }
    351183      foreach (var op in Operators.OfType<ISingleObjectiveTestFunctionAdditiveMoveEvaluator>()) {
     184        operators.Add(op);
    352185        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    353186        op.QualityParameter.Hidden = true;
    354         op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    355         op.RealVectorParameter.Hidden = true;
    356       }
    357       foreach (var op in Operators.OfType<IRealVectorParticleCreator>()) {
    358         op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    359         op.RealVectorParameter.Hidden = true;
    360         op.BoundsParameter.ActualName = BoundsParameter.Name;
    361         op.BoundsParameter.Hidden = true;
    362         op.ProblemSizeParameter.ActualName = ProblemSizeParameter.Name;
    363         op.ProblemSizeParameter.Hidden = true;
    364       }
    365       foreach (var op in Operators.OfType<IRealVectorParticleUpdater>()) {
    366         op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    367         op.RealVectorParameter.Hidden = true;
    368         op.BoundsParameter.ActualName = BoundsParameter.Name;
    369         op.BoundsParameter.Hidden = true;
     187        foreach (var movOp in Encoding.Operators.OfType<IRealVectorAdditiveMoveQualityOperator>())
     188          movOp.MoveQualityParameter.ActualName = op.MoveQualityParameter.ActualName;
    370189      }
    371190      foreach (var op in Operators.OfType<IRealVectorSwarmUpdater>()) {
    372         op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    373         op.RealVectorParameter.Hidden = true;
    374191        op.MaximizationParameter.ActualName = MaximizationParameter.Name;
    375192        op.MaximizationParameter.Hidden = true;
    376193      }
    377       foreach (var op in Operators.OfType<IRealVectorMultiNeighborhoodShakingOperator>()) {
    378         op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    379         op.RealVectorParameter.Hidden = true;
    380       }
    381194      foreach (var op in Operators.OfType<ISingleObjectiveImprovementOperator>()) {
    382         op.SolutionParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
     195        operators.Add(op);
     196        op.SolutionParameter.ActualName = Encoding.Name;
    383197        op.SolutionParameter.Hidden = true;
    384198      }
    385       foreach (var op in Operators.OfType<ISingleObjectivePathRelinker>()) {
    386         op.ParentsParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    387         op.ParentsParameter.Hidden = true;
    388       }
    389       foreach (var op in Operators.OfType<ISolutionSimilarityCalculator>()) {
    390         op.SolutionVariableName = SolutionCreator.RealVectorParameter.ActualName;
     199      foreach (var op in Operators.OfType<ITestFunctionSolutionSimilarityCalculator>()) {
     200        operators.Add(op);
     201        op.SolutionVariableName = Encoding.Name;
    391202        op.QualityVariableName = Evaluator.QualityParameter.ActualName;
    392         var calc = op as SingleObjectiveTestFunctionSimilarityCalculator;
    393         if (calc != null) calc.Bounds = Bounds;
    394       }
    395     }
    396     private void UpdateStrategyVectorBounds() {
    397       var strategyBounds = (DoubleMatrix)Bounds.Clone();
    398       for (int i = 0; i < strategyBounds.Rows; i++) {
    399         if (strategyBounds[i, 0] < 0) strategyBounds[i, 0] = 0;
    400         strategyBounds[i, 1] = 0.1 * (Bounds[i, 1] - Bounds[i, 0]);
    401       }
    402       strategyVectorCreator.BoundsParameter.Value = strategyBounds;
     203        op.Bounds = Bounds;
     204      }
     205
     206      if (operators.Count > 0) Encoding.ConfigureOperators(operators);
    403207    }
    404208    #endregion
     
    407211      Name = data.Name;
    408212      Description = data.Description;
    409       Evaluator = data.Evaluator;
     213      TestFunction = data.TestFunction;
    410214    }
    411215  }
Note: See TracChangeset for help on using the changeset viewer.