mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-17 17:50:56 +00:00
fix continuing-step for reaching; add sparse-polar-data-exception to path-generator;
This commit is contained in:
1 parent
ccca4683a9
commit
b11c4e151a
8 files changed
+40
-25
No files matched your search
+4
-2
@@ -384,7 +384,7 @@ public class SimulationServiceImpl implements SimulationService {
|
||||
SimulationParameters simulationPars = new SimulationParametersImpl(course, polarDiagram, windField,
|
||||
simuStep, SailingSimulatorConstants.ModeEvent, true, true, legType);
|
||||
Map<PathType, Path> paths = null;
|
||||
if ((polarDiagram != null)&&(legType != LegType.REACHING)) {
|
||||
if (polarDiagram != null) {
|
||||
paths = getAllPathsEvenTimed(simulationPars, timeStep.asMillis());
|
||||
}
|
||||
// prepare simulator-results
|
||||
@@ -457,7 +457,9 @@ public class SimulationServiceImpl implements SimulationService {
|
||||
for (Entry<PathType, Path> entry : allPaths.entrySet()) {
|
||||
PathType pathType = entry.getKey();
|
||||
Path pathValue = entry.getValue();
|
||||
allTimedPaths.put(pathType, pathValue.getEvenTimedPath(millisecondsStep));
|
||||
if (pathValue != null) {
|
||||
allTimedPaths.put(pathType, pathValue.getEvenTimedPath(millisecondsStep));
|
||||
}
|
||||
}
|
||||
return allTimedPaths;
|
||||
}
|
||||
|
||||
+2
-1
@@ -21,6 +21,7 @@ import com.sap.sailing.simulator.impl.PolarDiagram49STG;
|
||||
import com.sap.sailing.simulator.impl.RectangularGrid;
|
||||
import com.sap.sailing.simulator.impl.SimulatorImpl;
|
||||
import com.sap.sailing.simulator.impl.SimulationParametersImpl;
|
||||
import com.sap.sailing.simulator.impl.SparsePolarDataException;
|
||||
import com.sap.sailing.simulator.util.SailingSimulatorConstants;
|
||||
import com.sap.sailing.simulator.windfield.WindControlParameters;
|
||||
import com.sap.sailing.simulator.windfield.WindFieldGenerator;
|
||||
@@ -33,7 +34,7 @@ import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
public class SimulatorTest {
|
||||
|
||||
@Test
|
||||
public void testSailingSimulatorALL() {
|
||||
public void testSailingSimulatorALL() throws SparsePolarDataException {
|
||||
|
||||
// race course: copacabana, rio de janeiro, brasil
|
||||
Position start = new DegreePosition(-22.975779, -43.17421);
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package com.sap.sailing.simulator;
|
||||
|
||||
import com.sap.sailing.simulator.impl.SparsePolarDataException;
|
||||
|
||||
public interface PathGenerator {
|
||||
|
||||
void setSimulationParameters(SimulationParameters params);
|
||||
|
||||
SimulationParameters getSimulationParameters();
|
||||
|
||||
Path getPath();
|
||||
Path getPath() throws SparsePolarDataException;
|
||||
|
||||
Path getPathEvenTimed(long stepMilliseconds);
|
||||
Path getPathEvenTimed(long stepMilliseconds) throws SparsePolarDataException;
|
||||
|
||||
public boolean isTimedOut();
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.sap.sailing.simulator;
|
||||
import java.util.List;
|
||||
|
||||
import com.sap.sailing.simulator.impl.MaximumTurnTimes;
|
||||
import com.sap.sailing.simulator.impl.SparsePolarDataException;
|
||||
|
||||
|
||||
public interface Simulator {
|
||||
@@ -11,7 +12,7 @@ public interface Simulator {
|
||||
|
||||
SimulationParameters getSimulationParameters();
|
||||
|
||||
Path getPath(PathType pathType, MaximumTurnTimes maxTurnTimes);
|
||||
Path getPath(PathType pathType, MaximumTurnTimes maxTurnTimes) throws SparsePolarDataException;
|
||||
|
||||
Path getRaceCourse();
|
||||
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ public class PathGeneratorBase implements PathGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getPath() {
|
||||
public Path getPath() throws SparsePolarDataException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PathGeneratorBase implements PathGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getPathEvenTimed(long stepMilliseconds) {
|
||||
public Path getPathEvenTimed(long stepMilliseconds) throws SparsePolarDataException {
|
||||
|
||||
Path path = this.getPath();
|
||||
|
||||
|
||||
+20
-11
@@ -109,7 +109,7 @@ public class PathGeneratorTreeGrow360 extends PathGeneratorBase {
|
||||
// default: L - left, R - right
|
||||
// extended: M - wide left, S - wide right
|
||||
TimedPosition getStep(TimedPosition pos, Wind posWind, Position posEnd, long timeStep, long turnLoss, boolean sameBaseDirection,
|
||||
char nextDirection) {
|
||||
char nextDirection) throws SparsePolarDataException {
|
||||
|
||||
TimePoint curTime = pos.getTimePoint();
|
||||
Position curPosition = pos.getPosition();
|
||||
@@ -134,6 +134,11 @@ public class PathGeneratorTreeGrow360 extends PathGeneratorBase {
|
||||
if ((nextDirection == 'D')||(nextDirection == 'E')) {
|
||||
travelBearing = curPosition.getBearingGreatCircle(posEnd);
|
||||
}
|
||||
|
||||
if (travelBearing == null) {
|
||||
logger.severe("Travel Bearing for NextDirection '" + nextDirection + "' is NULL. This must NOT happen.");
|
||||
throw new SparsePolarDataException();
|
||||
}
|
||||
|
||||
// determine beat-speed left and right
|
||||
SpeedWithBearing travelSpeed = pd.getSpeedAtBearing(travelBearing);
|
||||
@@ -164,7 +169,7 @@ public class PathGeneratorTreeGrow360 extends PathGeneratorBase {
|
||||
|
||||
// get path candidate measuring height towards (local, current-apparent) wind
|
||||
PathCandidate getPathCandWind(PathCandidate path, char nextDirection, long timeStep, long turnLoss,
|
||||
Position posStart, Position posEnd, double tgtHeight) {
|
||||
Position posStart, Position posEnd, double tgtHeight) throws SparsePolarDataException {
|
||||
|
||||
char prevDirection = path.path.charAt(path.path.length() - 1);
|
||||
boolean sameBaseDirection = this.isSameDirection(prevDirection, nextDirection);
|
||||
@@ -230,7 +235,7 @@ public class PathGeneratorTreeGrow360 extends PathGeneratorBase {
|
||||
|
||||
// generate path candidates based on bearing to target
|
||||
List<PathCandidate> getPathCandsBeatWind(PathCandidate path, long timeStep, long turnLoss, Position posStart,
|
||||
Position posEnd, double tgtHeight) {
|
||||
Position posEnd, double tgtHeight) throws SparsePolarDataException {
|
||||
|
||||
// determine bearing of target
|
||||
Bearing bearTarget = path.pos.getPosition().getBearingGreatCircle(posEnd);
|
||||
@@ -307,8 +312,10 @@ public class PathGeneratorTreeGrow360 extends PathGeneratorBase {
|
||||
result.add(newPathCand);
|
||||
}
|
||||
// continuing step (may be required to reach target at all)
|
||||
newPathCand = getPathCandWind(path, prevDirection, timeStep, turnLoss, posStart, posEnd, tgtHeight);
|
||||
result.add(newPathCand);
|
||||
if ((prevDirection != reachingSide) && (prevDirection != '0')) {
|
||||
newPathCand = getPathCandWind(path, prevDirection, timeStep, turnLoss, posStart, posEnd, tgtHeight);
|
||||
result.add(newPathCand);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -337,8 +344,10 @@ public class PathGeneratorTreeGrow360 extends PathGeneratorBase {
|
||||
result.add(newPathCand);
|
||||
// continuing step (may be required to reach target at all)
|
||||
char prevDirection = path.path.charAt(path.path.length() - 1);
|
||||
newPathCand = getPathCandWind(path, prevDirection, timeStep, turnLoss, posStart, posEnd, tgtHeight);
|
||||
result.add(newPathCand);
|
||||
if ((prevDirection != reachingSide) && (prevDirection != '0')) {
|
||||
newPathCand = getPathCandWind(path, prevDirection, timeStep, turnLoss, posStart, posEnd, tgtHeight);
|
||||
result.add(newPathCand);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -347,7 +356,7 @@ public class PathGeneratorTreeGrow360 extends PathGeneratorBase {
|
||||
}
|
||||
|
||||
Util.Pair<List<PathCandidate>, List<PathCandidate>> generateCandidate(List<PathCandidate> oldPaths, long timeStep,
|
||||
long turnLoss, Position posStart, Position posMiddle, Position posEnd, double tgtHeight) {
|
||||
long turnLoss, Position posStart, Position posMiddle, Position posEnd, double tgtHeight) throws SparsePolarDataException {
|
||||
|
||||
List<PathCandidate> newPathCands;
|
||||
List<PathCandidate> leftPaths = new ArrayList<PathCandidate>();
|
||||
@@ -533,7 +542,7 @@ public class PathGeneratorTreeGrow360 extends PathGeneratorBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getPath() {
|
||||
public Path getPath() throws SparsePolarDataException {
|
||||
this.algorithmStartTime = MillisecondsTimePoint.now();
|
||||
|
||||
WindFieldGenerator wf = this.parameters.getWindField();
|
||||
@@ -853,9 +862,9 @@ public class PathGeneratorTreeGrow360 extends PathGeneratorBase {
|
||||
SimpleDateFormat racetimeFormat = new SimpleDateFormat("HH:mm:ss:SSS");
|
||||
racetimeFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
String racetimeFormatted = racetimeFormat.format(cal.getTime());
|
||||
logger.info("\nPath: " + bestCand.path +"\n Time: "
|
||||
logger.info("Start Condition: " + this.initPathStr + "\nPath: " + bestCand.path +"\n Time: "
|
||||
+ racetimeFormatted + ", Distance: "
|
||||
+ String.format("%.2f", Math.round(bestCand.pos.getPosition().getDistance(endPos).getMeters() * 100.0) / 100.0) + "meters"
|
||||
+ String.format("%.2f", Math.round(bestCand.pos.getPosition().getDistance(endPos).getMeters() * 100.0) / 100.0) + " meters"
|
||||
+ ", " + bestCand.trn + " Turn" + (bestCand.trn>1?"s":""));
|
||||
|
||||
return new PathImpl(path, wf, maxTurnTime, this.algorithmTimedOut);
|
||||
|
||||
+1
-1
@@ -813,7 +813,7 @@ public class PolarDiagramBase implements PolarDiagram, Serializable {
|
||||
// TODO: retrieve values from polar data mining
|
||||
int turnLoss;
|
||||
if (this.boatClass.getDisplayName().equals(BoatClassMasterdata.EXTREME_40.getDisplayName())) {
|
||||
turnLoss = 1000;
|
||||
turnLoss = 2000;
|
||||
} else if (this.boatClass.getDisplayName().equals(BoatClassMasterdata._5O5.getDisplayName())) {
|
||||
turnLoss = 5000;
|
||||
} else {
|
||||
|
||||
+5
-5
@@ -40,23 +40,23 @@ public class SimulatorImpl implements Simulator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getPath(PathType pathType, MaximumTurnTimes maxTurnTimes) {
|
||||
PathGeneratorTreeGrow genTreeGrow;
|
||||
public Path getPath(PathType pathType, MaximumTurnTimes maxTurnTimes) throws SparsePolarDataException {
|
||||
PathGeneratorTreeGrow360 genTreeGrow;
|
||||
PathGeneratorOpportunistEuclidian genOpportunistic;
|
||||
Path path = null;
|
||||
switch (pathType) {
|
||||
case OMNISCIENT:
|
||||
genTreeGrow = new PathGeneratorTreeGrow(this.simulationParameters); // instantiate heuristic searcher
|
||||
genTreeGrow = new PathGeneratorTreeGrow360(this.simulationParameters); // instantiate heuristic searcher
|
||||
genTreeGrow.setEvaluationParameters(null, 0, null); // allow for arbitrary many turns
|
||||
path = genTreeGrow.getPath();
|
||||
break;
|
||||
case ONE_TURNER_LEFT:
|
||||
genTreeGrow = new PathGeneratorTreeGrow(this.simulationParameters); // instantiate heuristic searcher
|
||||
genTreeGrow = new PathGeneratorTreeGrow360(this.simulationParameters); // instantiate heuristic searcher
|
||||
genTreeGrow.setEvaluationParameters("L", 1, null); // start left and limit to one turn
|
||||
path = genTreeGrow.getPath();
|
||||
break;
|
||||
case ONE_TURNER_RIGHT:
|
||||
genTreeGrow = new PathGeneratorTreeGrow(this.simulationParameters); // instantiate heuristic searcher
|
||||
genTreeGrow = new PathGeneratorTreeGrow360(this.simulationParameters); // instantiate heuristic searcher
|
||||
genTreeGrow.setEvaluationParameters("R", 1, null); // start right and limit to one turn
|
||||
path = genTreeGrow.getPath();
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user