Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12573


Ignore:
Timestamp:
07/02/15 12:50:44 (9 years ago)
Author:
ascheibe
Message:

#2306 hopefully fixed random number generation problem

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/NKLandscape.cs

    r12569 r12573  
    4848      get { return (IValueParameter<BoolMatrix>)Parameters["GeneInteractions"]; }
    4949    }
     50    public IValueParameter<IntValue> SeedParameter {
     51      get { return (IValueParameter<IntValue>)Parameters["Seed"]; }
     52    }
    5053    public IValueParameter<IntValue> InteractionSeedParameter {
    5154      get { return (IValueParameter<IntValue>)Parameters["InteractionSeed"]; }
     
    9093      get { return WeightsInitializerParameter.Value; }
    9194    }
    92     #endregion
    93 
    94     [ThreadStatic]
    95     private static MersenneTwister random;
    96     public static MersenneTwister Random {
    97       get {
    98         if (random == null) {
    99           random = new MersenneTwister();
    100         }
    101         return random;
    102       }
    103     }
     95    public IntValue Seed {
     96      get { return SeedParameter.Value; }
     97    }
     98    #endregion
     99
     100    [Storable]
     101    private MersenneTwister random;
    104102
    105103    [ThreadStatic]
     
    119117    private NKLandscape(NKLandscape original, Cloner cloner)
    120118      : base(original, cloner) {
     119      random = (MersenneTwister)original.random.Clone(cloner);
    121120      RegisterEventHandlers();
    122121    }
    123122    public NKLandscape()
    124123      : base() {
     124      random = new MersenneTwister();
     125
    125126      Parameters.Add(new ValueParameter<BoolMatrix>("GeneInteractions", "Every column gives the participating genes for each fitness component"));
    126       Parameters.Add(new ValueParameter<IntValue>("InteractionSeed", "The seed used for the hash function to generate interaction tables.", new IntValue(Random.Next())));
     127      Parameters.Add(new ValueParameter<IntValue>("Seed", "The seed used for the random number generator.", new IntValue(0)));
     128      random.Reset(Seed.Value);
     129
     130      Parameters.Add(new ValueParameter<IntValue>("InteractionSeed", "The seed used for the hash function to generate interaction tables.", new IntValue(random.Next())));
    127131      Parameters.Add(new ValueParameter<IntValue>("NrOfFitnessComponents", "Number of fitness component functions. (nr of columns in the interaction column)", new IntValue(10)));
    128132      Parameters.Add(new ValueParameter<IntValue>("NrOfInteractions", "Number of genes interacting with each other. (nr of True values per column in the interaction matrix)", new IntValue(3)));
     
    175179      InteractionInitializerParameter.ValueChanged += InteractionInitializerParameter_ValueChanged;
    176180      WeightsInitializerParameter.ValueChanged += WeightsInitializerParameter_ValueChanged;
     181      SeedParameter.ValueChanged += SeedParameter_ValueChanged;
     182      SeedParameter.Value.ValueChanged += SeedParameter_ValueChanged;
     183    }
     184
     185    private void SeedParameter_ValueChanged(object sender, EventArgs e) {
     186      random.Reset(Seed.Value);
     187      InteractionSeed.Value = random.Next();
     188      InitializeInteractions();
    177189    }
    178190
     
    200212          Length,
    201213          NrOfFitnessComponents.Value,
    202           NrOfInteractions.Value, Random);
     214          NrOfInteractions.Value, random);
    203215    }
    204216
Note: See TracChangeset for help on using the changeset viewer.