#region License Information /* HeuristicLab * Copyright (C) 2002-2019 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 HEAL.Attic; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using System.Collections.Generic; namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { [Item("SucsessMap", "A map of models of models of models")] [StorableType("3880BA82-4CB0-4838-A17A-823E91BC046C")] public class EMMSucsessMap : EMMMapBase { [Storable] public SelfConfiguration SelfConfigurationMechanism { get; private set; } #region constructors [StorableConstructor] protected EMMSucsessMap(StorableConstructorFlag _) : base(_) { } public override IDeepCloneable Clone(Cloner cloner) { return new EMMSucsessMap(this, cloner); } public EMMSucsessMap() : base() { ModelSet = new List(); SelfConfigurationMechanism = new SelfConfiguration(); } public EMMSucsessMap(EMMSucsessMap original, Cloner cloner) : base(original, cloner) { SelfConfigurationMechanism = new SelfConfiguration(original.SelfConfigurationMechanism, cloner); } #endregion #region Map Creation override public void CreateMap(IRandom random) { if (Map != null) { Map.Clear(); } Map.Add(new List()); MapSizeCheck(ModelSet.Count); ApplySucsessMapCreationAlgorithm(random, ModelSet.Count); } override public void MapRead(IEnumerable trees) { base.MapRead(trees); string fileName = ("Map" + DistanceParametr + ".txt"); SelfConfigurationMechanism.ReadFromFile(ModelSet.Count, fileName); } override public string[] MapToStoreInFile() { // Function that prepare Map to printing in .txt File: create a set of strings for future reading by computer string[] s; s = new string[1]; for (int i = 0; i < Map.Count; i++) { s[0] = ""; s[0] += SelfConfigurationMechanism.Probabilities[i].ToString(); } return s; } private void ApplySucsessMapCreationAlgorithm(IRandom random, int mapSize) { for (int t = 0; t < mapSize; t++) { Map[t].Add(t); } SelfConfigurationMechanism.Initialization(mapSize); } public override void MapUpDate(Dictionary population) { SelfConfigurationMechanism.UpDate(population); } #endregion #region Map Apply Functions public override ISymbolicExpressionTree NewModelForMutation(IRandom random, out int treeNumber, int parentTreeNumber) { treeNumber = Map[SelfConfigurationMechanism.Aplay(random)][0]; return (ISymbolicExpressionTree)ModelSet[treeNumber].Clone(); } override public ISymbolicExpressionTree NewModelForInizializtionNotTree(IRandom random, out int treeNumber) { return NewModelForInizializtion(random, out treeNumber); } #endregion } }