Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Infrastructure/Contexts/PopulationContext.cs

Last change on this file was 16728, checked in by abeham, 6 years ago

#1614: updated to new persistence and .NET 4.6.1

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 HEAL.Attic;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27
28namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms {
29  [Item("Population Context", "A context for population-based algorithms.")]
30  [StorableType("2FF3BB92-80E9-4463-B05A-5D36B76873A6")]
31  public abstract class PopulationContext<TSolutionScope> : StochasticContext
32    where TSolutionScope: class, IScope {
33
34    public IEnumerable<TSolutionScope> Population {
35      get { return Scope.SubScopes.OfType<TSolutionScope>(); }
36    }
37    public void AddToPopulation(TSolutionScope solScope) {
38      Scope.SubScopes.Add(solScope);
39    }
40    public void ReplaceAtPopulation(int index, TSolutionScope solScope) {
41      Scope.SubScopes[index] = solScope;
42    }
43    public void ReplacePopulation(IEnumerable<TSolutionScope> replacement) {
44      Scope.SubScopes.Replace(replacement);
45    }
46    public TSolutionScope AtPopulation(int index) {
47      return Scope.SubScopes[index] as TSolutionScope;
48    }
49    public TSolutionScope AtRandomPopulation() {
50      return Scope.SubScopes[Random.Next(PopulationCount)] as TSolutionScope;
51    }
52    public int PopulationCount {
53      get { return Scope.SubScopes.Count; }
54    }
55
56
57    [StorableConstructor]
58    protected PopulationContext(StorableConstructorFlag _) : base(_) { }
59    protected PopulationContext(PopulationContext<TSolutionScope> original, Cloner cloner)
60      : base(original, cloner) {
61    }
62    protected PopulationContext() : base() { }
63    protected PopulationContext(string name) : base(name) { }
64    protected PopulationContext(string name, ParameterCollection parameters) : base(name, parameters) { }
65    protected PopulationContext(string name, string description) : base(name, description) { }
66    protected PopulationContext(string name, string description, ParameterCollection parameters) : base(name, description, parameters) { }
67  }
68}
Note: See TracBrowser for help on using the repository browser.