Changeset 12566 for branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/InteractionInitializers
- Timestamp:
- 07/01/15 15:32:22 (9 years ago)
- Location:
- branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/InteractionInitializers
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/InteractionInitializers/IInteractionInitializer.cs
r7128 r12566 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2015 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 5 22 using HeuristicLab.Core; 6 23 using HeuristicLab.Data; -
branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/InteractionInitializers/IncreasingBlockSizeInteractionsInitializer.cs
r7128 r12566 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2015 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 2 22 using System.Collections.Generic; 3 23 using System.Linq; 4 using System.Text;24 using HeuristicLab.Common; 5 25 using HeuristicLab.Core; 6 26 using HeuristicLab.Data; 7 using HeuristicLab. Common;27 using HeuristicLab.Encodings.BinaryVectorEncoding; 8 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 9 using HeuristicLab.Encodings.BinaryVectorEncoding;10 using HeuristicLab.Parameters;11 using HeuristicLab.PluginInfrastructure;12 29 13 30 namespace HeuristicLab.Problems.NK { … … 15 32 [Item("IncreasingBlockSizeInteractionsInitializer", "Randomly assignes interactions across all bits but makes sure that different numbers of ineractions are applied to different bits.")] 16 33 [StorableClass] 17 public class IncreasingBlockSizeInteractionsInitializer : ParameterizedNamedItem, IInteractionInitializer { 18 34 public class IncreasingBlockSizeInteractionsInitializer : ParameterizedNamedItem, IInteractionInitializer { 35 19 36 [StorableConstructor] 20 37 protected IncreasingBlockSizeInteractionsInitializer(bool serializing) : base(serializing) { } 21 38 protected IncreasingBlockSizeInteractionsInitializer(IncreasingBlockSizeInteractionsInitializer original, Cloner cloner) : base(original, cloner) { } 22 public IncreasingBlockSizeInteractionsInitializer() { 39 public IncreasingBlockSizeInteractionsInitializer() { 23 40 } 24 41 25 42 26 43 public override IDeepCloneable Clone(Cloner cloner) { 27 44 return new IncreasingBlockSizeInteractionsInitializer(this, cloner); 28 } 45 } 29 46 30 47 #region IInteractionInitializer Members 31 48 public BoolMatrix InitializeInterations(int length, int nComponents, int nInteractions, IRandom random) { 32 49 Dictionary<int, int> bitInteractionCounts = new Dictionary<int, int>(); 33 for (int i = 0; i <length; i++) {34 int count = nInteractions *2*i/length;50 for (int i = 0; i < length; i++) { 51 int count = nInteractions * 2 * i / length; 35 52 if (count > 0) 36 53 bitInteractionCounts[i] = count; … … 39 56 while (bitInteractionCounts.Count > 0) { 40 57 BinaryVector component = new BinaryVector(length); 41 for (int i = 0; i <nInteractions; i++) {58 for (int i = 0; i < nInteractions; i++) { 42 59 while (bitInteractionCounts.Count > 0) { 43 60 int bit = bitInteractionCounts.ElementAt(random.Next(bitInteractionCounts.Count)).Key; … … 48 65 break; 49 66 } 50 } 67 } 51 68 } 52 69 components.Add(component); 53 } 70 } 54 71 BoolMatrix m = new BoolMatrix(length, components.Count); 55 foreach (var c in components.Select((v, j) => new { v, j})) {56 for (int i = 0; i <c.v.Length; i++) {72 foreach (var c in components.Select((v, j) => new { v, j })) { 73 for (int i = 0; i < c.v.Length; i++) { 57 74 m[i, c.j] = c.v[i]; 58 } 75 } 59 76 } 60 77 return m; -
branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/InteractionInitializers/LimitedRandomInteractionsInitializer.cs
r7128 r12566 1 using System; 2 using System.Collections.Generic; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2015 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 22 using System; 3 23 using System.Linq; 4 using System.Text;24 using HeuristicLab.Common; 5 25 using HeuristicLab.Core; 6 26 using HeuristicLab.Data; 7 using HeuristicLab. Common;27 using HeuristicLab.Parameters; 8 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 9 using HeuristicLab.Encodings.BinaryVectorEncoding;10 using HeuristicLab.Parameters;11 using HeuristicLab.PluginInfrastructure;12 29 13 30 namespace HeuristicLab.Problems.NK { … … 34 51 public ValueParameter<DoubleValue> MaximumDistanceRatioParameter { 35 52 get { return (ValueParameter<DoubleValue>)Parameters["MaximumDistanceRatio"]; } 36 } 53 } 37 54 38 55 private int MaximumDistance(int length, int nInteractions) { 39 56 int maxBitDist = MaximumDistanceParameter.Value.Value; 40 57 double maxDistRatio = MaximumDistanceRatioParameter.Value.Value; 41 maxBitDist = 58 maxBitDist = Math.Min( 42 59 maxBitDist == 0 ? length : maxBitDist, 43 maxDistRatio == 0 ? length : (int)Math.Round(maxDistRatio *length));60 maxDistRatio == 0 ? length : (int)Math.Round(maxDistRatio * length)); 44 61 if (maxBitDist * 2 < nInteractions) 45 62 maxBitDist = (int)Math.Ceiling(0.5 * nInteractions); 46 63 return maxBitDist; 47 } 48 64 } 65 49 66 [StorableConstructor] 50 67 protected LimitedRandomInteractionsInitializer(bool serializing) : base(serializing) { } … … 54 71 Parameters.Add(new ValueParameter<DoubleValue>("MaximumDistanceRatio", "Maximum distance of interactions as ratio of the total length or 0 for unlimited")); 55 72 } 56 73 57 74 public override IDeepCloneable Clone(Cloner cloner) { 58 75 return new LimitedRandomInteractionsInitializer(this, cloner); 59 } 76 } 60 77 61 78 #region IInteractionInitializer Members … … 63 80 BoolMatrix m = new BoolMatrix(length, nComponents); 64 81 int maxBitDistance = MaximumDistance(length, nInteractions); 65 var minBounds = new Bounds(0, length -nInteractions);66 var maxBounds = new Bounds(nInteractions, length -1);67 for (int c = 0; c <m.Columns; c++) {68 int min = minBounds.bounded(c -maxBitDistance);69 int max = maxBounds.bounded(c +maxBitDistance);70 var indices = Enumerable.Range(min, max -min).ToList();82 var minBounds = new Bounds(0, length - nInteractions); 83 var maxBounds = new Bounds(nInteractions, length - 1); 84 for (int c = 0; c < m.Columns; c++) { 85 int min = minBounds.bounded(c - maxBitDistance); 86 int max = maxBounds.bounded(c + maxBitDistance); 87 var indices = Enumerable.Range(min, max - min).ToList(); 71 88 indices.Remove(c); 72 m[c, c] = true; 89 m[c, c] = true; 73 90 while (indices.Count > nInteractions) { 74 91 indices.RemoveAt(random.Next(indices.Count)); … … 78 95 } 79 96 } 80 return m; 97 return m; 81 98 } 82 99 #endregion -
branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/InteractionInitializers/RandomInteractionsInitializer.cs
r7128 r12566 1 using System; 2 using System.Collections.Generic; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2015 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 3 22 using System.Linq; 4 using System.Text;23 using HeuristicLab.Common; 5 24 using HeuristicLab.Core; 6 25 using HeuristicLab.Data; 7 using HeuristicLab.Common;8 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 9 27 … … 32 50 public BoolMatrix InitializeInterations(int length, int nComponents, int nInteractions, IRandom random) { 33 51 BoolMatrix m = new BoolMatrix(length, nComponents); 34 for (int c = 0; c <m.Columns; c++) {52 for (int c = 0; c < m.Columns; c++) { 35 53 var indices = Enumerable.Range(0, length).ToList(); 36 54 if (indices.Count > c) { … … 45 63 } 46 64 } 47 return m; 65 return m; 48 66 } 49 67 #endregion -
branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/InteractionInitializers/SortedRandomInteractionsInitializer.cs
r8172 r12566 1 using System.Linq; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2015 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 22 using System.Linq; 2 23 using HeuristicLab.Common; 3 24 using HeuristicLab.Core;
Note: See TracChangeset
for help on using the changeset viewer.