Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/EvaluationResult.cs @ 17699

Last change on this file since 17699 was 17381, checked in by mkommend, 5 years ago

#2521: Fixed single-objective evaluation results and scope contexts.

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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.Linq;
24using HEAL.Attic;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27
28namespace HeuristicLab.Optimization {
29
30  //TODO maybe change EvaluationResult from class to struct
31  //TODO implement indexer instead of get/set additional data
32  [StorableType("3E4F5781-0DDB-4B7A-99E2-89C3F1028EB1")]
33  public abstract class EvaluationResult : Item, IEvaluationResult {
34
35    [Storable]
36    private readonly Dictionary<string, object> data = new Dictionary<string, object>();
37
38    protected EvaluationResult() : base() { }
39
40
41    [StorableConstructor]
42    protected EvaluationResult(StorableConstructorFlag _) : base(_) { }
43
44    protected EvaluationResult(EvaluationResult original, Cloner cloner) : base(original, cloner) {
45      data = original.data.ToDictionary(entry => entry.Key,
46                                        entry => entry.Value is DeepCloneable ? cloner.Clone((DeepCloneable)entry.Value) : entry.Value);
47    }
48
49
50    public void SetAdditionalData(string identifier, object o) {
51      data[identifier] = o;
52    }
53    public object GetAdditionalData(string identifier) {
54      return data[identifier];
55    }
56
57  }
58
59  [StorableType("1468E570-64D1-43A5-8B0A-B7821BFAE708")]
60  public class SingleObjectiveEvaluationResult : EvaluationResult, ISingleObjectiveEvaluationResult {
61    [Storable]
62    public double Quality { get; private set; }
63
64    public SingleObjectiveEvaluationResult(double quality) {
65      Quality = quality;
66    }
67
68    [StorableConstructor]
69    protected SingleObjectiveEvaluationResult(StorableConstructorFlag _) : base(_) { }
70
71    public SingleObjectiveEvaluationResult(SingleObjectiveEvaluationResult original, Cloner cloner) : base(original, cloner) {
72      Quality = original.Quality;
73    }
74
75    public override IDeepCloneable Clone(Cloner cloner) {
76      return new SingleObjectiveEvaluationResult(this, cloner);
77    }
78  }
79
80  [StorableType("6D2B628D-E3B0-4C0A-8A2E-61BC8F38439B")]
81  public class MultiObjectiveEvaluationResult : EvaluationResult, IMultiObjectiveEvaluationResult {
82    [Storable]
83    public double[] Quality { get; private set; }
84
85    public MultiObjectiveEvaluationResult(double[] quality) {
86      Quality = quality;
87    }
88
89    [StorableConstructor]
90    protected MultiObjectiveEvaluationResult(StorableConstructorFlag _) : base(_) { }
91
92    public MultiObjectiveEvaluationResult(MultiObjectiveEvaluationResult original, Cloner cloner) : base(original, cloner) {
93      Quality = original.Quality;
94    }
95
96    public override IDeepCloneable Clone(Cloner cloner) {
97      return new MultiObjectiveEvaluationResult(this, cloner);
98    }
99  }
100}
Note: See TracBrowser for help on using the repository browser.