#region License Information /* HeuristicLab * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Collections.Generic; using System.Linq; using HEAL.Attic; using HeuristicLab.Common; using HeuristicLab.Core; namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms { [Item("Population Context", "A context for population-based algorithms.")] [StorableType("2FF3BB92-80E9-4463-B05A-5D36B76873A6")] public abstract class PopulationContext : StochasticContext where TSolutionScope: class, IScope { public IEnumerable Population { get { return Scope.SubScopes.OfType(); } } public void AddToPopulation(TSolutionScope solScope) { Scope.SubScopes.Add(solScope); } public void ReplaceAtPopulation(int index, TSolutionScope solScope) { Scope.SubScopes[index] = solScope; } public void ReplacePopulation(IEnumerable replacement) { Scope.SubScopes.Replace(replacement); } public TSolutionScope AtPopulation(int index) { return Scope.SubScopes[index] as TSolutionScope; } public TSolutionScope AtRandomPopulation() { return Scope.SubScopes[Random.Next(PopulationCount)] as TSolutionScope; } public int PopulationCount { get { return Scope.SubScopes.Count; } } [StorableConstructor] protected PopulationContext(StorableConstructorFlag _) : base(_) { } protected PopulationContext(PopulationContext original, Cloner cloner) : base(original, cloner) { } protected PopulationContext() : base() { } protected PopulationContext(string name) : base(name) { } protected PopulationContext(string name, ParameterCollection parameters) : base(name, parameters) { } protected PopulationContext(string name, string description) : base(name, description) { } protected PopulationContext(string name, string description, ParameterCollection parameters) : base(name, description, parameters) { } } }