mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-01 01:44:08 +00:00
Keeping random seeds for blasts between winddisplay and simulation views.
This commit is contained in:
1 parent
67092a7c3b
commit
390120346d
8 files changed
+158
-7
No files matched your search
+5
-2
@@ -198,11 +198,12 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
|
||||
RectangularBoundary bd = new RectangularBoundary(nw, se, 0.1);
|
||||
// List<Position> lattice = bd.extractLattice(params.getxRes(),
|
||||
// params.getyRes());
|
||||
|
||||
|
||||
controlParameters.resetBlastRandomStream = params.isKeepState();
|
||||
retreiveWindControlParameters(pattern);
|
||||
logger.info("Boundary south direction " + bd.getSouth());
|
||||
controlParameters.baseWindBearing += bd.getSouth().getDegrees();
|
||||
|
||||
|
||||
WindFieldGenerator wf = wfGenFactory.createWindFieldGenerator(pattern.getWindPattern().name(), bd, controlParameters);
|
||||
|
||||
if (wf == null) {
|
||||
@@ -427,6 +428,8 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
|
||||
List<Position> course = null;
|
||||
TimePoint startTime = new MillisecondsTimePoint(params.getStartTime().getTime());
|
||||
TimePoint timeStep = new MillisecondsTimePoint(params.getTimeStep().getTime());
|
||||
|
||||
controlParameters.resetBlastRandomStream = params.isKeepState();
|
||||
retreiveWindControlParameters(pattern);
|
||||
|
||||
wf = wfGenFactory.createWindFieldGenerator(pattern.getWindPattern().name(), null, controlParameters);
|
||||
|
||||
+10
@@ -16,6 +16,8 @@ public class WindFieldGenParamsDTO implements IsSerializable {
|
||||
private Date endTime;
|
||||
private Date timeStep;
|
||||
|
||||
private boolean keepState;
|
||||
|
||||
/**
|
||||
* Currently m is for measured
|
||||
*/
|
||||
@@ -99,4 +101,12 @@ public class WindFieldGenParamsDTO implements IsSerializable {
|
||||
public void setMode(char mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public boolean isKeepState() {
|
||||
return keepState;
|
||||
}
|
||||
|
||||
public void setKeepState(boolean keepState) {
|
||||
this.keepState = keepState;
|
||||
}
|
||||
}
|
||||
+8
@@ -574,6 +574,14 @@ public class SimulatorMap extends AbsolutePanel implements RequiresDataInitializ
|
||||
if ((isCourseSet())||(mode == SailingSimulatorUtil.measured)) {
|
||||
mapw.setDoubleClickZoom(true);
|
||||
raceCourseCanvasOverlay.setSelected(false);
|
||||
windParams.setKeepState(!force);
|
||||
if (force) {
|
||||
if (replayPathCanvasOverlays != null) {
|
||||
removeOverlays();
|
||||
timeListeners.clear();
|
||||
replayPathCanvasOverlays.clear();
|
||||
}
|
||||
}
|
||||
switch (name) {
|
||||
case SUMMARY:
|
||||
refreshSummaryView(windPatternDisplay, boatClassIndex, force);
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.sap.sailing.simulator.windfield;
|
||||
|
||||
import umontreal.iro.lecuyer.rng.RandomStream;
|
||||
|
||||
public interface RandomStreamManager {
|
||||
|
||||
/**
|
||||
* Initialise the random streams managed by the class
|
||||
*/
|
||||
public void initialize();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return the RandomStream identified by the name
|
||||
*/
|
||||
public RandomStream getRandomStream(String name);
|
||||
|
||||
/**
|
||||
* Reset all the random streams managed by the class
|
||||
*/
|
||||
public void reset();
|
||||
}
|
||||
+30
@@ -1,5 +1,9 @@
|
||||
package com.sap.sailing.simulator.windfield;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sap.sailing.simulator.windfield.impl.BlastRandomSeedManagerImpl;
|
||||
|
||||
|
||||
public class WindControlParameters {
|
||||
/**
|
||||
@@ -74,11 +78,22 @@ public class WindControlParameters {
|
||||
*/
|
||||
public Double blastWindSpeedVar;
|
||||
|
||||
/**
|
||||
* Flag to control if the random stream should be reset
|
||||
*/
|
||||
public boolean resetBlastRandomStream;
|
||||
|
||||
private RandomStreamManager blastRandomStreamManager;
|
||||
|
||||
private static Logger logger = Logger.getLogger(WindControlParameters.class.getName());
|
||||
|
||||
public WindControlParameters() {
|
||||
resetBlastRandomStream = false;
|
||||
setDefaults();
|
||||
}
|
||||
|
||||
public WindControlParameters(double speedInKnots, double bearing) {
|
||||
resetBlastRandomStream = false;
|
||||
setDefaults();
|
||||
baseWindSpeed = speedInKnots;
|
||||
baseWindBearing = bearing;
|
||||
@@ -99,5 +114,20 @@ public class WindControlParameters {
|
||||
maxBlastSize = 1.0;
|
||||
blastWindSpeed = 120.0;
|
||||
blastWindSpeedVar = 10.0;
|
||||
|
||||
if (blastRandomStreamManager == null || !resetBlastRandomStream) {
|
||||
setBlastRandomStreamManager(new BlastRandomSeedManagerImpl());
|
||||
} else {
|
||||
logger.info("Resetting random seeds for wind field.");
|
||||
blastRandomStreamManager.reset();
|
||||
}
|
||||
}
|
||||
|
||||
public RandomStreamManager getBlastRandomStreamManager() {
|
||||
return blastRandomStreamManager;
|
||||
}
|
||||
|
||||
public void setBlastRandomStreamManager(RandomStreamManager blastRandomStreamManager) {
|
||||
this.blastRandomStreamManager = blastRandomStreamManager;
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
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 {
|
||||
|
||||
public enum BlastStream {
|
||||
SEED,
|
||||
CELL,
|
||||
SPEED,
|
||||
SIZE,
|
||||
BEARING
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
randomStreamMap = new HashMap<String, RandomStream>();
|
||||
|
||||
RandomStream stream = new LFSR113(BlastStream.SEED.name());
|
||||
randomStreamMap.put(BlastStream.SEED.name(),stream);
|
||||
|
||||
stream = new LFSR113(BlastStream.CELL.name());
|
||||
randomStreamMap.put(BlastStream.CELL.name(),stream);
|
||||
|
||||
stream = new LFSR113(BlastStream.SPEED.name());
|
||||
randomStreamMap.put(BlastStream.SPEED.name(),stream);
|
||||
|
||||
stream = new MRG32k3a(BlastStream.SIZE.name());
|
||||
randomStreamMap.put(BlastStream.SIZE.name(),stream);
|
||||
|
||||
stream = new LFSR113(BlastStream.BEARING.name());
|
||||
randomStreamMap.put(BlastStream.BEARING.name(), stream);
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
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 {
|
||||
|
||||
protected Map<String, RandomStream> randomStreamMap;
|
||||
|
||||
public RandomStreamManagerImpl() {
|
||||
initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomStream getRandomStream(String name) {
|
||||
return randomStreamMap.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
for(Entry<String, RandomStream> entry : randomStreamMap.entrySet()) {
|
||||
entry.getValue().resetStartStream();
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-5
@@ -7,6 +7,7 @@ import umontreal.iro.lecuyer.randvar.NormalGen;
|
||||
import umontreal.iro.lecuyer.randvar.UniformGen;
|
||||
import umontreal.iro.lecuyer.rng.LFSR113;
|
||||
import umontreal.iro.lecuyer.rng.MRG32k3a;
|
||||
import umontreal.iro.lecuyer.rng.RandomStream;
|
||||
|
||||
import com.sap.sailing.domain.base.SpeedWithBearing;
|
||||
import com.sap.sailing.domain.base.impl.KnotSpeedWithBearingImpl;
|
||||
@@ -144,11 +145,13 @@ public class WindFieldGeneratorBlastImpl extends WindFieldGeneratorImpl implemen
|
||||
}
|
||||
|
||||
private boolean isBlastSeed() {
|
||||
return UniformGen.nextDouble(new LFSR113("BlastSeedStream"), 0, 1) < windParameters.blastProbability / 100.0;
|
||||
//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 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() {
|
||||
@@ -156,16 +159,22 @@ public class WindFieldGeneratorBlastImpl extends WindFieldGeneratorImpl implemen
|
||||
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);
|
||||
//return NormalGen.nextDouble(new LFSR113("BlastSpeedStream"), bSpeedMean, bSpeedVar);
|
||||
RandomStream speedStream = windParameters.getBlastRandomStreamManager().getRandomStream(BlastRandomSeedManagerImpl.BlastStream.SPEED.name());
|
||||
return NormalGen.nextDouble(speedStream, bSpeedMean, bSpeedVar);
|
||||
|
||||
}
|
||||
|
||||
private int getBlastSize() {
|
||||
return GeometricGen.nextInt(new MRG32k3a("BlastSizeStream"), blastSizeProbability / 100.0);
|
||||
//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);
|
||||
}
|
||||
|
||||
private double getBlastAngle() {
|
||||
return NormalGen.nextDouble(new LFSR113("BlastAngleStream"), blastBearingMean, blastBearingVar);
|
||||
//return NormalGen.nextDouble(new LFSR113("BlastAngleStream"), blastBearingMean, blastBearingVar);
|
||||
RandomStream bearingStream = windParameters.getBlastRandomStreamManager().getRandomStream(BlastRandomSeedManagerImpl.BlastStream.BEARING.name());
|
||||
return NormalGen.nextDouble(bearingStream, blastBearingMean, blastBearingVar);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user