Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProgrammableProblem.cs @ 11961

Last change on this file since 11961 was 11961, checked in by abeham, 10 years ago

#2174: Integrated programmable problem into trunk

  • Fixed build configuration
  • Fixed some assembly references that had CopyLocal set to true
  • Added a missing license header
  • Cleaned some usings
  • Fixed the version number in ExternalEvaluation.GP
  • Added ProgrammableProblem and new ExternalEvaluationProblem as a reference to unit tests
  • Fixed plugin dependencies and assembly references
  • Changed icon of programmable problem to script icon
  • Fixed name clash in VRP that also had defined a "PermutationEncoding" class
  • (Hopefully) fixed all output paths
File size: 3.6 KB
Line 
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
22using System.Drawing;
23using HeuristicLab.Common;
24using HeuristicLab.Common.Resources;
25using HeuristicLab.Core;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.Programmable {
31  [Item("Programmable Problem (multi-objective)", "Represents a multi-objective problem that can be programmed with a script.")]
32  [Creatable("Problems")]
33  [StorableClass]
34  public sealed class MultiObjectiveProgrammableProblem : MultiObjectiveBasicProblem<IEncoding> {
35    public static new Image StaticItemImage {
36      get { return VSImageLibrary.Script; }
37    }
38
39    private FixedValueParameter<MultiObjectiveProblemDefinitionScript> MultiObjectiveProblemScriptParameter {
40      get { return (FixedValueParameter<MultiObjectiveProblemDefinitionScript>)Parameters["ProblemScript"]; }
41    }
42
43    public MultiObjectiveProblemDefinitionScript ProblemScript {
44      get { return MultiObjectiveProblemScriptParameter.Value; }
45    }
46
47    public IMultiObjectiveProblemDefinition ProblemDefinition {
48      get { return MultiObjectiveProblemScriptParameter.Value; }
49    }
50
51    private MultiObjectiveProgrammableProblem(MultiObjectiveProgrammableProblem original, Cloner cloner)
52      : base(original, cloner) {
53      RegisterEvents();
54    }
55    public override IDeepCloneable Clone(Cloner cloner) { return new MultiObjectiveProgrammableProblem(this, cloner); }
56
57    [StorableConstructor]
58    private MultiObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
59    public MultiObjectiveProgrammableProblem()
60      : base() {
61      Parameters.Add(new FixedValueParameter<MultiObjectiveProblemDefinitionScript>("ProblemScript", "Defines the problem.", new MultiObjectiveProblemDefinitionScript() { Name = Name }));
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();
72    }
73
74    private void OnProblemDefinitionChanged() {
75      Encoding = ProblemDefinition.Encoding;
76      OnOperatorsChanged();
77      OnReset();
78    }
79
80    public override bool[] Maximization {
81      get { return ProblemDefinition.Maximization; }
82    }
83
84    public override double[] Evaluate(Individual individual, IRandom random) {
85      return ProblemDefinition.Evaluate(individual, random);
86    }
87
88    public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
89      ProblemDefinition.Analyze(individuals, qualities, results, random);
90    }
91  }
92}
Note: See TracBrowser for help on using the repository browser.