Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/CombinedSolution.cs @ 15301

Last change on this file since 15301 was 13376, checked in by abeham, 9 years ago

#2521: working on refactoring

File size: 2.7 KB
RevLine 
[11598]1#region License Information
2/* HeuristicLab
[12012]3 * Copyright (C) 2002-2015 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;
[11813]24using HeuristicLab.Common;
[11598]25using HeuristicLab.Core;
[13351]26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[11598]27
[11949]28namespace HeuristicLab.Optimization {
[13356]29  [Item("CombinedSolution", "A solution that consists of other solutions.")]
[13351]30  [StorableClass]
[13356]31  public sealed class CombinedSolution : Item, ISolution {
[11598]32
[13376]33    private CombinedEncoding Encoding { get; set; }
34    private IScope Scope { get; set; }
[11737]35
[13351]36    [StorableConstructor]
[13356]37    private CombinedSolution(bool deserializing) : base(deserializing) { }
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
[13351]52    public ISolution this[string name] {
[13359]53      get { return ScopeUtil.GetSolution(Scope, name); }
54      set { ScopeUtil.CopySolutionToScope(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
[13359]68    public TSolution GetSolution<TSolution>(string name) where TSolution : class, ISolution {
69      return (TSolution)ScopeUtil.GetSolution(Scope, name);
[11598]70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.