[11740] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12009] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[11740] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[11961] | 22 | using System.Drawing;
|
---|
[11740] | 23 | using HeuristicLab.Common;
|
---|
[11961] | 24 | using HeuristicLab.Common.Resources;
|
---|
[11740] | 25 | using HeuristicLab.Core;
|
---|
[12005] | 26 | using HeuristicLab.Data;
|
---|
[11740] | 27 | using HeuristicLab.Optimization;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
[11753] | 31 | namespace HeuristicLab.Problems.Programmable {
|
---|
[11814] | 32 | [Item("Programmable Problem (multi-objective)", "Represents a multi-objective problem that can be programmed with a script.")]
|
---|
[11961] | 33 | [Creatable("Problems")]
|
---|
[11740] | 34 | [StorableClass]
|
---|
[11814] | 35 | public sealed class MultiObjectiveProgrammableProblem : MultiObjectiveBasicProblem<IEncoding> {
|
---|
[11961] | 36 | public static new Image StaticItemImage {
|
---|
| 37 | get { return VSImageLibrary.Script; }
|
---|
| 38 | }
|
---|
[11740] | 39 |
|
---|
| 40 | private FixedValueParameter<MultiObjectiveProblemDefinitionScript> MultiObjectiveProblemScriptParameter {
|
---|
| 41 | get { return (FixedValueParameter<MultiObjectiveProblemDefinitionScript>)Parameters["ProblemScript"]; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[11753] | 44 | public MultiObjectiveProblemDefinitionScript ProblemScript {
|
---|
[11740] | 45 | get { return MultiObjectiveProblemScriptParameter.Value; }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[11753] | 48 | public IMultiObjectiveProblemDefinition ProblemDefinition {
|
---|
[11740] | 49 | get { return MultiObjectiveProblemScriptParameter.Value; }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[11814] | 52 | private MultiObjectiveProgrammableProblem(MultiObjectiveProgrammableProblem original, Cloner cloner)
|
---|
[11740] | 53 | : base(original, cloner) {
|
---|
| 54 | RegisterEvents();
|
---|
| 55 | }
|
---|
[11814] | 56 | public override IDeepCloneable Clone(Cloner cloner) { return new MultiObjectiveProgrammableProblem(this, cloner); }
|
---|
[11740] | 57 |
|
---|
| 58 | [StorableConstructor]
|
---|
[11814] | 59 | private MultiObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
|
---|
| 60 | public MultiObjectiveProgrammableProblem()
|
---|
[11740] | 61 | : base() {
|
---|
[11768] | 62 | Parameters.Add(new FixedValueParameter<MultiObjectiveProblemDefinitionScript>("ProblemScript", "Defines the problem.", new MultiObjectiveProblemDefinitionScript() { Name = Name }));
|
---|
[11740] | 63 | RegisterEvents();
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 67 | private void AfterDeserialization() {
|
---|
| 68 | RegisterEvents();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | private void RegisterEvents() {
|
---|
| 72 | ProblemScript.ProblemDefinitionChanged += (o, e) => OnProblemDefinitionChanged();
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | private void OnProblemDefinitionChanged() {
|
---|
[12005] | 76 | Parameters.Remove("Maximization");
|
---|
| 77 | Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly()) { Hidden = true });
|
---|
| 78 |
|
---|
[11753] | 79 | Encoding = ProblemDefinition.Encoding;
|
---|
| 80 | OnOperatorsChanged();
|
---|
| 81 | OnReset();
|
---|
[11740] | 82 | }
|
---|
| 83 |
|
---|
| 84 | public override bool[] Maximization {
|
---|
[12005] | 85 | get { return Parameters.ContainsKey("ProblemScript") ? ProblemDefinition.Maximization : new[] { false }; }
|
---|
[11740] | 86 | }
|
---|
| 87 |
|
---|
| 88 | public override double[] Evaluate(Individual individual, IRandom random) {
|
---|
| 89 | return ProblemDefinition.Evaluate(individual, random);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[11880] | 92 | public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
|
---|
| 93 | ProblemDefinition.Analyze(individuals, qualities, results, random);
|
---|
[11740] | 94 | }
|
---|
| 95 | }
|
---|
| 96 | }
|
---|