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