Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 11961 was 11961, checked in by abeham, 9 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.7 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.Collections.Generic;
23using System.Drawing;
24using HeuristicLab.Common;
25using HeuristicLab.Common.Resources;
26using HeuristicLab.Core;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.Programmable {
32  [Item("Programmable Problem (single-objective)", "Represents a single-objective problem that can be programmed with a script.")]
33  [Creatable("Problems")]
34  [StorableClass]
35  public sealed class SingleObjectiveProgrammableProblem : SingleObjectiveBasicProblem<IEncoding> {
36    public static new Image StaticItemImage {
37      get { return VSImageLibrary.Script; }
38    }
39
40    private FixedValueParameter<SingleObjectiveProblemDefinitionScript> SingleObjectiveProblemScriptParameter {
41      get { return (FixedValueParameter<SingleObjectiveProblemDefinitionScript>)Parameters["ProblemScript"]; }
42    }
43
44    public SingleObjectiveProblemDefinitionScript ProblemScript {
45      get { return SingleObjectiveProblemScriptParameter.Value; }
46    }
47
48    public ISingleObjectiveProblemDefinition ProblemDefinition {
49      get { return SingleObjectiveProblemScriptParameter.Value; }
50    }
51
52    private SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem original, Cloner cloner)
53      : base(original, cloner) {
54      RegisterEvents();
55    }
56    public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveProgrammableProblem(this, cloner); }
57
58    [StorableConstructor]
59    private SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
60    public SingleObjectiveProgrammableProblem()
61      : base() {
62      Parameters.Add(new FixedValueParameter<SingleObjectiveProblemDefinitionScript>("ProblemScript", "Defines the problem.", new SingleObjectiveProblemDefinitionScript() { Name = Name }));
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() {
76      Encoding = ProblemDefinition.Encoding;
77    }
78
79    public override bool Maximization {
80      get { return ProblemDefinition.Maximization; }
81    }
82
83    public override double Evaluate(Individual individual, IRandom random) {
84      return ProblemDefinition.Evaluate(individual, random);
85    }
86
87    public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
88      ProblemDefinition.Analyze(individuals, qualities, results, random);
89    }
90    public override IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
91      return ProblemDefinition.GetNeighbors(individual, random);
92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.