#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 HeuristicLab.Random; using System.Collections.Generic; using System.Linq; namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { [Item("IslandMap", "A map of models of models of models")] [StorableType("E4AB04B9-FD5D-47EE-949D-243660754F3A")] public class EMMIslandMap : EMMMapBase { [Storable] public List ClusterNumber { get; set; } // May be only Island Map really need it #region conctructors [StorableConstructor] protected EMMIslandMap(StorableConstructorFlag _) : base(_) { } public EMMIslandMap() { ModelSet = new List(); ClusterNumber = new List(); } public override IDeepCloneable Clone(Cloner cloner) { return new EMMIslandMap(this, cloner); } public EMMIslandMap(EMMIslandMap original, Cloner cloner) : base(original, cloner) { if (original.ClusterNumber != null) { ClusterNumber = original.ClusterNumber.ToList(); } } #endregion #region MapApplayFunctions override public void CreateMap(IRandom random, int k) { k = EMModelsClusterizationAlgorithm.ApplyClusteringAlgorithm(random, CalculateDistances(), ClusterNumber, k); MapSizeCheck(k); for (int i = 0; i < ModelSet.Count; i++) { Map[ClusterNumber[i]].Add(i); } } override public ISymbolicExpressionTree NewModelForInizializtionNotTree(IRandom random, out int treeNumber) { return NewModelForInizializtion(random, out treeNumber); } public override ISymbolicExpressionTree NewModelForMutation(IRandom random, out int treeNumber, int parentTreeNumber) { if (parentTreeNumber == -10) { treeNumber = random.Next(ModelSet.Count); } else { treeNumber = Map[ClusterNumber[parentTreeNumber]].SampleRandom(random); } return (ISymbolicExpressionTree)ModelSet[treeNumber].Clone(); } public void ClusterNumbersCalculate() { // May be it should be transported to Child Clase (IslandMap) for (int i = 0; i < Map.Count; i++) { for (int j = 0; j < Map[i].Count; j++) { ClusterNumber.Add(0); } } for (int i = 0; i < Map.Count; i++) { for (int j = 0; j < Map[i].Count; j++) { ClusterNumber[Map[i][j]] = i; } } } #endregion } }