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 |
|
---|
22 |
|
---|
23 | using System;
|
---|
24 | using System.Collections.Generic;
|
---|
25 |
|
---|
26 | using HEAL.Attic;
|
---|
27 | using HeuristicLab.Common;
|
---|
28 | using HeuristicLab.Core;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Optimization {
|
---|
31 | [StorableType("72638F28-11DD-440D-B7A2-79E16E0EFB83")]
|
---|
32 | public abstract class SolutionContext : Item {
|
---|
33 |
|
---|
34 | [Storable]
|
---|
35 | private readonly Dictionary<string, object> data = new Dictionary<string, object>();
|
---|
36 |
|
---|
37 | [Storable]
|
---|
38 | public IEncodedSolution EncodedSolution { get; private set; }
|
---|
39 |
|
---|
40 | [Storable]
|
---|
41 | public IEvaluationResult EvaluationResult { get; protected set; }
|
---|
42 |
|
---|
43 | public bool IsEvaluated => EvaluationResult != null;
|
---|
44 |
|
---|
45 | protected SolutionContext(IEncodedSolution encodedSolution) : base() {
|
---|
46 | EncodedSolution = encodedSolution ?? throw new ArgumentNullException("encodedSolution");
|
---|
47 | }
|
---|
48 |
|
---|
49 | protected SolutionContext(IEncodedSolution encodedSolution, IEvaluationResult evaluationResult) : this(encodedSolution) {
|
---|
50 | EvaluationResult = evaluationResult ?? throw new ArgumentNullException("evaluationResult");
|
---|
51 | }
|
---|
52 |
|
---|
53 | [StorableConstructor]
|
---|
54 | protected SolutionContext(StorableConstructorFlag _) : base(_) { }
|
---|
55 |
|
---|
56 | public SolutionContext(SolutionContext original, Cloner cloner) : base(original, cloner) {
|
---|
57 | //TODO clone data dictionary
|
---|
58 | EncodedSolution = cloner.Clone(original.EncodedSolution);
|
---|
59 | EvaluationResult = cloner.Clone(original.EvaluationResult);
|
---|
60 | }
|
---|
61 |
|
---|
62 | public void SetAdditionalData(string identifier, object o) {
|
---|
63 | data[identifier] = o;
|
---|
64 | }
|
---|
65 | public object GetAdditionalData(string identifier) {
|
---|
66 | return data[identifier];
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | [StorableType("DF6DA9C9-7EF4-4DC3-9855-6C43BDEDD735")]
|
---|
71 | public class SingleObjectiveSolutionContext : SolutionContext, ISingleObjectiveSolutionContext {
|
---|
72 | public new ISingleObjectiveEvaluationResult EvaluationResult { get; set; }
|
---|
73 |
|
---|
74 | public SingleObjectiveSolutionContext(IEncodedSolution encodedSolution) : base(encodedSolution) { }
|
---|
75 |
|
---|
76 |
|
---|
77 | public SingleObjectiveSolutionContext(IEncodedSolution encodedSolution, IEvaluationResult evaluationResult) : base(encodedSolution, evaluationResult) { }
|
---|
78 |
|
---|
79 | [StorableConstructor]
|
---|
80 | public SingleObjectiveSolutionContext(StorableConstructorFlag _) : base(_) { }
|
---|
81 |
|
---|
82 | public SingleObjectiveSolutionContext(SolutionContext original, Cloner cloner) : base(original, cloner) { }
|
---|
83 |
|
---|
84 |
|
---|
85 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
86 | return new SingleObjectiveSolutionContext(this, cloner);
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | [StorableType("929868B3-8994-4D75-B363-CCF9C51410F9")]
|
---|
91 | public class MultiObjectiveSolutionContext : SolutionContext, IMultiObjectiveSolutionContext {
|
---|
92 | public new IMultiObjectiveEvaluationResult EvaluationResult { get; set; }
|
---|
93 |
|
---|
94 | public MultiObjectiveSolutionContext(IEncodedSolution encodedSolution) : base(encodedSolution) { }
|
---|
95 |
|
---|
96 |
|
---|
97 | public MultiObjectiveSolutionContext(IEncodedSolution encodedSolution, IEvaluationResult evaluationResult) : base(encodedSolution, evaluationResult) { }
|
---|
98 |
|
---|
99 | [StorableConstructor]
|
---|
100 | public MultiObjectiveSolutionContext(StorableConstructorFlag _) : base(_) { }
|
---|
101 |
|
---|
102 | public MultiObjectiveSolutionContext(SolutionContext original, Cloner cloner) : base(original, cloner) { }
|
---|
103 |
|
---|
104 |
|
---|
105 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
106 | return new MultiObjectiveSolutionContext(this, cloner);
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|