From bbebd762d683b218fd59dc922f20ef75cbb89a98 Mon Sep 17 00:00:00 2001 From: "Christopher Ronnewinkel (D036654)" Date: Wed, 29 Apr 2015 14:44:59 +0200 Subject: [PATCH] handle sparse-simulation-data-exception; further improvement for finish-phase of opportunist-360; --- .../simulator/impl/PathGeneratorBase.java | 2 +- .../PathGeneratorOpportunistEuclidian360.java | 29 ++++++++- .../sailing/simulator/impl/SimulatorImpl.java | 60 +++++++++++-------- 3 files changed, 61 insertions(+), 30 deletions(-) diff --git a/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/PathGeneratorBase.java b/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/PathGeneratorBase.java index c1f571f2896..e6761c48730 100644 --- a/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/PathGeneratorBase.java +++ b/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/PathGeneratorBase.java @@ -11,7 +11,7 @@ import com.sap.sse.common.impl.MillisecondsTimePoint; public class PathGeneratorBase implements PathGenerator { protected SimulationParameters parameters; - protected final Duration algorithmMaxDuration = new MillisecondsDurationImpl(2*60*1000); // 2 minutes maximum duration of one path generation + protected final Duration algorithmMaxDuration = new MillisecondsDurationImpl(20000); // 20 seconds maximum duration of one path generation protected TimePoint algorithmStartTime; protected boolean algorithmTimedOut = false; diff --git a/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/PathGeneratorOpportunistEuclidian360.java b/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/PathGeneratorOpportunistEuclidian360.java index ed40ab424d6..05df87f733a 100644 --- a/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/PathGeneratorOpportunistEuclidian360.java +++ b/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/PathGeneratorOpportunistEuclidian360.java @@ -78,6 +78,7 @@ public class PathGeneratorOpportunistEuclidian360 extends PathGeneratorBase { double currentHeight = startPos.getDistance(endPos).getMeters(); BoatDirection prevDirection = BoatDirection.NONE; + BoatDirection prevPrevDirection = BoatDirection.NONE; long turnLoss = polarDiagram.getTurnLoss(); // time lost when doing a turn double fracFinishPhase = 0.05; @@ -199,9 +200,10 @@ public class PathGeneratorOpportunistEuclidian360 extends PathGeneratorBase { Distance targetDistanceRight = nextBoatPositionRight.getDistance(endPos); double targetDistanceMetersLeft = Math.round(targetDistanceLeft.getMeters() * 1000.) / 1000.; double targetDistanceMetersRight = Math.round(targetDistanceRight.getMeters() * 1000.) / 1000.; - + prevPrevDirection = prevDirection; + if (prevDirection == BoatDirection.NONE) { - + if (startLeft) { if (pointOfSail == PointOfSail.TACKING) { path.add(new TimedPositionWithSpeedImpl(nextTime, nextBoatPositionLeft, currentWind)); @@ -287,6 +289,7 @@ public class PathGeneratorOpportunistEuclidian360 extends PathGeneratorBase { turns++; } + prevPrevDirection = prevDirection; prevDirection = reachingSide; if (reachingSide == BoatDirection.REACH_LEFT) { pathStr += "D"; @@ -299,7 +302,27 @@ public class PathGeneratorOpportunistEuclidian360 extends PathGeneratorBase { Position posHeight = currentPosition.projectToLineThrough(startPos, bearStart); currentHeight = startPos.getDistance(endPos).getMeters() - posHeight.getDistance(startPos).getMeters(); } - + + // remove last position, if already too close to target for finish-phase + if (currentHeight < startPos.getDistance(endPos).getMeters()*fracFinishPhase/2) { + path.remove(path.size()-1); + currentTime = path.get(path.size()-1).getTimePoint(); + currentPosition = path.get(path.size()-1).getPosition(); + prevDirection = prevPrevDirection; + } else { + // get bearing to target + Bearing nextBearTarget = currentPosition.getBearingGreatCircle(endPos); + // get point-of-sail and reaching-side + Pair nextPointOfSailAndReachingSide = polarDiagram.getPointOfSail(nextBearTarget); + PointOfSail nextPointOfSail = nextPointOfSailAndReachingSide.getA(); + if (nextPointOfSail == PointOfSail.REACHING) { + path.remove(path.size()-1); + currentTime = path.get(path.size()-1).getTimePoint(); + currentPosition = path.get(path.size()-1).getPosition(); + prevDirection = prevPrevDirection; + } + } + if (!this.isTimedOut()) { // // FinishPhase: get 1-turners to finalize course diff --git a/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/SimulatorImpl.java b/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/SimulatorImpl.java index 0ede09e556b..d993a4bd300 100644 --- a/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/SimulatorImpl.java +++ b/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/SimulatorImpl.java @@ -10,6 +10,7 @@ import com.sap.sailing.simulator.RaceProperties; import com.sap.sailing.simulator.SimulationParameters; import com.sap.sailing.simulator.Simulator; import com.sap.sailing.simulator.SimulatorUISelection; +import com.sap.sailing.simulator.TimedPositionWithSpeed; import com.sap.sailing.simulator.util.SailingSimulatorConstants; public class SimulatorImpl implements Simulator { @@ -44,32 +45,39 @@ public class SimulatorImpl implements Simulator { PathGeneratorTreeGrow360 genTreeGrow; PathGeneratorOpportunistEuclidian360 genOpportunistic; Path path = null; - switch (pathType) { - case OMNISCIENT: - 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 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 PathGeneratorTreeGrow360(this.simulationParameters); // instantiate heuristic searcher - genTreeGrow.setEvaluationParameters("R", 1, null); // start right and limit to one turn - path = genTreeGrow.getPath(); - break; - case OPPORTUNIST_LEFT: - genOpportunistic = new PathGeneratorOpportunistEuclidian360(this.simulationParameters); // instantiate greedy searcher - genOpportunistic.setEvaluationParameters(true); // use maxTurnTimes of 1-turners to avoid passing of lay lines - path = genOpportunistic.getPath(); - break; - case OPPORTUNIST_RIGHT: - genOpportunistic = new PathGeneratorOpportunistEuclidian360(this.simulationParameters); // instantiate greedy searcher - genOpportunistic.setEvaluationParameters(false); // use maxTurnTimes of 1-turners to avoid passing of lay lines - path = genOpportunistic.getPath(); - break; + try { + switch (pathType) { + case OMNISCIENT: + 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 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 PathGeneratorTreeGrow360(this.simulationParameters); // instantiate heuristic searcher + genTreeGrow.setEvaluationParameters("R", 1, null); // start right and limit to one turn + path = genTreeGrow.getPath(); + break; + case OPPORTUNIST_LEFT: + genOpportunistic = new PathGeneratorOpportunistEuclidian360(this.simulationParameters); // instantiate greedy searcher + genOpportunistic.setEvaluationParameters(true); // use maxTurnTimes of 1-turners to avoid passing of lay lines + path = genOpportunistic.getPath(); + break; + case OPPORTUNIST_RIGHT: + genOpportunistic = new PathGeneratorOpportunistEuclidian360(this.simulationParameters); // instantiate greedy searcher + genOpportunistic.setEvaluationParameters(false); // use maxTurnTimes of 1-turners to avoid passing of lay lines + path = genOpportunistic.getPath(); + break; + } + } catch (SparseSimulationDataException e) { + LOGGER.warning(e.getMessage() + "(PathType: " + pathType.getTxtId() + ")"); + List points = new ArrayList(); + points.add(new TimedPositionWithSpeedImpl(this.simulationParameters.getWindField().getStartTime(), this.simulationParameters.getCourse().get(0), null)); + path = new PathImpl(points, null, 0, true, false); } return path; }