Permalink
Browse files

Adding in MersenneTwister as a random number generator

  • Loading branch information...
philmcminn committed Jan 10, 2017
1 parent e6de380 commit 2897a0de692eb67b1100865c35cabf074cd29d28
Showing with 140 additions and 122 deletions.
  1. +1 −0 iguana.config
  2. +4 −4 src/main/java/org/iguanatool/Run.java
  3. +10 −10 src/main/java/org/iguanatool/search/SearchFactory.java
  4. +3 −3 src/main/java/org/iguanatool/search/local/neighbourhoodsearch/CachedNeighbourhoodSearch.java
  5. +2 −2 src/main/java/org/iguanatool/search/local/neighbourhoodsearch/Geometric_No_Bias.java
  6. +2 −2 src/main/java/org/iguanatool/search/local/neighbourhoodsearch/Geometric_Opposite_Direction_Bias.java
  7. +2 −2 src/main/java/org/iguanatool/search/local/neighbourhoodsearch/Geometric_Right_Bias.java
  8. +2 −2 src/main/java/org/iguanatool/search/local/neighbourhoodsearch/IPS_No_Bias.java
  9. +2 −2 src/main/java/org/iguanatool/search/local/neighbourhoodsearch/IPS_Right_Bias.java
  10. +2 −2 src/main/java/org/iguanatool/search/local/neighbourhoodsearch/Lattice_No_Bias.java
  11. +2 −2 src/main/java/org/iguanatool/search/local/neighbourhoodsearch/Lattice_Opposite_Direction_Bias.java
  12. +2 −2 src/main/java/org/iguanatool/search/local/neighbourhoodsearch/Lattice_Right_Bias.java
  13. +2 −2 src/main/java/org/iguanatool/search/local/neighbourhoodsearch/Random.java
  14. +0 −80 src/main/java/org/iguanatool/search/randomnumbergenerator/MersenneTwister.java
  15. +74 −0 src/main/java/org/iguanatool/search/randomnumbergenerator/MersenneTwisterRandomNumberGenerator.java
  16. +23 −0 src/main/java/org/iguanatool/search/randomnumbergenerator/RandomNumberGeneratorFactory.java
  17. +6 −6 src/main/java/org/iguanatool/testobject/JavaWrapper.java
  18. +1 −1 src/test/java/org/iguanatool/search/evolve/mutation/MuhlenbeinMutationTest.java
View
@@ -9,6 +9,7 @@ aim = branchcoverage
max_evaluations = 100000
seed = 1
input_specification_setup = default
random_number_generator = MersenneTwister
# test object assimilation
display_system_commands = true
@@ -6,9 +6,8 @@
import org.iguanatool.inputgeneration.variableinclusion.IncludeAllVariables;
import org.iguanatool.search.Search;
import org.iguanatool.search.SearchFactory;
import org.iguanatool.search.randomnumbergenerator.MersenneTwister;
import org.iguanatool.search.randomnumbergenerator.RandomNumberGenerator;
import org.iguanatool.search.randomnumbergenerator.SimpleRandomNumberGenerator;
import org.iguanatool.search.randomnumbergenerator.RandomNumberGeneratorFactory;
import org.iguanatool.testobject.TestObject;
import org.iguanatool.testobject.TestObjectFactory;
@@ -32,9 +31,10 @@ public Run(String[] configProperties) {
String aimDescription = config.getRequiredProperty("aim");
int maxEvaluations = Integer.parseInt(config.getRequiredProperty("max_evaluations"));
long seed = Long.parseLong(config.getRequiredProperty("seed"));
// initiate random number generator
RandomNumberGenerator r = new SimpleRandomNumberGenerator();
String randomNumberGenerator = config.getRequiredProperty("random_number_generator");
RandomNumberGenerator r = RandomNumberGeneratorFactory.instantiateGenerator(randomNumberGenerator);
r.setSeed(seed);
// instantiate test object loader
@@ -27,7 +27,7 @@
import org.iguanatool.search.local.restarter.RandomRestarter;
import org.iguanatool.search.local.restarter.Restarter;
import org.iguanatool.search.pso.Swarm;
import org.iguanatool.search.randomnumbergenerator.MersenneTwister;
import org.iguanatool.search.randomnumbergenerator.MersenneTwisterRandomNumberGenerator;
import org.iguanatool.search.randomnumbergenerator.RandomNumberGenerator;
import java.lang.reflect.Method;
@@ -573,55 +573,55 @@ public static Search swarmSearch(RandomNumberGenerator r, int maxEvaluations) {
public static Search randomSearch(RandomNumberGenerator r, int maxEvaluations) {
HillClimb h = new HillClimb(r, maxEvaluations);
h.setNeighbourhoodSearch(new Random((MersenneTwister) r));
h.setNeighbourhoodSearch(new Random((MersenneTwisterRandomNumberGenerator) r));
return h;
}
public static Search ips_no_biasSearch(RandomNumberGenerator r, int maxEvaluations) {
HillClimb h = new HillClimb(r, maxEvaluations);
h.setNeighbourhoodSearch(new IPS_No_Bias((MersenneTwister) r));
h.setNeighbourhoodSearch(new IPS_No_Bias((MersenneTwisterRandomNumberGenerator) r));
return h;
}
public static Search geometric_no_biasSearch(RandomNumberGenerator r, int maxEvaluations) {
HillClimb h = new HillClimb(r, maxEvaluations);
h.setNeighbourhoodSearch(new Geometric_No_Bias((MersenneTwister) r));
h.setNeighbourhoodSearch(new Geometric_No_Bias((MersenneTwisterRandomNumberGenerator) r));
return h;
}
public static Search lattice_no_biasSearch(RandomNumberGenerator r, int maxEvaluations) {
HillClimb h = new HillClimb(r, maxEvaluations);
h.setNeighbourhoodSearch(new Lattice_No_Bias((MersenneTwister) r));
h.setNeighbourhoodSearch(new Lattice_No_Bias((MersenneTwisterRandomNumberGenerator) r));
return h;
}
public static Search geometric_opposite_direction_biasSearch(RandomNumberGenerator r, int maxEvaluations) {
HillClimb h = new HillClimb(r, maxEvaluations);
h.setNeighbourhoodSearch(new Geometric_Opposite_Direction_Bias((MersenneTwister) r));
h.setNeighbourhoodSearch(new Geometric_Opposite_Direction_Bias((MersenneTwisterRandomNumberGenerator) r));
return h;
}
public static Search lattice_opposite_direction_biasSearch(RandomNumberGenerator r, int maxEvaluations) {
HillClimb h = new HillClimb(r, maxEvaluations);
h.setNeighbourhoodSearch(new Lattice_Opposite_Direction_Bias((MersenneTwister) r));
h.setNeighbourhoodSearch(new Lattice_Opposite_Direction_Bias((MersenneTwisterRandomNumberGenerator) r));
return h;
}
public static Search ips_right_biasSearch(RandomNumberGenerator r, int maxEvaluations) {
HillClimb h = new HillClimb(r, maxEvaluations);
h.setNeighbourhoodSearch(new IPS_Right_Bias((MersenneTwister) r));
h.setNeighbourhoodSearch(new IPS_Right_Bias((MersenneTwisterRandomNumberGenerator) r));
return h;
}
public static Search geometric_right_biasSearch(RandomNumberGenerator r, int maxEvaluations) {
HillClimb h = new HillClimb(r, maxEvaluations);
h.setNeighbourhoodSearch(new Geometric_Right_Bias((MersenneTwister) r));
h.setNeighbourhoodSearch(new Geometric_Right_Bias((MersenneTwisterRandomNumberGenerator) r));
return h;
}
public static Search lattice_right_biasSearch(RandomNumberGenerator r, int maxEvaluations) {
HillClimb h = new HillClimb(r, maxEvaluations);
h.setNeighbourhoodSearch(new Lattice_Right_Bias((MersenneTwister) r));
h.setNeighbourhoodSearch(new Lattice_Right_Bias((MersenneTwisterRandomNumberGenerator) r));
return h;
}
@@ -6,7 +6,7 @@
import org.iguanatool.search.SearchException;
import org.iguanatool.search.objective.ObjectiveFunction;
import org.iguanatool.search.objective.ObjectiveValue;
import org.iguanatool.search.randomnumbergenerator.MersenneTwister;
import org.iguanatool.search.randomnumbergenerator.MersenneTwisterRandomNumberGenerator;
import org.iguanatool.search.solution.NumericalSolution;
import org.iguanatool.search.solution.Solution;
@@ -17,15 +17,15 @@
public abstract class CachedNeighbourhoodSearch extends NeighbourhoodSearch {
protected MersenneTwister rng; // random number generator
protected MersenneTwisterRandomNumberGenerator rng; // random number generator
protected int nVariables;
protected List<Integer> indicies; // order to cycle through variables
protected Map<NumericalSolution, ObjectiveValue> cache = new HashMap<NumericalSolution, ObjectiveValue>();
protected CachedNeighbourhoodSearch(MersenneTwister rng) {
protected CachedNeighbourhoodSearch(MersenneTwisterRandomNumberGenerator rng) {
this.rng = rng;
}
@@ -4,13 +4,13 @@
import org.iguanatool.search.SearchException;
import org.iguanatool.search.SearchMonitor;
import org.iguanatool.search.objective.ObjectiveFunction;
import org.iguanatool.search.randomnumbergenerator.MersenneTwister;
import org.iguanatool.search.randomnumbergenerator.MersenneTwisterRandomNumberGenerator;
import org.iguanatool.search.solution.NumericalSolution;
import org.iguanatool.search.solution.Solution;
public class Geometric_No_Bias extends CachedNeighbourhoodSearch {
public Geometric_No_Bias(MersenneTwister rng) {
public Geometric_No_Bias(MersenneTwisterRandomNumberGenerator rng) {
super(rng);
}
@@ -4,13 +4,13 @@
import org.iguanatool.search.SearchException;
import org.iguanatool.search.SearchMonitor;
import org.iguanatool.search.objective.ObjectiveFunction;
import org.iguanatool.search.randomnumbergenerator.MersenneTwister;
import org.iguanatool.search.randomnumbergenerator.MersenneTwisterRandomNumberGenerator;
import org.iguanatool.search.solution.NumericalSolution;
import org.iguanatool.search.solution.Solution;
public class Geometric_Opposite_Direction_Bias extends CachedNeighbourhoodSearch {
public Geometric_Opposite_Direction_Bias(MersenneTwister rng) {
public Geometric_Opposite_Direction_Bias(MersenneTwisterRandomNumberGenerator rng) {
super(rng);
}
@@ -4,13 +4,13 @@
import org.iguanatool.search.SearchException;
import org.iguanatool.search.SearchMonitor;
import org.iguanatool.search.objective.ObjectiveFunction;
import org.iguanatool.search.randomnumbergenerator.MersenneTwister;
import org.iguanatool.search.randomnumbergenerator.MersenneTwisterRandomNumberGenerator;
import org.iguanatool.search.solution.NumericalSolution;
import org.iguanatool.search.solution.Solution;
public class Geometric_Right_Bias extends CachedNeighbourhoodSearch {
public Geometric_Right_Bias(MersenneTwister rng) {
public Geometric_Right_Bias(MersenneTwisterRandomNumberGenerator rng) {
super(rng);
}
@@ -4,13 +4,13 @@
import org.iguanatool.search.SearchException;
import org.iguanatool.search.SearchMonitor;
import org.iguanatool.search.objective.ObjectiveFunction;
import org.iguanatool.search.randomnumbergenerator.MersenneTwister;
import org.iguanatool.search.randomnumbergenerator.MersenneTwisterRandomNumberGenerator;
import org.iguanatool.search.solution.NumericalSolution;
import org.iguanatool.search.solution.Solution;
public class IPS_No_Bias extends CachedNeighbourhoodSearch {
public IPS_No_Bias(MersenneTwister rng) {
public IPS_No_Bias(MersenneTwisterRandomNumberGenerator rng) {
super(rng);
}
@@ -4,13 +4,13 @@
import org.iguanatool.search.SearchException;
import org.iguanatool.search.SearchMonitor;
import org.iguanatool.search.objective.ObjectiveFunction;
import org.iguanatool.search.randomnumbergenerator.MersenneTwister;
import org.iguanatool.search.randomnumbergenerator.MersenneTwisterRandomNumberGenerator;
import org.iguanatool.search.solution.NumericalSolution;
import org.iguanatool.search.solution.Solution;
public class IPS_Right_Bias extends CachedNeighbourhoodSearch {
public IPS_Right_Bias(MersenneTwister rng) {
public IPS_Right_Bias(MersenneTwisterRandomNumberGenerator rng) {
super(rng);
}
@@ -4,7 +4,7 @@
import org.iguanatool.search.SearchException;
import org.iguanatool.search.SearchMonitor;
import org.iguanatool.search.objective.ObjectiveFunction;
import org.iguanatool.search.randomnumbergenerator.MersenneTwister;
import org.iguanatool.search.randomnumbergenerator.MersenneTwisterRandomNumberGenerator;
import org.iguanatool.search.solution.NumericalSolution;
import org.iguanatool.search.solution.Solution;
@@ -21,7 +21,7 @@
}
}
public Lattice_No_Bias(MersenneTwister rng) {
public Lattice_No_Bias(MersenneTwisterRandomNumberGenerator rng) {
super(rng);
}
@@ -4,7 +4,7 @@
import org.iguanatool.search.SearchException;
import org.iguanatool.search.SearchMonitor;
import org.iguanatool.search.objective.ObjectiveFunction;
import org.iguanatool.search.randomnumbergenerator.MersenneTwister;
import org.iguanatool.search.randomnumbergenerator.MersenneTwisterRandomNumberGenerator;
import org.iguanatool.search.solution.NumericalSolution;
import org.iguanatool.search.solution.Solution;
@@ -21,7 +21,7 @@
}
}
public Lattice_Opposite_Direction_Bias(MersenneTwister rng) {
public Lattice_Opposite_Direction_Bias(MersenneTwisterRandomNumberGenerator rng) {
super(rng);
}
@@ -4,7 +4,7 @@
import org.iguanatool.search.SearchException;
import org.iguanatool.search.SearchMonitor;
import org.iguanatool.search.objective.ObjectiveFunction;
import org.iguanatool.search.randomnumbergenerator.MersenneTwister;
import org.iguanatool.search.randomnumbergenerator.MersenneTwisterRandomNumberGenerator;
import org.iguanatool.search.solution.NumericalSolution;
import org.iguanatool.search.solution.Solution;
@@ -21,7 +21,7 @@
}
}
public Lattice_Right_Bias(MersenneTwister rng) {
public Lattice_Right_Bias(MersenneTwisterRandomNumberGenerator rng) {
super(rng);
}
@@ -3,13 +3,13 @@
import org.iguanatool.search.SearchException;
import org.iguanatool.search.SearchMonitor;
import org.iguanatool.search.objective.ObjectiveFunction;
import org.iguanatool.search.randomnumbergenerator.MersenneTwister;
import org.iguanatool.search.randomnumbergenerator.MersenneTwisterRandomNumberGenerator;
import org.iguanatool.search.solution.NumericalSolution;
import org.iguanatool.search.solution.Solution;
public class Random extends CachedNeighbourhoodSearch {
public Random(MersenneTwister rng) {
public Random(MersenneTwisterRandomNumberGenerator rng) {
super(rng);
}
@@ -1,80 +0,0 @@
package org.iguanatool.search.randomnumbergenerator;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class MersenneTwister extends RandomNumberGenerator {
private Random rng;
private long seed;
public MersenneTwister() {
//rng = ...
}
@Override
public void setSeed(long seed) {
rng.setSeed(this.seed = seed);
}
@Override
public long getInitialSeed() {
return seed;
}
@Override
public void reset() {
setSeed(seed);
}
@Override
public boolean nextBoolean() {
return rng.nextBoolean();
}
@Override
public int nextInt() {
return rng.nextInt();
}
@Override
public int nextInt(int max) {
return rng.nextInt(max);
}
@Override
public int nextInt(int min, int max) {
return min + nextInt(max - min);
}
@Override
public double nextDouble() {
return rng.nextDouble();
}
@Override
public double nextDouble(double max) {
return max * nextDouble();
}
@Override
public double nextDouble(double min, double max) {
return min + nextDouble(max - min);
}
@Override
public double nextGaussian() {
return rng.nextGaussian();
}
@Override
public double nextGaussian(double standardDeviation) {
return standardDeviation * nextGaussian();
}
public void shuffle(List<Integer> indicies) {
Collections.shuffle(indicies, rng);
}
}
Oops, something went wrong.

0 comments on commit 2897a0d

Please sign in to comment.