Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProgrammableProblem.cs @ 11949

Last change on this file since 11949 was 11949, checked in by mkommend, 9 years ago

#2174: Distributed files in programmable problem branch to the correct plugins.

File size: 3.4 KB
RevLine 
[11740]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
[11767]22using System;
[11740]23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Optimization;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
[11753]29namespace HeuristicLab.Problems.Programmable {
[11814]30  [Item("Programmable Problem (multi-objective)", "Represents a multi-objective problem that can be programmed with a script.")]
[11740]31  [Creatable("1 Test")]
32  [StorableClass]
[11814]33  public sealed class MultiObjectiveProgrammableProblem : MultiObjectiveBasicProblem<IEncoding> {
[11740]34
35    private FixedValueParameter<MultiObjectiveProblemDefinitionScript> MultiObjectiveProblemScriptParameter {
36      get { return (FixedValueParameter<MultiObjectiveProblemDefinitionScript>)Parameters["ProblemScript"]; }
37    }
38
[11753]39    public MultiObjectiveProblemDefinitionScript ProblemScript {
[11740]40      get { return MultiObjectiveProblemScriptParameter.Value; }
41    }
42
[11753]43    public IMultiObjectiveProblemDefinition ProblemDefinition {
[11740]44      get { return MultiObjectiveProblemScriptParameter.Value; }
45    }
46
[11814]47    private MultiObjectiveProgrammableProblem(MultiObjectiveProgrammableProblem original, Cloner cloner)
[11740]48      : base(original, cloner) {
49      RegisterEvents();
50    }
[11814]51    public override IDeepCloneable Clone(Cloner cloner) { return new MultiObjectiveProgrammableProblem(this, cloner); }
[11740]52
53    [StorableConstructor]
[11814]54    private MultiObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
55    public MultiObjectiveProgrammableProblem()
[11740]56      : base() {
[11768]57      Parameters.Add(new FixedValueParameter<MultiObjectiveProblemDefinitionScript>("ProblemScript", "Defines the problem.", new MultiObjectiveProblemDefinitionScript() { Name = Name }));
[11740]58      RegisterEvents();
59    }
60
61    [StorableHook(HookType.AfterDeserialization)]
62    private void AfterDeserialization() {
63      RegisterEvents();
64    }
65
66    private void RegisterEvents() {
67      ProblemScript.ProblemDefinitionChanged += (o, e) => OnProblemDefinitionChanged();
68    }
69
70    private void OnProblemDefinitionChanged() {
[11753]71      Encoding = ProblemDefinition.Encoding;
72      OnOperatorsChanged();
73      OnReset();
[11740]74    }
75
76    public override bool[] Maximization {
77      get { return ProblemDefinition.Maximization; }
78    }
79
80    public override double[] Evaluate(Individual individual, IRandom random) {
81      return ProblemDefinition.Evaluate(individual, random);
82    }
83
[11880]84    public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
85      ProblemDefinition.Analyze(individuals, qualities, results, random);
[11740]86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.