Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 18086 was 17709, checked in by abeham, 4 years ago

#2521: working on VRP

File size: 3.6 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    public IEnumerable<KeyValuePair<string, object>> AdditionalData => data.AsEnumerable();
38
39    protected EvaluationResult() : base() { }
40
41
42    [StorableConstructor]
43    protected EvaluationResult(StorableConstructorFlag _) : base(_) { }
44
45    protected EvaluationResult(EvaluationResult original, Cloner cloner) : base(original, cloner) {
46      data = original.data.ToDictionary(entry => entry.Key,
47                                        entry => entry.Value is DeepCloneable ? cloner.Clone((DeepCloneable)entry.Value) : entry.Value);
48    }
49
50
51    public void SetAdditionalData(string identifier, object o) {
52      data[identifier] = o;
53    }
54    public object GetAdditionalData(string identifier) {
55      return data[identifier];
56    }
57
58  }
59
60  [StorableType("1468E570-64D1-43A5-8B0A-B7821BFAE708")]
61  public class SingleObjectiveEvaluationResult : EvaluationResult, ISingleObjectiveEvaluationResult {
62    [Storable]
63    public double Quality { get; private set; }
64
65    public SingleObjectiveEvaluationResult(double quality) {
66      Quality = quality;
67    }
68
69    [StorableConstructor]
70    protected SingleObjectiveEvaluationResult(StorableConstructorFlag _) : base(_) { }
71
72    public SingleObjectiveEvaluationResult(SingleObjectiveEvaluationResult original, Cloner cloner) : base(original, cloner) {
73      Quality = original.Quality;
74    }
75
76    public override IDeepCloneable Clone(Cloner cloner) {
77      return new SingleObjectiveEvaluationResult(this, cloner);
78    }
79  }
80
81  [StorableType("6D2B628D-E3B0-4C0A-8A2E-61BC8F38439B")]
82  public class MultiObjectiveEvaluationResult : EvaluationResult, IMultiObjectiveEvaluationResult {
83    [Storable]
84    public double[] Quality { get; private set; }
85
86    public MultiObjectiveEvaluationResult(double[] quality) {
87      Quality = quality;
88    }
89
90    [StorableConstructor]
91    protected MultiObjectiveEvaluationResult(StorableConstructorFlag _) : base(_) { }
92
93    public MultiObjectiveEvaluationResult(MultiObjectiveEvaluationResult original, Cloner cloner) : base(original, cloner) {
94      Quality = original.Quality;
95    }
96
97    public override IDeepCloneable Clone(Cloner cloner) {
98      return new MultiObjectiveEvaluationResult(this, cloner);
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.