mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-17 01:31:01 +00:00
implemented a functional heuristic in createHeuristic and a demo roundtrip
for it
This commit is contained in:
1 parent
8d9770c7c2
commit
fdc36871c2
1 file changed
+67
-7
+67
-7
@@ -3,9 +3,13 @@ package com.sap.sailing.simulator.impl;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sap.sailing.domain.base.SpeedWithBearing;
|
||||
import com.sap.sailing.domain.base.impl.MeterDistance;
|
||||
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.Bearing;
|
||||
import com.sap.sailing.domain.common.Distance;
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.domain.common.Speed;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.DegreeBearingImpl;
|
||||
import com.sap.sailing.domain.common.impl.DegreePosition;
|
||||
@@ -41,7 +45,7 @@ public class SailingSimulatorImpl implements SailingSimulator {
|
||||
|
||||
//calls either createDummy or createHeuristic()
|
||||
|
||||
return createDummy();
|
||||
return createHeuristic();
|
||||
}
|
||||
|
||||
private Path createDummy() {
|
||||
@@ -64,20 +68,76 @@ public class SailingSimulatorImpl implements SailingSimulator {
|
||||
}
|
||||
|
||||
private Path createHeuristic() {
|
||||
Boundary boundary = simulationParameters.getBoundaries();
|
||||
WindField wf = simulationParameters.getWindField();
|
||||
PolarDiagram pd = simulationParameters.getBoatPolarDiagram();
|
||||
Position start = simulationParameters.getCourse().get(0);
|
||||
Position end = simulationParameters.getCourse().get(1);
|
||||
TimePoint startTime = new MillisecondsTimePoint(0);
|
||||
List<TimedPositionWithSpeed> lst = new ArrayList<TimedPositionWithSpeed>();
|
||||
|
||||
Position currentPosition = start;
|
||||
TimePoint currentTime = startTime;
|
||||
|
||||
return null;
|
||||
//while there is more than 5% of the total distance to the finish
|
||||
while ( currentPosition.getDistance(end).compareTo(start.getDistance(end).scale(0.05)) > 0) {
|
||||
|
||||
TimePoint nextTime = new MillisecondsTimePoint(currentTime.asMillis() + 30000);
|
||||
|
||||
pd.setWind(wf.getWind(new TimedPositionWithSpeedSimple(currentPosition)));
|
||||
|
||||
Bearing lft = pd.optimalDirectionsDownwind()[0];
|
||||
Bearing rght = pd.optimalDirectionsUpwind()[1];
|
||||
Bearing direct = currentPosition.getBearingGreatCircle(end);
|
||||
|
||||
SpeedWithBearing sdirect = pd.getSpeedAtBearing(direct);
|
||||
SpeedWithBearing slft= pd.getSpeedAtBearing(lft);
|
||||
SpeedWithBearing srght = pd.getSpeedAtBearing(rght);
|
||||
|
||||
Position pdirect = sdirect.travelTo(currentPosition, currentTime, nextTime);
|
||||
Position plft = slft.travelTo(currentPosition, currentTime, nextTime);
|
||||
Position prght = srght.travelTo(currentPosition, currentTime, nextTime);
|
||||
|
||||
Distance ddirect = pdirect.getDistance(end);
|
||||
Distance dlft = plft.getDistance(end);
|
||||
Distance drght = prght.getDistance(end);
|
||||
|
||||
if(ddirect.compareTo(dlft)<=0 && ddirect.compareTo(drght)<=0) {
|
||||
lst.add(new TimedPositionWithSpeedImpl(nextTime, pdirect, sdirect));
|
||||
currentPosition = pdirect;
|
||||
}
|
||||
|
||||
if(dlft.compareTo(ddirect)<=0 && dlft.compareTo(drght)<=0) {
|
||||
lst.add(new TimedPositionWithSpeedImpl(nextTime, plft, slft));
|
||||
currentPosition = plft;
|
||||
}
|
||||
|
||||
if(drght.compareTo(dlft)<=0 && drght.compareTo(ddirect)<=0) {
|
||||
lst.add(new TimedPositionWithSpeedImpl(nextTime, prght, srght));
|
||||
currentPosition = prght;
|
||||
}
|
||||
|
||||
currentTime = nextTime;
|
||||
|
||||
}
|
||||
|
||||
return new PathImpl(lst);
|
||||
}
|
||||
|
||||
//SailingSimulator roundtrip
|
||||
public static void main(String args[]) {
|
||||
Position p1 = new DegreePosition(25.045792, -91.472168);
|
||||
Position p2 = new DegreePosition(26.076521,-89.681396);
|
||||
Position p1 = new DegreePosition(25.661333,-90.752563);
|
||||
Position p2 = new DegreePosition(24.522137,-90.774536);
|
||||
|
||||
Boundary b = new RectangularBoundary(p1, p2);
|
||||
|
||||
System.out.println(b.getCorners());
|
||||
Distance dist = p1.getDistance(p2);
|
||||
//the Speed required to go from p1 to p2 in 10 minutes
|
||||
Speed requiredSpeed10 = dist.inTime(600000);
|
||||
|
||||
WindField wf = new WindFieldImpl(b, 20, 45);
|
||||
//I am creating the WindField such as the course goes mainly against the wind (as it should)
|
||||
//and the speed of the wind would go over the course in 10 minutes (for the sake of the running time)
|
||||
WindField wf = new WindFieldImpl(b, requiredSpeed10.getKilometersPerHour(), b.getSouth().getDegrees());
|
||||
PolarDiagram pd = new PolarDiagramImpl(1);
|
||||
List<Position> course= new ArrayList<Position>();
|
||||
course.add(p1);
|
||||
@@ -87,7 +147,7 @@ public class SailingSimulatorImpl implements SailingSimulator {
|
||||
|
||||
Path pth = solver.getOptimumPath();
|
||||
|
||||
for(TimedPosition p : pth.getEvenTimedPoints(360000)) {
|
||||
for(TimedPositionWithSpeed p : pth.getPathPoints()) {
|
||||
System.out.println("Position: " + p.getPosition() + " Wind: " + wf.getWind(new TimedPositionWithSpeedSimple(p.getPosition())));
|
||||
}
|
||||
//the null in the Wind output is the timestamp - this Wind is time-invariant!
|
||||
|
||||
Reference in new issue
Block a user