From 4c8c75ca3868e944fad70e7998de4476d9c1181c Mon Sep 17 00:00:00 2001 From: "Christopher Ronnewinkel (D036654)" Date: Fri, 1 Feb 2013 16:00:13 +0100 Subject: [PATCH] tree grow: keep horizontal bins fixed with regards to race course --- java/com.sap.sailing.gwt.ui/.classpath | 2 +- .../SailingServer (No Proxy).launch | 2 +- .../SailingServer (Proxy).launch | 2 +- .../com.sap.sailing.simulator.test/.classpath | 2 +- .../impl/PathGeneratorTreeGrowWind.java | 6 +- .../simulator/impl/SailingSimulatorImpl.java | 93 ++++++++++--------- 6 files changed, 58 insertions(+), 49 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/.classpath b/java/com.sap.sailing.gwt.ui/.classpath index ecd3e9b3c2d..52b2e581ab3 100755 --- a/java/com.sap.sailing.gwt.ui/.classpath +++ b/java/com.sap.sailing.gwt.ui/.classpath @@ -6,7 +6,7 @@ - + diff --git a/java/com.sap.sailing.server/SailingServer (No Proxy).launch b/java/com.sap.sailing.server/SailingServer (No Proxy).launch index 8ae94d50478..691b88d9f3f 100755 --- a/java/com.sap.sailing.server/SailingServer (No Proxy).launch +++ b/java/com.sap.sailing.server/SailingServer (No Proxy).launch @@ -17,7 +17,7 @@ - + diff --git a/java/com.sap.sailing.server/SailingServer (Proxy).launch b/java/com.sap.sailing.server/SailingServer (Proxy).launch index de1e6af6090..20947235a74 100755 --- a/java/com.sap.sailing.server/SailingServer (Proxy).launch +++ b/java/com.sap.sailing.server/SailingServer (Proxy).launch @@ -17,7 +17,7 @@ - + diff --git a/java/com.sap.sailing.simulator.test/.classpath b/java/com.sap.sailing.simulator.test/.classpath index 1703b8ce8ff..f3de24b7a85 100644 --- a/java/com.sap.sailing.simulator.test/.classpath +++ b/java/com.sap.sailing.simulator.test/.classpath @@ -3,7 +3,7 @@ - + diff --git a/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/PathGeneratorTreeGrowWind.java b/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/PathGeneratorTreeGrowWind.java index dcc9438a9ad..e4850b2a0b4 100644 --- a/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/PathGeneratorTreeGrowWind.java +++ b/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/PathGeneratorTreeGrowWind.java @@ -173,8 +173,8 @@ public class PathGeneratorTreeGrowWind extends PathGeneratorBase { // calculate height-position with reference to race course Position posHeight = pathPos.getPosition().projectToLineThrough(posEnd, posWind.getBearing()); - //Bearing bearVrt = posStart.getBearingGreatCircle(posEnd); - //Position posHeightTrgt = pathPos.getPosition().projectToLineThrough(posStart, bearVrt); + Bearing bearVrt = posStart.getBearingGreatCircle(posEnd); + Position posHeightTrgt = pathPos.getPosition().projectToLineThrough(posStart, bearVrt); //Position posHeightWind = pathPos.getPosition().projectToLineThrough(posRef, posWind.getBearing()); // calculate vertical distance as distance of height-position to start @@ -202,7 +202,7 @@ public class PathGeneratorTreeGrowWind extends PathGeneratorBase { } // calculate horizontal distance as distance of height-position to current position //double hrzDist = Math.round(posSide*posHeight.getDistance(pathPos.getPosition()).getMeters()*100.0)/100.0; - double hrzDist = Math.round(posSide*posHeight.getDistance(pathPos.getPosition()).getMeters()*100.0)/100.0; + double hrzDist = Math.round(posSide*posHeightTrgt.getDistance(pathPos.getPosition()).getMeters()*100.0)/100.0; //System.out.println(""+hrzDist+", "+vrtDist+", "+pathPos.getPosition().getLatDeg()+", "+pathPos.getPosition().getLngDeg()+", "+posHeight.getLatDeg()+", "+posHeight.getLngDeg()); diff --git a/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/SailingSimulatorImpl.java b/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/SailingSimulatorImpl.java index 8d66e61b07a..676c78d59e8 100644 --- a/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/SailingSimulatorImpl.java +++ b/java/com.sap.sailing.simulator/src/com/sap/sailing/simulator/impl/SailingSimulatorImpl.java @@ -27,9 +27,9 @@ import com.sap.sailing.domain.common.Position; import com.sap.sailing.domain.common.impl.DegreeBearingImpl; import com.sap.sailing.simulator.Boundary; import com.sap.sailing.simulator.Path; -import com.sap.sailing.simulator.PathGenerator; import com.sap.sailing.simulator.SailingSimulator; import com.sap.sailing.simulator.SimulationParameters; +import com.sap.sailing.simulator.impl.PathGeneratorTreeGrowWind.PathCand; import com.sap.sailing.simulator.util.SailingSimulatorUtil; import com.sap.sailing.simulator.windfield.WindFieldGenerator; import com.sap.sailing.simulator.windfield.impl.WindFieldGeneratorMeasured; @@ -127,8 +127,10 @@ public class SailingSimulatorImpl implements SailingSimulator { //System.out.println("baseWindBearing: " + wf.getWindParameters().baseWindBearing); logger.info("base wind: "+this.simulationParameters.getBoatPolarDiagram().getWind().getKnots()+" kn, "+((wf.getWindParameters().baseWindBearing)%360.0)+"°"); + // initialize interpolation table for getSpeedAtBearingOverGround, e.g. for what-if or for optimization on overground-grids + //this.simulationParameters.getBoatPolarDiagram().setCurrent(null); // initialize + // set water current - this.simulationParameters.getBoatPolarDiagram().setCurrent(null); // initialize //this.simulationParameters.getBoatPolarDiagram().setCurrent(new KnotSpeedWithBearingImpl(0.0,new DegreeBearingImpl((wf.getWindParameters().baseWindBearing+90.0)%360.0))); this.simulationParameters.getBoatPolarDiagram().setCurrent(new KnotSpeedWithBearingImpl(wf.getWindParameters().curSpeed, new DegreeBearingImpl(wf.getWindParameters().curBearing))); //this.simulationParameters.getBoatPolarDiagram().setCurrent(new KnotSpeedWithBearingImpl(2.0,new DegreeBearingImpl((270.0)%360.0))); @@ -146,29 +148,34 @@ public class SailingSimulatorImpl implements SailingSimulator { // Start Simulation // - // get 1-turners - final PathGenerator1Turner gen1Turner = new PathGenerator1Turner(this.simulationParameters); - gen1Turner.setEvaluationParameters(true, null, null, 0, 0, 0); - final Path leftPath = gen1Turner.getPath(); - final int left1TurnMiddle = gen1Turner.getMiddle(); - gen1Turner.setEvaluationParameters(false, null, null, 0, 0, 0); - final Path rightPath = gen1Turner.getPath(); - final int right1TurnMiddle = gen1Turner.getMiddle(); + // get instance of heuristic searcher + PathGeneratorTreeGrowWind genTreeGrow = new PathGeneratorTreeGrowWind(this.simulationParameters); + + // search best left-starting 1-turner + genTreeGrow.setEvaluationParameters("L", 1); + Path leftPath = genTreeGrow.getPath(); + PathCand leftBestCand = genTreeGrow.getBestCand(); + int left1TurnMiddle = leftBestCand.path.indexOf("LR"); - // get left- and right-going heuristic based on 1-turner - final PathGeneratorOpportunistEuclidian genOpportunistic = new PathGeneratorOpportunistEuclidian( - this.simulationParameters); + // search best right-starting 1-turner + genTreeGrow.setEvaluationParameters("R", 1); + Path rightPath = genTreeGrow.getPath(); + PathCand rightBestCand = genTreeGrow.getBestCand(); + int right1TurnMiddle = rightBestCand.path.indexOf("RL"); + + // evaluate opportunistic heuristic + PathGeneratorOpportunistEuclidian genOpportunistic = new PathGeneratorOpportunistEuclidian(this.simulationParameters); // PathGeneratorOpportunistVMG genOpportunistic = new PathGeneratorOpportunistVMG(simulationParameters); + + // left-starting opportunist genOpportunistic.setEvaluationParameters(left1TurnMiddle, right1TurnMiddle, true); - final Path oppPathL = genOpportunistic.getPath(); + Path oppPathL = genOpportunistic.getPath(); + // right-starting opportunist genOpportunistic.setEvaluationParameters(left1TurnMiddle, right1TurnMiddle, false); - final Path oppPathR = genOpportunistic.getPath(); + Path oppPathR = genOpportunistic.getPath(); + // compare left- & right-starting opportunists Path oppPath = null; - // System.out.println("left -going: "+oppPathL.getPathPoints().get(oppPathL.getPathPoints().size() - - // 1).getTimePoint().asMillis()); - // System.out.println("right-going: "+oppPathR.getPathPoints().get(oppPathR.getPathPoints().size() - - // 1).getTimePoint().asMillis()); if (oppPathL.getPathPoints().get(oppPathL.getPathPoints().size() - 1).getTimePoint().asMillis() <= oppPathR .getPathPoints().get(oppPathR.getPathPoints().size() - 1).getTimePoint().asMillis()) { oppPath = oppPathL; @@ -176,41 +183,43 @@ public class SailingSimulatorImpl implements SailingSimulator { oppPath = oppPathR; } - // get optimal path from dynamic programming with forward iteration - final PathGenerator genDynProgForward = new PathGeneratorDynProgForward(this.simulationParameters); - Path optPath = genDynProgForward.getPath(); + // search best multi-turn course + genTreeGrow.setEvaluationParameters(null, 0); + Path optPath = genTreeGrow.getPath(); // // NOTE: pathName convention is: sort-digit + "#" + path-name // The sort-digit defines the sorting of paths in webbrowser // - // compare paths to avoid misleading display due to artifactual results from optimization (caused by finite - // resolution of optimization grid) - if (leftPath.getPathPoints() != null) { - if (leftPath.getPathPoints().get(leftPath.getPathPoints().size() - 1).getTimePoint().asMillis() <= optPath - .getPathPoints().get(optPath.getPathPoints().size() - 1).getTimePoint().asMillis()) { - optPath = leftPath; + boolean plausCheck = false; + // ensure omniscient is best avoiding artifactual results due to coarse-grainedness (finite timesteps) of course generation + if (plausCheck) { + if (leftPath.getPathPoints() != null) { + if (leftPath.getPathPoints().get(leftPath.getPathPoints().size() - 1).getTimePoint().asMillis() <= optPath.getPathPoints().get(optPath.getPathPoints().size() - 1).getTimePoint() + .asMillis()) { + optPath = leftPath; + } } - allPaths.put("3#1-Turner Left", leftPath); - } - if (rightPath.getPathPoints() != null) { - if (rightPath.getPathPoints().get(rightPath.getPathPoints().size() - 1).getTimePoint().asMillis() <= optPath - .getPathPoints().get(optPath.getPathPoints().size() - 1).getTimePoint().asMillis()) { - optPath = rightPath; + if (rightPath.getPathPoints() != null) { + if (rightPath.getPathPoints().get(rightPath.getPathPoints().size() - 1).getTimePoint().asMillis() <= optPath.getPathPoints().get(optPath.getPathPoints().size() - 1).getTimePoint() + .asMillis()) { + optPath = rightPath; + } } - allPaths.put("4#1-Turner Right", rightPath); - } - if (oppPath != null) { - if (oppPath.getPathPoints().get(oppPath.getPathPoints().size() - 1).getTimePoint().asMillis() <= optPath - .getPathPoints().get(optPath.getPathPoints().size() - 1).getTimePoint().asMillis()) { - optPath = oppPath; + if (oppPath != null) { + if (oppPath.getPathPoints().get(oppPath.getPathPoints().size() - 1).getTimePoint().asMillis() <= optPath.getPathPoints().get(optPath.getPathPoints().size() - 1).getTimePoint() + .asMillis()) { + optPath = oppPath; + } } - allPaths.put("2#Opportunistic", oppPath); } - + + allPaths.put("4#1-Turner Right", rightPath); + allPaths.put("3#1-Turner Left", leftPath); + allPaths.put("2#Opportunistic", oppPath); allPaths.put("1#Omniscient", optPath); if (this.simulationParameters.getMode() == SailingSimulatorUtil.measured) {