1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2019 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 | using HEAL.Attic;
|
---|
22 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
25 | using System.Collections.Generic;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels {
|
---|
28 | [Item("SucsessMap", "A map of models of models of models")]
|
---|
29 | [StorableType("3880BA82-4CB0-4838-A17A-823E91BC046C")]
|
---|
30 | public class EMMSucsessMap : EMMMapBase<ISymbolicExpressionTree> {
|
---|
31 | [Storable]
|
---|
32 | public SelfConfiguration SelfConfigurationMechanism { get; private set; }
|
---|
33 | #region constructors
|
---|
34 | [StorableConstructor]
|
---|
35 | protected EMMSucsessMap(StorableConstructorFlag _) : base(_) { }
|
---|
36 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
37 | return new EMMSucsessMap(this, cloner);
|
---|
38 | }
|
---|
39 | public EMMSucsessMap() : base() {
|
---|
40 | ModelSet = new List<ISymbolicExpressionTree>();
|
---|
41 | SelfConfigurationMechanism = new SelfConfiguration();
|
---|
42 | }
|
---|
43 | public EMMSucsessMap(EMMSucsessMap original, Cloner cloner) : base(original, cloner) {
|
---|
44 | SelfConfigurationMechanism = new SelfConfiguration(original.SelfConfigurationMechanism, cloner);
|
---|
45 | }
|
---|
46 | #endregion
|
---|
47 | #region Map Creation
|
---|
48 | override public void CreateMap(IRandom random) {
|
---|
49 | if (Map != null) {
|
---|
50 | Map.Clear();
|
---|
51 | }
|
---|
52 | Map.Add(new List<int>());
|
---|
53 | MapSizeCheck(ModelSet.Count);
|
---|
54 | ApplySucsessMapCreationAlgorithm(random, ModelSet.Count);
|
---|
55 | }
|
---|
56 | override public void MapRead(IEnumerable<ISymbolicExpressionTree> trees) {
|
---|
57 | base.MapRead(trees);
|
---|
58 | string fileName = ("Map" + DistanceParametr + ".txt");
|
---|
59 | SelfConfigurationMechanism.ReadFromFile(ModelSet.Count, fileName);
|
---|
60 | }
|
---|
61 | override public string[] MapToStoreInFile() { // Function that prepare Map to printing in .txt File: create a set of strings for future reading by computer
|
---|
62 | string[] s;
|
---|
63 | s = new string[1];
|
---|
64 | for (int i = 0; i < Map.Count; i++) {
|
---|
65 | s[0] = "";
|
---|
66 | s[0] += SelfConfigurationMechanism.Probabilities[i].ToString();
|
---|
67 | }
|
---|
68 | return s;
|
---|
69 | }
|
---|
70 | private void ApplySucsessMapCreationAlgorithm(IRandom random, int mapSize) {
|
---|
71 | for (int t = 0; t < mapSize; t++) {
|
---|
72 | Map[t].Add(t);
|
---|
73 | }
|
---|
74 | SelfConfigurationMechanism.Initialization(mapSize);
|
---|
75 | }
|
---|
76 | public override void MapUpDate(Dictionary<ISymbolicExpressionTree, double> population) {
|
---|
77 | SelfConfigurationMechanism.UpDate(population);
|
---|
78 | }
|
---|
79 | #endregion
|
---|
80 | #region Map Apply Functions
|
---|
81 | public override ISymbolicExpressionTree NewModelForMutation(IRandom random, out int treeNumber, int parentTreeNumber) {
|
---|
82 | treeNumber = Map[SelfConfigurationMechanism.Aplay(random)][0];
|
---|
83 | return (ISymbolicExpressionTree)ModelSet[treeNumber].Clone();
|
---|
84 | }
|
---|
85 | override public ISymbolicExpressionTree NewModelForInizializtionNotTree(IRandom random, out int treeNumber) {
|
---|
86 | return NewModelForInizializtion(random, out treeNumber);
|
---|
87 | }
|
---|
88 | #endregion
|
---|
89 | }
|
---|
90 | }
|
---|