Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProgrammableProblem.cs @ 15318

Last change on this file since 15318 was 13656, checked in by ascheibe, 9 years ago

#2582 created branch for Hive Web Job Manager

File size: 4.1 KB
RevLine 
[11740]1#region License Information
2/* HeuristicLab
[12012]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
22using HeuristicLab.Common;
23using HeuristicLab.Core;
[11996]24using HeuristicLab.Data;
[11740]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.")]
[12504]31  [Creatable(CreatableAttribute.Categories.Problems, Priority = 120)]
[11740]32  [StorableClass]
[12616]33  public sealed class MultiObjectiveProgrammableProblem : MultiObjectiveBasicProblem<IEncoding>, IProgrammableItem {
[11740]34
[13656]35
36    private FixedValueParameter<MultiObjectiveProblemDefinitionScript> MultiObjectiveProblemScriptParameter
37    {
[11740]38      get { return (FixedValueParameter<MultiObjectiveProblemDefinitionScript>)Parameters["ProblemScript"]; }
39    }
40
[13656]41    public MultiObjectiveProblemDefinitionScript ProblemScript
42    {
[11740]43      get { return MultiObjectiveProblemScriptParameter.Value; }
44    }
45
[13656]46    public IMultiObjectiveProblemDefinition ProblemDefinition
47    {
[11740]48      get { return MultiObjectiveProblemScriptParameter.Value; }
49    }
50
[11814]51    private MultiObjectiveProgrammableProblem(MultiObjectiveProgrammableProblem original, Cloner cloner)
[11740]52      : base(original, cloner) {
53      RegisterEvents();
54    }
[11814]55    public override IDeepCloneable Clone(Cloner cloner) { return new MultiObjectiveProgrammableProblem(this, cloner); }
[11740]56
57    [StorableConstructor]
[11814]58    private MultiObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
59    public MultiObjectiveProgrammableProblem()
[11740]60      : base() {
[11768]61      Parameters.Add(new FixedValueParameter<MultiObjectiveProblemDefinitionScript>("ProblemScript", "Defines the problem.", new MultiObjectiveProblemDefinitionScript() { Name = Name }));
[11740]62      RegisterEvents();
63    }
64
65    [StorableHook(HookType.AfterDeserialization)]
66    private void AfterDeserialization() {
67      RegisterEvents();
68    }
69
70    private void RegisterEvents() {
71      ProblemScript.ProblemDefinitionChanged += (o, e) => OnProblemDefinitionChanged();
[13626]72      ProblemScript.NameChanged += (o, e) => OnProblemScriptNameChanged();
[11740]73    }
74
75    private void OnProblemDefinitionChanged() {
[12002]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 });
[11996]78
[11753]79      Encoding = ProblemDefinition.Encoding;
80      OnOperatorsChanged();
81      OnReset();
[11740]82    }
[13626]83    protected override void OnNameChanged() {
84      base.OnNameChanged();
85      ProblemScript.Name = Name;
86    }
87    private void OnProblemScriptNameChanged() {
88      Name = ProblemScript.Name;
89    }
[11740]90
[13656]91    public override bool[] Maximization
92    {
[12002]93      get { return Parameters.ContainsKey("ProblemScript") ? ProblemDefinition.Maximization : new[] { false }; }
[11740]94    }
95
96    public override double[] Evaluate(Individual individual, IRandom random) {
97      return ProblemDefinition.Evaluate(individual, random);
98    }
99
[11880]100    public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
101      ProblemDefinition.Analyze(individuals, qualities, results, random);
[11740]102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.