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 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Optimization;
|
---|
26 | using HeuristicLab.Parameters;
|
---|
27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Problems.Programmable {
|
---|
30 | [Item("Scriptable Problem (multi-objective)", "Represents a multi-objective problem that can be scripted.")]
|
---|
31 | [Creatable("1 Test")]
|
---|
32 | [StorableClass]
|
---|
33 | public sealed class MultiObjectiveScriptableProblem : MultiObjectiveProgrammableProblem<IEncoding> {
|
---|
34 |
|
---|
35 | private FixedValueParameter<MultiObjectiveProblemDefinitionScript> MultiObjectiveProblemScriptParameter {
|
---|
36 | get { return (FixedValueParameter<MultiObjectiveProblemDefinitionScript>)Parameters["ProblemScript"]; }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public MultiObjectiveProblemDefinitionScript ProblemScript {
|
---|
40 | get { return MultiObjectiveProblemScriptParameter.Value; }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public IMultiObjectiveProblemDefinition ProblemDefinition {
|
---|
44 | get { return MultiObjectiveProblemScriptParameter.Value; }
|
---|
45 | }
|
---|
46 |
|
---|
47 | private MultiObjectiveScriptableProblem(MultiObjectiveScriptableProblem original, Cloner cloner)
|
---|
48 | : base(original, cloner) {
|
---|
49 | RegisterEvents();
|
---|
50 | ProblemScript.Compile();
|
---|
51 | }
|
---|
52 | public override IDeepCloneable Clone(Cloner cloner) { return new MultiObjectiveScriptableProblem(this, cloner); }
|
---|
53 |
|
---|
54 |
|
---|
55 | [StorableConstructor]
|
---|
56 | private MultiObjectiveScriptableProblem(bool deserializing) : base(deserializing) { }
|
---|
57 |
|
---|
58 | public MultiObjectiveScriptableProblem()
|
---|
59 | : base() {
|
---|
60 | Parameters.Add(new FixedValueParameter<SingleObjectiveProblemDefinitionScript>("ProblemScript", "Defines the problem.", new SingleObjectiveProblemDefinitionScript() { Name = Name }));
|
---|
61 | RegisterEvents();
|
---|
62 | }
|
---|
63 |
|
---|
64 | [StorableHook(HookType.AfterDeserialization)]
|
---|
65 | private void AfterDeserialization() {
|
---|
66 | RegisterEvents();
|
---|
67 | ProblemScript.Compile();
|
---|
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) {
|
---|
89 | ProblemDefinition.Analyze(individuals, qualities, results);
|
---|
90 | }
|
---|
91 | }
|
---|
92 | }
|
---|