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 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.Linq;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms {
|
---|
29 | [Item("Population Context", "A context for population-based algorithms.")]
|
---|
30 | [StorableClass]
|
---|
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(bool deserializing) : base(deserializing) { }
|
---|
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 | }
|
---|