#region License Information
/* HeuristicLab
* Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using HEAL.Attic;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Optimization;
namespace HeuristicLab.Problems.Modifiers {
[StorableType("7C9DECC0-1CA1-4198-835F-CB1CF35D88E8")]
[Item("SingleObjectiveEndPointProblemModifier", "A dummy problem modifier leading to a single objective basic problem")]
public class SingleObjectiveEndPointProblemModifier : ProblemModifier where T : class, IEncoding {
private SingleObjectiveBasicProblem problem;
[Storable]
public SingleObjectiveBasicProblem Problem {
get => problem;
set {
problem = value;
UpdateState();
//TODO attach to EncodingChanged and MaximizationChanged Events ... (not implemented in BasicProblem yet)
}
}
public override IEncoding Encoding => Problem?.Encoding;
public override BoolArray Maximization {
get {
if (Problem == null) return new BoolArray(new[] { false });
var dict = new Dictionary();
Problem.CollectParameterValues(dict);
var b = dict.ContainsKey("Maximization") ? ((BoolValue)dict["Maximization"]).Value : problem.Maximization;
return new BoolArray(new[] { b });
}
}
[StorableConstructor]
protected SingleObjectiveEndPointProblemModifier(StorableConstructorFlag _) : base(_) { }
protected SingleObjectiveEndPointProblemModifier(SingleObjectiveEndPointProblemModifier original, Cloner cloner) : base(original, cloner) {
Problem = cloner.Clone(original?.Problem);
}
public SingleObjectiveEndPointProblemModifier() { }
public override IDeepCloneable Clone(Cloner cloner) {
return new SingleObjectiveEndPointProblemModifier(this, cloner);
}
public override double[] ModifiedEvaluate(Individual individual, IRandom random) {
return new[] { Problem.Evaluate(individual, random) };
}
public override void ModifiedAnalyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
Problem.Analyze(individuals, qualities.Select(x => x.Single()).ToArray(), results, random);
}
public void UpdateState() {
InvokeEncodingChanged();
InvokeMaximizationChanged();
}
}
}