Skip to content

Commit

Permalink
Removes mentions of googlecode. Update sites harmonized among features
Browse files Browse the repository at this point in the history
Signed-off-by: AlexisDrogoul <alexis.drogoul@gmail.com>
  • Loading branch information
AlexisDrogoul committed May 21, 2016
1 parent aca673c commit dee4b1e
Show file tree
Hide file tree
Showing 15 changed files with 370 additions and 284 deletions.
4 changes: 2 additions & 2 deletions msi.gama.application/p2.inf
@@ -1,3 +1,3 @@
instructions.configure=\
addRepository(type:0,location:https${#58}//gama-platform.googlecode.com/svn/update_site/);\
addRepository(type:1,location:https${#58}//gama-platform.googlecode.com/svn/update_site/);
addRepository(type:0,location:http${#58}//updates.gama-platform.org);\
addRepository(type:1,location:http${#58}//updates.gama-platform.org);
87 changes: 49 additions & 38 deletions msi.gama.core/src/msi/gama/util/random/CellularAutomatonRNG.java
Expand Up @@ -5,7 +5,7 @@
* GAMA modeling and simulation platform.
* (c) 2007-2014 UMI 209 UMMISCO IRD/UPMC & Partners
*
* Visit http://gama-platform.googlecode.com for license information and developers contact.
* Visit http://gama-platform.org for license information and developers contact.
*
*
**********************************************************************************************/
Expand All @@ -28,8 +28,11 @@
import msi.gama.common.util.RandomUtils;

/**
* Java port of the <a href="http://home.southernct.edu/~pasqualonia1/ca/report.html"
* target="_top">cellular automaton pseudorandom number generator</a> developed by Tony Pasqualoni.
* Java port of the
* <a href="http://home.southernct.edu/~pasqualonia1/ca/report.html" target=
* "_top">cellular automaton pseudorandom number generator</a> developed by Tony
* Pasqualoni.
*
* @author Tony Pasqualoni (original C version)
* @author Daniel Dyer (Java port)
*/
Expand All @@ -39,27 +42,28 @@ public class CellularAutomatonRNG extends GamaRNG {
private static final int AUTOMATON_LENGTH = 2056;

private static final int[] RNG_RULE = { 100, 75, 16, 3, 229, 51, 197, 118, 24, 62, 198, 11, 141, 152, 241, 188, 2,
17, 71, 47, 179, 177, 126, 231, 202, 243, 59, 25, 77, 196, 30, 134, 199, 163, 34, 216, 21, 84, 37, 182, 224,
186, 64, 79, 225, 45, 143, 20, 48, 147, 209, 221, 125, 29, 99, 12, 46, 190, 102, 220, 80, 215, 242, 105, 15, 53,
0, 67, 68, 69, 70, 89, 109, 195, 170, 78, 210, 131, 42, 110, 181, 145, 40, 114, 254, 85, 107, 87, 72, 192, 90,
201, 162, 122, 86, 252, 94, 129, 98, 132, 193, 249, 156, 172, 219, 230, 153, 54, 180, 151, 83, 214, 123, 88,
164, 167, 116, 117, 7, 27, 23, 213, 235, 5, 65, 124, 60, 127, 236, 149, 44, 28, 58, 121, 191, 13, 250, 10, 232,
112, 101, 217, 183, 239, 8, 32, 228, 174, 49, 113, 247, 158, 106, 218, 154, 66, 226, 157, 50, 26, 253, 93, 205,
41, 133, 165, 61, 161, 187, 169, 6, 171, 81, 248, 56, 175, 246, 36, 178, 52, 57, 212, 39, 176, 184, 185, 245,
63, 35, 189, 206, 76, 104, 233, 194, 19, 43, 159, 108, 55, 200, 155, 14, 74, 244, 255, 222, 207, 208, 137, 128,
135, 96, 144, 18, 95, 234, 139, 173, 92, 1, 203, 115, 223, 130, 97, 91, 227, 146, 4, 31, 120, 211, 38, 22, 138,
140, 237, 238, 251, 240, 160, 142, 119, 73, 103, 166, 33, 148, 9, 111, 136, 168, 150, 82, 204, 100, 75, 16, 3,
229, 51, 197, 118, 24, 62, 198, 11, 141, 152, 241, 188, 2, 17, 71, 47, 179, 177, 126, 231, 202, 243, 59, 25, 77,
196, 30, 134, 199, 163, 34, 216, 21, 84, 37, 182, 224, 186, 64, 79, 225, 45, 143, 20, 48, 147, 209, 221, 125,
29, 99, 12, 46, 190, 102, 220, 80, 215, 242, 105, 15, 53, 0, 67, 68, 69, 70, 89, 109, 195, 170, 78, 210, 131,
42, 110, 181, 145, 40, 114, 254, 85, 107, 87, 72, 192, 90, 201, 162, 122, 86, 252, 94, 129, 98, 132, 193, 249,
156, 172, 219, 230, 153, 54, 180, 151, 83, 214, 123, 88, 164, 167, 116, 117, 7, 27, 23, 213, 235, 5, 65, 124,
60, 127, 236, 149, 44, 28, 58, 121, 191, 13, 250, 10, 232, 112, 101, 217, 183, 239, 8, 32, 228, 174, 49, 113,
247, 158, 106, 218, 154, 66, 226, 157, 50, 26, 253, 93, 205, 41, 133, 165, 61, 161, 187, 169, 6, 171, 81, 248,
56, 175, 246, 36, 178, 52, 57, 212, 39, 176, 184, 185, 245, 63, 35, 189, 206, 76, 104, 233, 194, 19, 43, 159,
108, 55, 200, 155, 14, 74, 244, 255, 222, 207, 208, 137, 128, 135, 96, 144, 18, 95, 234, 139, 173, 92, 1, 203,
115, 223, 130, 97, 91, 227, 146, 4, 31, 120, 211, 38, 22, 138, 140, 237, 238, 251, 240, 160, 142, 119, 73, 103,
166, 33, 148, 9, 111, 136, 168, 150, 82 };
17, 71, 47, 179, 177, 126, 231, 202, 243, 59, 25, 77, 196, 30, 134, 199, 163, 34, 216, 21, 84, 37, 182, 224,
186, 64, 79, 225, 45, 143, 20, 48, 147, 209, 221, 125, 29, 99, 12, 46, 190, 102, 220, 80, 215, 242, 105, 15,
53, 0, 67, 68, 69, 70, 89, 109, 195, 170, 78, 210, 131, 42, 110, 181, 145, 40, 114, 254, 85, 107, 87, 72,
192, 90, 201, 162, 122, 86, 252, 94, 129, 98, 132, 193, 249, 156, 172, 219, 230, 153, 54, 180, 151, 83, 214,
123, 88, 164, 167, 116, 117, 7, 27, 23, 213, 235, 5, 65, 124, 60, 127, 236, 149, 44, 28, 58, 121, 191, 13,
250, 10, 232, 112, 101, 217, 183, 239, 8, 32, 228, 174, 49, 113, 247, 158, 106, 218, 154, 66, 226, 157, 50,
26, 253, 93, 205, 41, 133, 165, 61, 161, 187, 169, 6, 171, 81, 248, 56, 175, 246, 36, 178, 52, 57, 212, 39,
176, 184, 185, 245, 63, 35, 189, 206, 76, 104, 233, 194, 19, 43, 159, 108, 55, 200, 155, 14, 74, 244, 255,
222, 207, 208, 137, 128, 135, 96, 144, 18, 95, 234, 139, 173, 92, 1, 203, 115, 223, 130, 97, 91, 227, 146,
4, 31, 120, 211, 38, 22, 138, 140, 237, 238, 251, 240, 160, 142, 119, 73, 103, 166, 33, 148, 9, 111, 136,
168, 150, 82, 204, 100, 75, 16, 3, 229, 51, 197, 118, 24, 62, 198, 11, 141, 152, 241, 188, 2, 17, 71, 47,
179, 177, 126, 231, 202, 243, 59, 25, 77, 196, 30, 134, 199, 163, 34, 216, 21, 84, 37, 182, 224, 186, 64,
79, 225, 45, 143, 20, 48, 147, 209, 221, 125, 29, 99, 12, 46, 190, 102, 220, 80, 215, 242, 105, 15, 53, 0,
67, 68, 69, 70, 89, 109, 195, 170, 78, 210, 131, 42, 110, 181, 145, 40, 114, 254, 85, 107, 87, 72, 192, 90,
201, 162, 122, 86, 252, 94, 129, 98, 132, 193, 249, 156, 172, 219, 230, 153, 54, 180, 151, 83, 214, 123, 88,
164, 167, 116, 117, 7, 27, 23, 213, 235, 5, 65, 124, 60, 127, 236, 149, 44, 28, 58, 121, 191, 13, 250, 10,
232, 112, 101, 217, 183, 239, 8, 32, 228, 174, 49, 113, 247, 158, 106, 218, 154, 66, 226, 157, 50, 26, 253,
93, 205, 41, 133, 165, 61, 161, 187, 169, 6, 171, 81, 248, 56, 175, 246, 36, 178, 52, 57, 212, 39, 176, 184,
185, 245, 63, 35, 189, 206, 76, 104, 233, 194, 19, 43, 159, 108, 55, 200, 155, 14, 74, 244, 255, 222, 207,
208, 137, 128, 135, 96, 144, 18, 95, 234, 139, 173, 92, 1, 203, 115, 223, 130, 97, 91, 227, 146, 4, 31, 120,
211, 38, 22, 138, 140, 237, 238, 251, 240, 160, 142, 119, 73, 103, 166, 33, 148, 9, 111, 136, 168, 150,
82 };

private final byte[] seed;
private final int[] cells = new int[AUTOMATON_LENGTH];
Expand All @@ -78,21 +82,27 @@ public class CellularAutomatonRNG extends GamaRNG {

/**
* Seed the RNG using the provided seed generation strategy.
* @param seedGenerator The seed generation strategy that will provide the seed value for this
* RNG.
* @throws SeedException If there is a problem generating a seed.
*
* @param seedGenerator
* The seed generation strategy that will provide the seed value
* for this RNG.
* @throws SeedException
* If there is a problem generating a seed.
*/
public CellularAutomatonRNG(final RandomUtils seedGenerator) {
this(seedGenerator.generateSeed(SEED_SIZE_BYTES));
}

/**
* Creates an RNG and seeds it with the specified seed data.
* @param seed The seed data used to initialise the RNG.
*
* @param seed
* The seed data used to initialise the RNG.
*/
public CellularAutomatonRNG(final byte[] seed) {
if ( seed == null || seed.length != SEED_SIZE_BYTES ) { throw new IllegalArgumentException(
"Cellular Automaton RNG requires a 32-bit (4-byte) seed."); }
if (seed == null || seed.length != SEED_SIZE_BYTES) {
throw new IllegalArgumentException("Cellular Automaton RNG requires a 32-bit (4-byte) seed.");
}
this.seed = seed.clone();

// Set initial cell states using seed.
Expand All @@ -102,15 +112,15 @@ public CellularAutomatonRNG(final byte[] seed) {
cells[AUTOMATON_LENGTH - 4] = seed[3] + 128;

int seedAsInt = convertBytesToInt(seed, 0);
if ( seedAsInt != 0xFFFFFFFF ) {
if (seedAsInt != 0xFFFFFFFF) {
seedAsInt++;
}
for ( int i = 0; i < AUTOMATON_LENGTH - 4; i++ ) {
for (int i = 0; i < AUTOMATON_LENGTH - 4; i++) {
cells[i] = 0x000000FF & seedAsInt >> i % 32;
}

// Evolve automaton before returning integers.
for ( int i = 0; i < AUTOMATON_LENGTH * AUTOMATON_LENGTH / 4; i++ ) {
for (int i = 0; i < AUTOMATON_LENGTH * AUTOMATON_LENGTH / 4; i++) {
next(32);
}
}
Expand All @@ -125,17 +135,18 @@ public int next(final int bits) {
// try {
// lock.lock();
// Set cell addresses using address of current cell.
int cellC = currentCellIndex - 1;
int cellB = cellC - 1;
int cellA = cellB - 1;
final int cellC = currentCellIndex - 1;
final int cellB = cellC - 1;
final int cellA = cellB - 1;

// Update cell states using rule table.
cells[currentCellIndex] = RNG_RULE[cells[cellC] + cells[currentCellIndex]];
cells[cellC] = RNG_RULE[cells[cellB] + cells[cellC]];
cells[cellB] = RNG_RULE[cells[cellA] + cells[cellB]];

// Update the state of cellA and shift current cell to the left by 4 bytes.
if ( cellA == 0 ) {
// Update the state of cellA and shift current cell to the left by 4
// bytes.
if (cellA == 0) {
cells[cellA] = RNG_RULE[cells[cellA]];
currentCellIndex = AUTOMATON_LENGTH - 1;
} else {
Expand Down
31 changes: 20 additions & 11 deletions msi.gama.core/src/msi/gama/util/random/JavaRNG.java
Expand Up @@ -5,7 +5,7 @@
* GAMA modeling and simulation platform.
* (c) 2007-2014 UMI 209 UMMISCO IRD/UPMC & Partners
*
* Visit http://gama-platform.googlecode.com for license information and developers contact.
* Visit http://gama-platform.org for license information and developers contact.
*
*
**********************************************************************************************/
Expand All @@ -29,11 +29,14 @@

/**
* <p>
* This is the default {@link Random JDK RNG} extended to implement the {@link RepeatableRNG} interface (for consistency with the other RNGs in this package).
* This is the default {@link Random JDK RNG} extended to implement the
* {@link RepeatableRNG} interface (for consistency with the other RNGs in this
* package).
* </p>
*
* <p>
* The {@link MersenneTwisterRNG} should be used in preference to this class because it is statistically more random and performs slightly better.
* The {@link MersenneTwisterRNG} should be used in preference to this class
* because it is statistically more random and performs slightly better.
* </p>
*
* @author Daniel Dyer
Expand All @@ -53,17 +56,22 @@ public class JavaRNG extends GamaRNG {

/**
* Seed the RNG using the provided seed generation strategy.
* @param seedGenerator The seed generation strategy that will provide
* the seed value for this RNG.
* @throws SeedException If there is a problem generating a seed.
*
* @param seedGenerator
* The seed generation strategy that will provide the seed value
* for this RNG.
* @throws SeedException
* If there is a problem generating a seed.
*/
public JavaRNG(final RandomUtils seedGenerator) {
this(seedGenerator.generateSeed(SEED_SIZE_BYTES));
}

/**
* Creates an RNG and seeds it with the specified seed data.
* @param seed The seed data used to initialise the RNG.
*
* @param seed
* The seed data used to initialise the RNG.
*/
public JavaRNG(final byte[] seed) {
super(createLongSeed(seed));
Expand All @@ -81,11 +89,12 @@ public int next(final int bits) {
* super class.
*/
private static long createLongSeed(final byte[] seed) {
if ( seed == null || seed.length != SEED_SIZE_BYTES ) { throw new IllegalArgumentException(
"Java RNG requires a 64-bit (8-byte) seed."); }
if (seed == null || seed.length != SEED_SIZE_BYTES) {
throw new IllegalArgumentException("Java RNG requires a 64-bit (8-byte) seed.");
}
long value = 0;
for ( int i = 0; i < 0 + 8; i++ ) {
byte b = seed[i];
for (int i = 0; i < 0 + 8; i++) {
final byte b = seed[i];
value <<= 8;
value += b;
}
Expand Down
74 changes: 45 additions & 29 deletions msi.gama.core/src/msi/gama/util/random/MersenneTwisterRNG.java
Expand Up @@ -5,7 +5,7 @@
* GAMA modeling and simulation platform.
* (c) 2007-2014 UMI 209 UMMISCO IRD/UPMC & Partners
*
* Visit http://gama-platform.googlecode.com for license information and developers contact.
* Visit http://gama-platform.org for license information and developers contact.
*
*
**********************************************************************************************/
Expand All @@ -30,31 +30,38 @@

/**
* <p>
* Random number generator based on the <a href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html" target="_top">Mersenne Twister</a> algorithm developed by Makoto Matsumoto and Takuji
* Nishimura.
* Random number generator based on the
* <a href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html" target=
* "_top">Mersenne Twister</a> algorithm developed by Makoto Matsumoto and
* Takuji Nishimura.
* </p>
*
* <p>
* This is a very fast random number generator with good statistical properties (it passes the full DIEHARD suite). This is the best RNG for most experiments. If a non-linear generator is required,
* use the slower {@link AESCounterRNG} RNG.
* This is a very fast random number generator with good statistical properties
* (it passes the full DIEHARD suite). This is the best RNG for most
* experiments. If a non-linear generator is required, use the slower
* {@link AESCounterRNG} RNG.
* </p>
*
* <p>
* This PRNG is deterministic, which can be advantageous for testing purposes since the output is repeatable. If multiple instances of this class are created with the same seed they will all have
* identical output.
* This PRNG is deterministic, which can be advantageous for testing purposes
* since the output is repeatable. If multiple instances of this class are
* created with the same seed they will all have identical output.
* </p>
*
* <p>
* This code is translated from the original C version and assumes that we will always seed from an array of bytes. I don't pretend to know the meanings of the magic numbers or how it works, it just
* does.
* This code is translated from the original C version and assumes that we will
* always seed from an array of bytes. I don't pretend to know the meanings of
* the magic numbers or how it works, it just does.
* </p>
*
* @author Makoto Matsumoto and Takuji Nishimura (original C version)
* @author Daniel Dyer (Java port)
*/
public class MersenneTwisterRNG extends GamaRNG {

// The actual seed size isn't that important, but it should be a multiple of 4.
// The actual seed size isn't that important, but it should be a multiple of
// 4.
private static final int SEED_SIZE_BYTES = 16;

// Magic numbers from original C version.
Expand Down Expand Up @@ -87,55 +94,64 @@ public class MersenneTwisterRNG extends GamaRNG {

/**
* Seed the RNG using the provided seed generation strategy.
* @param seedGenerator The seed generation strategy that will provide the seed value for this
* RNG.
* @throws SeedException If there is a problem generating a seed.
*
* @param seedGenerator
* The seed generation strategy that will provide the seed value
* for this RNG.
* @throws SeedException
* If there is a problem generating a seed.
*/
public MersenneTwisterRNG(final RandomUtils seedGenerator) {
this(seedGenerator.generateSeed(SEED_SIZE_BYTES));
}

/**
* Creates an RNG and seeds it with the specified seed data.
* @param seed The seed data used to initialise the RNG.
*
* @param seed
* The seed data used to initialise the RNG.
*/
public MersenneTwisterRNG(final byte[] seed) {
if ( seed == null || seed.length != SEED_SIZE_BYTES ) { throw new IllegalArgumentException(
"Mersenne Twister RNG requires a 128-bit (16-byte) seed."); }
if (seed == null || seed.length != SEED_SIZE_BYTES) {
throw new IllegalArgumentException("Mersenne Twister RNG requires a 128-bit (16-byte) seed.");
}
this.seed = seed.clone();

int[] seedInts = convertBytesToInts(this.seed);
final int[] seedInts = convertBytesToInts(this.seed);

// This section is translated from the init_genrand code in the C version.
// This section is translated from the init_genrand code in the C
// version.
mt[0] = BOOTSTRAP_SEED;
for ( mtIndex = 1; mtIndex < N; mtIndex++ ) {
for (mtIndex = 1; mtIndex < N; mtIndex++) {
mt[mtIndex] = BOOTSTRAP_FACTOR * (mt[mtIndex - 1] ^ mt[mtIndex - 1] >>> 30) + mtIndex;
}

// This section is translated from the init_by_array code in the C version.
// This section is translated from the init_by_array code in the C
// version.
int i = 1;
int j = 0;
for ( int k = CmnFastMath.max(N, seedInts.length); k > 0; k-- ) {
for (int k = CmnFastMath.max(N, seedInts.length); k > 0; k--) {
mt[i] = (mt[i] ^ (mt[i - 1] ^ mt[i - 1] >>> 30) * SEED_FACTOR1) + seedInts[j] + j;
i++;
j++;
if ( i >= N ) {
if (i >= N) {
mt[0] = mt[N - 1];
i = 1;
}
if ( j >= seedInts.length ) {
if (j >= seedInts.length) {
j = 0;
}
}
for ( int k = N - 1; k > 0; k-- ) {
for (int k = N - 1; k > 0; k--) {
mt[i] = (mt[i] ^ (mt[i - 1] ^ mt[i - 1] >>> 30) * SEED_FACTOR2) - i;
i++;
if ( i >= N ) {
if (i >= N) {
mt[0] = mt[N - 1];
i = 1;
}
}
mt[0] = UPPER_MASK; // Most significant bit is 1 - guarantees non-zero initial array.
mt[0] = UPPER_MASK; // Most significant bit is 1 - guarantees non-zero
// initial array.
}

/**
Expand All @@ -156,14 +172,14 @@ protected final int next(final int bits) {
// try {
// lock.lock();

if ( mtIndex >= N ) // Generate N ints at a time.
if (mtIndex >= N) // Generate N ints at a time.
{
int kk;
for ( kk = 0; kk < N - M; kk++ ) {
for (kk = 0; kk < N - M; kk++) {
y = mt[kk] & UPPER_MASK | mt[kk + 1] & LOWER_MASK;
mt[kk] = mt[kk + M] ^ y >>> 1 ^ MAG01[y & 0x1];
}
for ( ; kk < N - 1; kk++ ) {
for (; kk < N - 1; kk++) {
y = mt[kk] & UPPER_MASK | mt[kk + 1] & LOWER_MASK;
mt[kk] = mt[kk + M - N] ^ y >>> 1 ^ MAG01[y & 0x1];
}
Expand Down

0 comments on commit dee4b1e

Please sign in to comment.