Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2936_GQAPIntegration/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Infrastructure/Contexts/PopulationContext.cs @ 16712

Last change on this file since 16712 was 16712, checked in by gkronber, 5 years ago

#2936: adapted branch to new persistence (works with HL trunk r16711)

File size: 2.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2017 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 HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HEAL.Attic;
28
29namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms {
30  [Item("Population Context", "A context for population-based algorithms.")]
31  [StorableType("328AF409-9ECE-4E59-A842-ABBD98CBE386")]
32  public abstract class PopulationContext<TSolutionScope> : StochasticContext
33    where TSolutionScope: class, IScope {
34
35    public IEnumerable<TSolutionScope> Population {
36      get { return Scope.SubScopes.OfType<TSolutionScope>(); }
37    }
38    public void AddToPopulation(TSolutionScope solScope) {
39      Scope.SubScopes.Add(solScope);
40    }
41    public void ReplaceAtPopulation(int index, TSolutionScope solScope) {
42      Scope.SubScopes[index] = solScope;
43    }
44    public void ReplacePopulation(IEnumerable<TSolutionScope> replacement) {
45      Scope.SubScopes.Replace(replacement);
46    }
47    public TSolutionScope AtPopulation(int index) {
48      return Scope.SubScopes[index] as TSolutionScope;
49    }
50    public TSolutionScope AtRandomPopulation() {
51      return Scope.SubScopes[Random.Next(PopulationCount)] as TSolutionScope;
52    }
53    public int PopulationCount {
54      get { return Scope.SubScopes.Count; }
55    }
56
57
58    [StorableConstructor]
59    protected PopulationContext(StorableConstructorFlag _) : base(_) { }
60    protected PopulationContext(PopulationContext<TSolutionScope> original, Cloner cloner)
61      : base(original, cloner) {
62    }
63    protected PopulationContext() : base() { }
64    protected PopulationContext(string name) : base(name) { }
65    protected PopulationContext(string name, ParameterCollection parameters) : base(name, parameters) { }
66    protected PopulationContext(string name, string description) : base(name, description) { }
67    protected PopulationContext(string name, string description, ParameterCollection parameters) : base(name, description, parameters) { }
68  }
69}
Note: See TracBrowser for help on using the repository browser.