[17002] | 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 HeuristicLab.Core;
|
---|
[16899] | 22 | using System.Collections.Generic;
|
---|
| 23 | using System.Linq;
|
---|
| 24 |
|
---|
| 25 | namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels {
|
---|
| 26 | class HelpFunctions {
|
---|
[17002] | 27 | public static int OneElementFromListProportionalSelection(IRandom random, List<double> list) {
|
---|
| 28 | double selectedQuality = random.NextDouble() * list.Sum();
|
---|
| 29 | int index = 0;
|
---|
| 30 | double currentQuality = list[index];
|
---|
| 31 | while ((currentQuality < selectedQuality) && (index < list.Count)) {
|
---|
| 32 | index++;
|
---|
| 33 | currentQuality += list[index];
|
---|
| 34 | }
|
---|
| 35 | return index;
|
---|
| 36 | }
|
---|
[16899] | 37 | public static int ChooseMinElementIndex(List<double> distances, int currentElement, List<int> previousNumbers) {
|
---|
| 38 | double minValue = 100;
|
---|
| 39 | int minElementNumber = 0;
|
---|
| 40 | int temp = 0, i = 0;
|
---|
| 41 | while (temp == 0) {
|
---|
| 42 | if ((currentElement != i) && (!CheckNumberIsInList(i, previousNumbers))) {
|
---|
| 43 | minValue = distances[i];
|
---|
| 44 | minElementNumber = i;
|
---|
| 45 | temp = i;
|
---|
| 46 | }
|
---|
| 47 | i++;
|
---|
| 48 | }
|
---|
| 49 | for (i = 0; i < distances.Count(); i++) {
|
---|
| 50 | if ((distances[i] < minValue) && (currentElement != i) && (!CheckNumberIsInList(i, previousNumbers))) {
|
---|
| 51 | minValue = distances[i];
|
---|
| 52 | minElementNumber = i;
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 | return minElementNumber;
|
---|
| 56 | }
|
---|
[17002] | 57 |
|
---|
[16899] | 58 | public static bool CheckNumberIsInList(int number, List<int> priviousNumber) {
|
---|
| 59 | foreach (var pNum in priviousNumber) {
|
---|
| 60 | if (number == pNum)
|
---|
| 61 | return true;
|
---|
| 62 | }
|
---|
| 63 | return false;
|
---|
| 64 | }
|
---|
| 65 | public static int ChooseMinElementIndex(List<double> averageClusterDistance) {
|
---|
| 66 | double minValue = averageClusterDistance[0];
|
---|
| 67 | int minElementNumber = 0;
|
---|
| 68 | for (int i = 1; i < averageClusterDistance.Count(); i++) {
|
---|
| 69 | if (averageClusterDistance[i] < minValue) {
|
---|
| 70 | minValue = averageClusterDistance[i];
|
---|
| 71 | minElementNumber = i;
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | return minElementNumber;
|
---|
| 75 | }
|
---|
[17002] | 76 | public static int ChooseMaxElementIndex(List<double> averageClusterDistance) {
|
---|
| 77 | double maxValue = averageClusterDistance[0];
|
---|
| 78 | int maxElementNumber = 0;
|
---|
| 79 | for (int i = 1; i < averageClusterDistance.Count(); i++) {
|
---|
| 80 | if (averageClusterDistance[i] > maxValue) {
|
---|
| 81 | maxValue = averageClusterDistance[i];
|
---|
| 82 | maxElementNumber = i;
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | return maxElementNumber;
|
---|
| 86 | }
|
---|
| 87 | public static double CheckSocialKatre(double socialKarteValue, double value, double stepValue) {
|
---|
| 88 | if (value > (socialKarteValue + stepValue))
|
---|
| 89 | return stepValue;
|
---|
| 90 | else if (value > socialKarteValue)
|
---|
| 91 | return (value - socialKarteValue);
|
---|
| 92 | else return 0;
|
---|
| 93 | }
|
---|
| 94 | public static void ProbabilitiesUpDate(List<List<double>> sucsessStatistics, List<double> probabilities) {
|
---|
| 95 |
|
---|
| 96 | var averageQuality = new List<double>();
|
---|
| 97 | foreach (var variant in sucsessStatistics) {
|
---|
| 98 | if (variant[0] > 0.005) {
|
---|
| 99 | averageQuality.Add(variant[1] / variant[0]);
|
---|
| 100 | } else { averageQuality.Add(0); }
|
---|
| 101 | }
|
---|
| 102 | int bestModelNumber = ChooseMaxElementIndex(averageQuality);
|
---|
| 103 | double socialKarte = 1.0 / (probabilities.Count * 20.0); // parameters of method
|
---|
| 104 | double stepValue = socialKarte / 5.0;
|
---|
| 105 | double totalChangeValue = 0, changeValue = 0;
|
---|
| 106 | for (int i = 0; i < probabilities.Count; i++) {
|
---|
| 107 | changeValue = CheckSocialKatre(socialKarte, probabilities[i], stepValue);
|
---|
| 108 | totalChangeValue += changeValue;
|
---|
| 109 | probabilities[i] -= changeValue;
|
---|
| 110 | }
|
---|
| 111 | probabilities[bestModelNumber] += totalChangeValue;
|
---|
| 112 | }
|
---|
[16899] | 113 | }
|
---|
| 114 | }
|
---|