Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/InteractionInitializers/RandomInteractionsInitializer.cs @ 11571

Last change on this file since 11571 was 7128, checked in by epitzer, 13 years ago

#1696 Integrate fitness landscape analysis plugins from Heureka! repository.

File size: 1.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.Common;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9
10namespace HeuristicLab.Problems.NK {
11
12  [Item("RandomInteractionsInitializer", "Randomly assignes interactions across all bits")]
13  [StorableClass]
14  public class RandomInteractionsInitializer : NamedItem, IInteractionInitializer {
15
16    public override bool CanChangeName { get { return false; } }
17    public override bool CanChangeDescription { get { return false; } }
18
19
20    [StorableConstructor]
21    protected RandomInteractionsInitializer(bool serializing) : base(serializing) { }
22    protected RandomInteractionsInitializer(RandomInteractionsInitializer original, Cloner cloner) : base(original, cloner) { }
23    public RandomInteractionsInitializer() {
24      name = ItemName;
25      description = ItemDescription;
26    }
27    public override IDeepCloneable Clone(Cloner cloner) {
28      return new RandomInteractionsInitializer(this, cloner);
29    }
30
31    #region IInteractionInitializer Members
32    public BoolMatrix InitializeInterations(int length, int nComponents, int nInteractions, IRandom random) {
33      BoolMatrix m = new BoolMatrix(length, nComponents);
34      for (int c = 0; c<m.Columns; c++) {
35        var indices = Enumerable.Range(0, length).ToList();
36        if (indices.Count > c) {
37          indices.RemoveAt(c);
38          m[c, c] = true;
39        }
40        while (indices.Count > nInteractions) {
41          indices.RemoveAt(random.Next(indices.Count));
42        }
43        foreach (var i in indices) {
44          m[i, c] = true;
45        }
46      }
47      return m;     
48    }
49    #endregion
50  }
51}
Note: See TracBrowser for help on using the repository browser.