mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-13 14:12:11 +00:00
use java.util.Random for random number generation (used for wind pattern with gusts); remove library "ssj.jar";
This commit is contained in:
1 parent
c6e04a0b8e
commit
b75c4725d6
9 files changed
+47
-44
No files matched your search
@@ -3,7 +3,6 @@
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="lib" path="lib/ssj.jar"/>
|
||||
<classpathentry kind="src" path="resources"/>
|
||||
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
|
||||
@@ -14,8 +14,7 @@ Require-Bundle: com.sap.sailing.domain.common;bundle-version="1.0.0",
|
||||
org.json.simple;bundle-version="1.1.0"
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Import-Package: org.osgi.framework;version="1.6.0"
|
||||
Bundle-ClassPath: .,
|
||||
lib/ssj.jar
|
||||
Bundle-ClassPath: .
|
||||
Export-Package: com.sap.sailing.simulator,
|
||||
com.sap.sailing.simulator.impl,
|
||||
com.sap.sailing.simulator.util,
|
||||
|
||||
@@ -3,5 +3,4 @@ source.. = src/,\
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
lib/ssj.jar,\
|
||||
resources/
|
||||
Binary file not shown.
+2
-2
@@ -2,7 +2,7 @@ package com.sap.sailing.simulator.windfield;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import umontreal.iro.lecuyer.rng.RandomStream;
|
||||
import com.sap.sailing.simulator.windfield.impl.BlastRandom;
|
||||
|
||||
public interface RandomStreamManager extends Serializable {
|
||||
|
||||
@@ -16,7 +16,7 @@ public interface RandomStreamManager extends Serializable {
|
||||
* @param name
|
||||
* @return the RandomStream identified by the name
|
||||
*/
|
||||
public RandomStream getRandomStream(String name);
|
||||
public BlastRandom getRandomStream(String name);
|
||||
|
||||
/**
|
||||
* Reset all the random streams managed by the class
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.sap.sailing.simulator.windfield.impl;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BlastRandom extends Random {
|
||||
|
||||
private static final long serialVersionUID = -6409398526247431352L;
|
||||
|
||||
// random number having uniform distribution
|
||||
public double nextDouble(double min, double max) {
|
||||
return (min + (max - min)*this.nextDouble());
|
||||
}
|
||||
|
||||
// random number having Gaussian distribution
|
||||
public double nextGaussian(double mean, double variance) {
|
||||
return (mean + variance * this.nextGaussian());
|
||||
}
|
||||
|
||||
// random number having exponential distribution
|
||||
public double nextExponential(double lambda) {
|
||||
return -Math.log(1.0 - this.nextDouble())/lambda;
|
||||
}
|
||||
|
||||
// random number having geometric distribution
|
||||
public int nextGeometric(double p) {
|
||||
return (int)Math.floor(nextExponential(p));
|
||||
}
|
||||
|
||||
}
|
||||
+6
-10
@@ -2,10 +2,6 @@ package com.sap.sailing.simulator.windfield.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import umontreal.iro.lecuyer.rng.LFSR113;
|
||||
import umontreal.iro.lecuyer.rng.MRG32k3a;
|
||||
import umontreal.iro.lecuyer.rng.RandomStream;
|
||||
|
||||
public class BlastRandomSeedManagerImpl extends RandomStreamManagerImpl {
|
||||
|
||||
private static final long serialVersionUID = -6409398526247431352L;
|
||||
@@ -20,21 +16,21 @@ public class BlastRandomSeedManagerImpl extends RandomStreamManagerImpl {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
randomStreamMap = new HashMap<String, RandomStream>();
|
||||
randomStreamMap = new HashMap<String, BlastRandom>();
|
||||
|
||||
RandomStream stream = new LFSR113(BlastStream.SEED.name());
|
||||
BlastRandom stream = new BlastRandom();
|
||||
randomStreamMap.put(BlastStream.SEED.name(),stream);
|
||||
|
||||
stream = new LFSR113(BlastStream.CELL.name());
|
||||
stream = new BlastRandom();
|
||||
randomStreamMap.put(BlastStream.CELL.name(),stream);
|
||||
|
||||
stream = new LFSR113(BlastStream.SPEED.name());
|
||||
stream = new BlastRandom();
|
||||
randomStreamMap.put(BlastStream.SPEED.name(),stream);
|
||||
|
||||
stream = new MRG32k3a(BlastStream.SIZE.name());
|
||||
stream = new BlastRandom();
|
||||
randomStreamMap.put(BlastStream.SIZE.name(),stream);
|
||||
|
||||
stream = new LFSR113(BlastStream.BEARING.name());
|
||||
stream = new BlastRandom();
|
||||
randomStreamMap.put(BlastStream.BEARING.name(), stream);
|
||||
}
|
||||
|
||||
|
||||
+3
-8
@@ -1,30 +1,25 @@
|
||||
package com.sap.sailing.simulator.windfield.impl;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import umontreal.iro.lecuyer.rng.RandomStream;
|
||||
|
||||
import com.sap.sailing.simulator.windfield.RandomStreamManager;
|
||||
|
||||
public abstract class RandomStreamManagerImpl implements RandomStreamManager {
|
||||
|
||||
private static final long serialVersionUID = -2066054080465695880L;
|
||||
protected Map<String, RandomStream> randomStreamMap;
|
||||
protected Map<String, BlastRandom> randomStreamMap;
|
||||
|
||||
public RandomStreamManagerImpl() {
|
||||
initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomStream getRandomStream(String name) {
|
||||
public BlastRandom getRandomStream(String name) {
|
||||
return randomStreamMap.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
for(Entry<String, RandomStream> entry : randomStreamMap.entrySet()) {
|
||||
entry.getValue().resetStartStream();
|
||||
}
|
||||
// if seeds are used, reset seeds
|
||||
}
|
||||
}
|
||||
+6
-20
@@ -2,10 +2,6 @@ package com.sap.sailing.simulator.windfield.impl;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import umontreal.iro.lecuyer.randvar.GeometricGen;
|
||||
import umontreal.iro.lecuyer.randvar.NormalGen;
|
||||
import umontreal.iro.lecuyer.rng.RandomStream;
|
||||
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.domain.common.SpeedWithBearing;
|
||||
import com.sap.sailing.domain.common.Wind;
|
||||
@@ -22,9 +18,6 @@ import com.sap.sse.common.Util;
|
||||
|
||||
public class WindFieldGeneratorBlastImpl extends WindFieldGeneratorImpl implements WindFieldGenerator {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -188939912966537200L;
|
||||
|
||||
private SpeedWithBearing[][] speedWithBearing;
|
||||
@@ -148,35 +141,28 @@ public class WindFieldGeneratorBlastImpl extends WindFieldGeneratorImpl implemen
|
||||
}
|
||||
|
||||
private boolean isBlastSeed() {
|
||||
//return UniformGen.nextDouble(new LFSR113("BlastSeedStream"), 0, 1) < windParameters.blastProbability / 100.0;
|
||||
return windParameters.getBlastRandomStreamManager().getRandomStream(BlastRandomSeedManagerImpl.BlastStream.SEED.name()).nextDouble() < windParameters.blastProbability / 100.0;
|
||||
}
|
||||
|
||||
private boolean isBlastCell() {
|
||||
//return UniformGen.nextDouble(new LFSR113("BlastCellStream"), 0, 1) > this.blastEdgeProbability / 100.0;
|
||||
return windParameters.getBlastRandomStreamManager().getRandomStream(BlastRandomSeedManagerImpl.BlastStream.CELL.name()).nextDouble() > this.blastEdgeProbability / 100.0;
|
||||
}
|
||||
|
||||
private double getBlastSpeed() {
|
||||
double bSpeedMean = windParameters.baseWindSpeed * (windParameters.blastWindSpeed / 100.0 - (defaultWindSpeed==0 ? 1. : 0.));
|
||||
double bSpeedVar = windParameters.baseWindSpeed * windParameters.blastWindSpeed / 100.0 * windParameters.blastWindSpeedVar / 100.0;
|
||||
//System.out.println("blast par speed: "+windParameters.blastWindSpeed+" var: "+windParameters.blastWindSpeedVar);
|
||||
//System.out.println("blast speed mean: "+bSpeedMean+" var: "+bSpeedVar);
|
||||
//return NormalGen.nextDouble(new LFSR113("BlastSpeedStream"), bSpeedMean, bSpeedVar);
|
||||
RandomStream speedStream = windParameters.getBlastRandomStreamManager().getRandomStream(BlastRandomSeedManagerImpl.BlastStream.SPEED.name());
|
||||
return Math.max(0.5*bSpeedMean, Math.min(1.5*bSpeedMean, NormalGen.nextDouble(speedStream, bSpeedMean, bSpeedVar)));
|
||||
BlastRandom speedStream = windParameters.getBlastRandomStreamManager().getRandomStream(BlastRandomSeedManagerImpl.BlastStream.SPEED.name());
|
||||
return Math.max(0.5*bSpeedMean, Math.min(1.5*bSpeedMean, speedStream.nextGaussian(bSpeedMean, bSpeedVar)));
|
||||
}
|
||||
|
||||
private int getBlastSize() {
|
||||
//return GeometricGen.nextInt(new MRG32k3a("BlastSizeStream"), blastSizeProbability / 100.0);
|
||||
RandomStream sizeStream = windParameters.getBlastRandomStreamManager().getRandomStream(BlastRandomSeedManagerImpl.BlastStream.SIZE.name());
|
||||
return GeometricGen.nextInt(sizeStream, blastSizeProbability / 100.0);
|
||||
BlastRandom sizeStream = windParameters.getBlastRandomStreamManager().getRandomStream(BlastRandomSeedManagerImpl.BlastStream.SIZE.name());
|
||||
return (1 + sizeStream.nextGeometric(blastSizeProbability / 100.0));
|
||||
}
|
||||
|
||||
private double getBlastAngle() {
|
||||
//return NormalGen.nextDouble(new LFSR113("BlastAngleStream"), blastBearingMean, blastBearingVar);
|
||||
RandomStream bearingStream = windParameters.getBlastRandomStreamManager().getRandomStream(BlastRandomSeedManagerImpl.BlastStream.BEARING.name());
|
||||
return Math.max(-1.5*blastBearingVar, Math.min(1.5*blastBearingVar, NormalGen.nextDouble(bearingStream, blastBearingMean, blastBearingVar)));
|
||||
BlastRandom bearingStream = windParameters.getBlastRandomStreamManager().getRandomStream(BlastRandomSeedManagerImpl.BlastStream.BEARING.name());
|
||||
return Math.max(-1.5*blastBearingVar, Math.min(1.5*blastBearingVar, bearingStream.nextGaussian(blastBearingMean, blastBearingVar)));
|
||||
}
|
||||
|
||||
private SpeedWithBearing getSpeedWithBearing(TimedPosition timedPosition) {
|
||||
|
||||
Reference in new issue
Block a user