Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/SingleObjectiveScriptableProblem.cs @ 11739

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

#2174: Worked on operators and programmable problem base classes and scripts.

File size: 3.5 KB
RevLine 
[11739]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 HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Optimization;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.Programmable.Problems {
30  [Item("Scriptable Problem (single-objective)", "Represents a single-objective problem that can be scripted.")]
31  [Creatable("1 Test")]
32  [StorableClass]
33  public sealed class SingleObjectiveScriptableProblem : SingleObjectiveProgrammableProblem<IEncoding> {
34
35    private FixedValueParameter<SingleObjectiveProblemDefinitionScript> SingleObjectiveProblemScriptParameter {
36      get { return (FixedValueParameter<SingleObjectiveProblemDefinitionScript>)Parameters["ProblemScript"]; }
37    }
38
39    private SingleObjectiveProblemDefinitionScript ProblemScript {
40      get { return SingleObjectiveProblemScriptParameter.Value; }
41    }
42
43    private ISingleObjectiveProblemDefinition ProblemDefinition {
44      get { return SingleObjectiveProblemScriptParameter.Value; }
45    }
46
47    private SingleObjectiveScriptableProblem(SingleObjectiveScriptableProblem original, Cloner cloner)
48      : base(original, cloner) {
49      RegisterEvents();
50    }
51    public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveScriptableProblem(this, cloner); }
52
53
54    [StorableConstructor]
55    private SingleObjectiveScriptableProblem(bool deserializing) : base(deserializing) { }
56
57    public SingleObjectiveScriptableProblem()
58      : base() {
59      Parameters.Add(new FixedValueParameter<SingleObjectiveProblemDefinitionScript>("ProblemScript", "Defines the problem.", new SingleObjectiveProblemDefinitionScript() { Name = Name }));
60      RegisterEvents();
61    }
62
63    [StorableHook(HookType.AfterDeserialization)]
64    private void AfterDeserialization() {
65      RegisterEvents();
66    }
67
68    private void RegisterEvents() {
69      ProblemScript.ProblemDefinitionChanged += (o, e) => OnProblemDefinitionChanged();
70    }
71
72    private void OnProblemDefinitionChanged() {
73    }
74
75    public override bool Maximization {
76      get { return ProblemDefinition.Maximization; }
77    }
78
79    public override double Evaluate(Individual individual, IRandom random) {
80      return ProblemDefinition.Evaluate(individual, random);
81    }
82
83    public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results) {
84      ProblemDefinition.Analyze(individuals, qualities, results);
85    }
86    public override IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
87      return ProblemDefinition.GetNeighbors(individual, random);
88    }
89  }
90}
Note: See TracBrowser for help on using the repository browser.