Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/CombinedSolution.cs @ 17383

Last change on this file since 17383 was 17226, checked in by mkommend, 5 years ago

#2521: Merged trunk changes into problem refactoring branch.

File size: 2.8 KB
RevLine 
[11598]1#region License Information
2/* HeuristicLab
[17226]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[11598]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;
23using System.Linq;
[16751]24using HEAL.Attic;
[11813]25using HeuristicLab.Common;
[11598]26using HeuristicLab.Core;
27
[11949]28namespace HeuristicLab.Optimization {
[13356]29  [Item("CombinedSolution", "A solution that consists of other solutions.")]
[16724]30  [StorableType("B5ED00CB-E533-4ED6-AB2D-95BF7A654AAD")]
[16751]31  public sealed class CombinedSolution : Item, IEncodedSolution {
[11598]32
[13376]33    private CombinedEncoding Encoding { get; set; }
34    private IScope Scope { get; set; }
[11737]35
[13351]36    [StorableConstructor]
[16724]37    private CombinedSolution(StorableConstructorFlag _) : base(_) { }
[13356]38    private CombinedSolution(CombinedSolution original, Cloner cloner)
[13351]39      : base(original, cloner) {
40      Encoding = cloner.Clone(original.Encoding);
41      Scope = cloner.Clone(original.Scope);
[11598]42    }
[13376]43    public CombinedSolution(IScope scope, CombinedEncoding encoding) {
[13351]44      Encoding = encoding;
45      Scope = scope;
46    }
[11598]47
[13351]48    public override IDeepCloneable Clone(Cloner cloner) {
[13356]49      return new CombinedSolution(this, cloner);
[11619]50    }
[11598]51
[16751]52    public IEncodedSolution this[string name] {
53      get { return ScopeUtil.GetEncodedSolution(Scope, name); }
54      set { ScopeUtil.CopyEncodedSolutionToScope(Scope, name, value); }
[11598]55    }
56
[13351]57    public TEncoding GetEncoding<TEncoding>() where TEncoding : IEncoding {
[11813]58      TEncoding encoding;
59      try {
60        encoding = (TEncoding)Encoding.Encodings.SingleOrDefault(e => e is TEncoding);
[11885]61      } catch (InvalidOperationException) {
[13351]62        throw new InvalidOperationException(string.Format("The solution uses multiple {0} .", typeof(TEncoding).GetPrettyName()));
[11813]63      }
[13351]64      if (encoding == null) throw new InvalidOperationException(string.Format("The solution does not use a {0}.", typeof(TEncoding).GetPrettyName()));
[11813]65      return encoding;
66    }
67
[16751]68    public TEncodedSolution GetEncodedSolution<TEncodedSolution>(string name) where TEncodedSolution : class, IEncodedSolution {
69      return (TEncodedSolution)ScopeUtil.GetEncodedSolution(Scope, name);
[11598]70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.