#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 HeuristicLab.Core; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.Problems.DataAnalysis.Symbolic; using HeuristicLab.Random; using System.Collections.Generic; using System.Linq; namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { class HelpFunctions { public static int OneElementFromListProportionalSelection(IRandom random, List list) { double selectedQuality = random.NextDouble() * list.Sum(); int index = 0; double currentQuality = list[index]; while ((currentQuality < selectedQuality) && (index < list.Count)) { index++; currentQuality += list[index]; } return index; } public static int ChooseMinElementIndex(List distances, int currentElement, List previousNumbers) { double minValue = 100; int minElementNumber = 0; int temp = 0, i = 0; while (temp == 0) { if ((currentElement != i) && (!CheckNumberIsInList(i, previousNumbers))) { minValue = distances[i]; minElementNumber = i; temp = i; } i++; } for (i = 0; i < distances.Count(); i++) { if ((distances[i] < minValue) && (currentElement != i) && (!CheckNumberIsInList(i, previousNumbers))) { minValue = distances[i]; minElementNumber = i; } } return minElementNumber; } public static bool CheckNumberIsInList(int number, List priviousNumber) { foreach (var pNum in priviousNumber) { if (number == pNum) return true; } return false; } public static int ChooseMinElementIndex(List averageClusterDistance) { double minValue = averageClusterDistance[0]; int minElementNumber = 0; for (int i = 1; i < averageClusterDistance.Count(); i++) { if (averageClusterDistance[i] < minValue) { minValue = averageClusterDistance[i]; minElementNumber = i; } } return minElementNumber; } public static int ChooseMaxElementIndex(List averageClusterDistance) { double maxValue = averageClusterDistance[0]; int maxElementNumber = 0; for (int i = 1; i < averageClusterDistance.Count(); i++) { if (averageClusterDistance[i] > maxValue) { maxValue = averageClusterDistance[i]; maxElementNumber = i; } } return maxElementNumber; } public static void SetLocalParametersForTree(IRandom random, double shakingFactor, ISymbolicExpressionTree tree) { foreach (var node in tree.IterateNodesPrefix().Where(x => x.HasLocalParameters)) { if (node is VariableTreeNode variableTreeNode) { var symbol = variableTreeNode.Symbol; variableTreeNode.Weight = NormalDistributedRandom.NextDouble(random, symbol.WeightManipulatorMu, symbol.WeightManipulatorSigma); } else { node.ResetLocalParameters(random); } } } } }