Changed Test to pass in fixes one by one.

This commit is contained in:
Nick Klose committed 2013-11-25 14:47:54 +01:00
1 parent 2a37662ca5
commit 93b06f64f2
6 files changed
+85 -77

No files matched your search

@@ -146,12 +146,10 @@ public class AbstractPosition implements Position {
.getDegrees()); .getDegrees());
if (toLeft > 90) { if (toLeft > 90) {
distance = this.getDistance(left); distance = this.getDistance(left);
} else { } else if (toRight > 90) {
if (toRight > 90) {
distance = this.getDistance(right); distance = this.getDistance(right);
} else { } else {
distance = this.absoluteCrossTrackError(left, left.getBearingGreatCircle(right)); distance = this.absoluteCrossTrackError(left, left.getBearingGreatCircle(right));
}
} }
// Right now this always returns a positiv value. It might be possible to change it so that the sign indicates // Right now this always returns a positiv value. It might be possible to change it so that the sign indicates
// which side of the Line the Position is on. // which side of the Line the Position is on.
@@ -116,12 +116,12 @@ public class CandidateChooser {
} }
private double numberOfCloseStarts(TimePoint t) { private double numberOfCloseStarts(TimePoint t) {
double numberOfSimilarStarts = -1; double numberOfSimilarStarts = 0;
double numberOfCompetitors = -1; double numberOfCompetitors = 0;
for (Competitor c : candidates.keySet()) { for (Competitor c : candidates.keySet()) {
numberOfCompetitors++; numberOfCompetitors++;
for (Candidate ca : candidates.get(c)) { for (Candidate ca : candidates.get(c)) {
if (ca.getID() == 1 && Math.abs(ca.getTimePoint().asMillis() - t.asMillis()) < 60000) { if (ca.getID() == 1 && Math.abs(ca.getTimePoint().asMillis() - t.asMillis()) < 30000) {
numberOfSimilarStarts++; numberOfSimilarStarts++;
break; break;
} }
@@ -163,6 +163,6 @@ public class CandidateChooser {
totalTime = totalTime * 3600000; totalTime = totalTime * 3600000;
double actualTime = c2.getTimePoint().asMillis() - c1.getTimePoint().asMillis(); double actualTime = c2.getTimePoint().asMillis() - c1.getTimePoint().asMillis();
double timeDiff = Math.abs(totalTime - actualTime) / 1000; double timeDiff = Math.abs(totalTime - actualTime) / 1000;
return 1 - (Math.log10(timeDiff+1) / 20); return 1-(Math.log10(timeDiff+1)/20);
} }
} }
@@ -14,6 +14,7 @@ import com.sap.sailing.domain.common.Position;
import com.sap.sailing.domain.common.TimePoint; import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.domain.tracking.DynamicGPSFixTrack; import com.sap.sailing.domain.tracking.DynamicGPSFixTrack;
import com.sap.sailing.domain.tracking.GPSFix; import com.sap.sailing.domain.tracking.GPSFix;
import com.sap.sailing.domain.tracking.GPSFixMoving;
import com.sap.sailing.domain.tracking.TrackedLeg; import com.sap.sailing.domain.tracking.TrackedLeg;
import com.sap.sailing.domain.tracking.impl.DynamicTrackImpl; import com.sap.sailing.domain.tracking.impl.DynamicTrackImpl;
@@ -59,7 +60,7 @@ public class CandidateFinder {
} }
} }
public void newCompetitorFix(GPSFix fix, Competitor c) { public void newCompetitorFix(GPSFixMoving fix, Competitor c) {
competitorTracks.get(c).addGPSFix(fix); competitorTracks.get(c).addGPSFix(fix);
distances.get(c).put(fix, new LinkedHashMap<Waypoint, Double>()); distances.get(c).put(fix, new LinkedHashMap<Waypoint, Double>());
for (Waypoint w : waypoints) { for (Waypoint w : waypoints) {
@@ -94,11 +95,10 @@ public class CandidateFinder {
for (Competitor c : competitorTracks.keySet()) { for (Competitor c : competitorTracks.keySet()) {
ArrayList<GPSFix> fixesAffected = new ArrayList<>(); ArrayList<GPSFix> fixesAffected = new ArrayList<>();
TimePoint t = start; TimePoint t = start;
while (!(competitorTracks.get(c).getFirstFixAfter(t) == null)) { while (competitorTracks.get(c).getFirstFixAfter(t) != null) {
GPSFix nextFix = competitorTracks.get(c).getFirstFixAfter(t); GPSFix nextFix = competitorTracks.get(c).getFirstFixAfter(t);
t = nextFix.getTimePoint(); t = nextFix.getTimePoint();
if (!(end == null) && !t.before(end)) { if (end!=null && !t.before(end)) {
fixesAffected.add(competitorTracks.get(c).getFirstFixAtOrAfter(end));
break; break;
} }
fixesAffected.add(nextFix); fixesAffected.add(nextFix);
@@ -106,18 +106,11 @@ public class CandidateFinder {
for (GPSFix gps : fixesAffected) { for (GPSFix gps : fixesAffected) {
distances.get(c).get(gps).put(w, calculateDistance(gps, w)); distances.get(c).get(gps).put(w, calculateDistance(gps, w));
} }
if (!(competitorTracks.get(c).getLastFixAtOrBefore(start) == null)) {
fixesAffected.add(competitorTracks.get(c).getLastFixAtOrBefore(start));
}
if (!fixesAffected.contains(competitorTracks.get(c).getLastFixBefore(start))
&& !(competitorTracks.get(c).getLastFixBefore(start) == null)) {
fixesAffected.add(competitorTracks.get(c).getLastFixBefore(start));
}
if (fixesAffected.size() > 0) { if (fixesAffected.size() > 0) {
System.out.println(fixesAffected.size());
reEvaluateFixes(fixesAffected, c, w); reEvaluateFixes(fixesAffected, c, w);
} }
} }
break;
} }
} }
} }
@@ -127,6 +120,8 @@ public class CandidateFinder {
for (GPSFix gps : fixes) { for (GPSFix gps : fixes) {
if (fixIsACandidate(gps, w, c) && !candidates.get(c).get(w).contains(gps)) { if (fixIsACandidate(gps, w, c) && !candidates.get(c).get(w).contains(gps)) {
candidates.get(c).get(w).add(gps); candidates.get(c).get(w).add(gps);
if (waypoints.indexOf(w) == 0) {
}
Candidate newCandidate = new Candidate(w, gps.getTimePoint(), getCost(distances.get(c).get(gps).get(w), Candidate newCandidate = new Candidate(w, gps.getTimePoint(), getCost(distances.get(c).get(gps).get(w),
getLegLength(gps.getTimePoint(), w)), waypoints.indexOf(w) + 1); getLegLength(gps.getTimePoint(), w)), waypoints.indexOf(w) + 1);
chooser.addCandidate(newCandidate, c); chooser.addCandidate(newCandidate, c);
@@ -154,15 +149,15 @@ public class CandidateFinder {
} }
private double getCost(Double distance, Double legLength) { private double getCost(Double distance, Double legLength) {
return 1/(10*Math.abs(distance/legLength)+1); return 1/(500*Math.abs(distance/legLength)+1);
} }
private boolean fixIsACandidate(GPSFix fix, Waypoint w, Competitor c) { private boolean fixIsACandidate(GPSFix fix, Waypoint w, Competitor c) {
GPSFix fixBefore = competitorTracks.get(c).getLastFixBefore(fix.getTimePoint()); GPSFix fixBefore = competitorTracks.get(c).getLastFixBefore(fix.getTimePoint());
GPSFix fixAfter = competitorTracks.get(c).getFirstFixAfter(fix.getTimePoint()); GPSFix fixAfter = competitorTracks.get(c).getFirstFixAfter(fix.getTimePoint());
if (distances.get(c).containsKey(fix) && !(fixBefore == null) if (distances.get(c).containsKey(fix) && !(fixBefore == null)
&& distances.get(c).get(fix).get(w) < distances.get(c).get(fixBefore).get(w) && !(fixAfter == null) && distances.get(c).get(fix).get(w) <= distances.get(c).get(fixBefore).get(w) && !(fixAfter == null)
&& distances.get(c).get(fix).get(w) < distances.get(c).get(fixAfter).get(w)) { && distances.get(c).get(fix).get(w) <= distances.get(c).get(fixAfter).get(w)) {
return true; return true;
} }
return false; return false;
@@ -198,7 +193,7 @@ public class CandidateFinder {
ArrayList<Position> positions = new ArrayList<>(); ArrayList<Position> positions = new ArrayList<>();
Iterator<Mark> it = w.getMarks().iterator(); Iterator<Mark> it = w.getMarks().iterator();
while (it.hasNext()) { while (it.hasNext()) {
positions.add(markTracks.get(it.next()).getEstimatedPosition(gps.getTimePoint(), true)); positions.add(markTracks.get(it.next()).getEstimatedPosition(gps.getTimePoint(), false));
} }
if (p.equals(PassingInstruction.Port) || p.equals(PassingInstruction.Starboard) if (p.equals(PassingInstruction.Port) || p.equals(PassingInstruction.Starboard)
|| p.equals(PassingInstruction.Offset) || p.equals(PassingInstruction.None)) { || p.equals(PassingInstruction.Offset) || p.equals(PassingInstruction.None)) {
@@ -206,6 +201,8 @@ public class CandidateFinder {
} }
if (p.equals(PassingInstruction.Line)) { if (p.equals(PassingInstruction.Line)) {
distance = gps.getPosition().getDistanceToLine(positions.get(0), positions.get(1)).getMeters(); distance = gps.getPosition().getDistanceToLine(positions.get(0), positions.get(1)).getMeters();
if(waypoints.indexOf(w)==0){
}
} }
if (p.equals(PassingInstruction.Gate)) { if (p.equals(PassingInstruction.Gate)) {
// Right now, both marks are observered, even though only one is actully rounded. // Right now, both marks are observered, even though only one is actully rounded.
@@ -9,7 +9,7 @@ public class Edge {
public Edge(Candidate start, Candidate end, double timeEstimation) { public Edge(Candidate start, Candidate end, double timeEstimation) {
this.start = start; this.start = start;
this.end = end; this.end = end;
penaltyForSkipped = 0.4; penaltyForSkipped = 0.2;
this.timeEstimation = timeEstimation; this.timeEstimation = timeEstimation;
} }
public String getIDs(){ public String getIDs(){
@@ -34,7 +34,6 @@ public class MarkPassingCalculator extends AbstractRaceChangeListener implements
if(startOfTracking==null){ if(startOfTracking==null){
startOfTracking = race.getTimePointOfOldestEvent(); startOfTracking = race.getTimePointOfOldestEvent();
} }
System.out.println(startOfTracking);
for (Waypoint w : race.getRace().getCourse().getWaypoints()) { for (Waypoint w : race.getRace().getCourse().getWaypoints()) {
waypoints.add(w); waypoints.add(w);
} }
@@ -1,7 +1,7 @@
package com.sap.sailing.domain.test.markpassing; package com.sap.sailing.domain.test.markpassing;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@@ -28,6 +28,7 @@ import com.sap.sailing.domain.common.impl.KnotSpeedWithBearingImpl;
import com.sap.sailing.domain.common.impl.MillisecondsTimePoint; import com.sap.sailing.domain.common.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.common.impl.WindSourceImpl; import com.sap.sailing.domain.common.impl.WindSourceImpl;
import com.sap.sailing.domain.test.OnlineTracTracBasedTest; import com.sap.sailing.domain.test.OnlineTracTracBasedTest;
import com.sap.sailing.domain.tracking.DynamicGPSFixTrack;
import com.sap.sailing.domain.tracking.DynamicTrackedRace; import com.sap.sailing.domain.tracking.DynamicTrackedRace;
import com.sap.sailing.domain.tracking.GPSFix; import com.sap.sailing.domain.tracking.GPSFix;
import com.sap.sailing.domain.tracking.GPSFixMoving; import com.sap.sailing.domain.tracking.GPSFixMoving;
@@ -48,36 +49,22 @@ public class MarkPassingCalculatorTest extends OnlineTracTracBasedTest {
testRace("04687b2a-9e68-11e0-85be-406186cbf87c"); testRace("04687b2a-9e68-11e0-85be-406186cbf87c");
} }
@Test
public void testTornado4() throws IOException, InterruptedException, URISyntaxException { @Test public void testTornado4() throws IOException, InterruptedException, URISyntaxException {
System.out.println("Tornado Race 4"); System.out.println("Tornado Race 4"); testRace("5291b3ea-9934-11e0-85be-406186cbf87c"); }
testRace("5291b3ea-9934-11e0-85be-406186cbf87c");
} @Test public void testStarMedal() throws IOException, InterruptedException, URISyntaxException {
System.out.println("Star Medal"); testRace("d591d808-9c48-11e0-85be-406186cbf87c"); }
@Test
public void testStarMedal() throws IOException, InterruptedException, URISyntaxException { @Test public void test505_2() throws IOException, InterruptedException, URISyntaxException {
System.out.println("Star Medal"); System.out.println("Tornado 16"); testRace("357c700a-9d9a-11e0-85be-406186cbf87c"); }
testRace("d591d808-9c48-11e0-85be-406186cbf87c");
} @Test public void test505_7() throws IOException, InterruptedException, URISyntaxException {
System.out.println("Tornado 16"); testRace("cb043bb4-9e92-11e0-85be-406186cbf87c"); }
@Test
public void test505_2() throws IOException, InterruptedException, URISyntaxException { @Test public void testStar4() throws IOException, InterruptedException, URISyntaxException {
System.out.println("Tornado 16"); System.out.println("Star 4"); testRace("f5f531ec-99ed-11e0-85be-406186cbf87c"); }
testRace("357c700a-9d9a-11e0-85be-406186cbf87c");
}
@Test
public void test505_7() throws IOException, InterruptedException, URISyntaxException {
System.out.println("Tornado 16");
testRace("cb043bb4-9e92-11e0-85be-406186cbf87c");
}
@Test
public void testStar4() throws IOException, InterruptedException, URISyntaxException {
System.out.println("Star 4");
testRace("f5f531ec-99ed-11e0-85be-406186cbf87c");
}
private void testRace(String raceID) throws IOException, InterruptedException, URISyntaxException { private void testRace(String raceID) throws IOException, InterruptedException, URISyntaxException {
setUp(raceID); setUp(raceID);
compareMarkpasses(); compareMarkpasses();
@@ -227,31 +214,57 @@ public class MarkPassingCalculatorTest extends OnlineTracTracBasedTest {
} }
} }
// Pass in Mark Fixes LinkedHashMap<Mark, GPSFix> nextMarkFix = new LinkedHashMap<>();
LinkedHashMap<Mark, DynamicGPSFixTrack<Mark, GPSFix>> markTracks = new LinkedHashMap<>();
for (Mark m : marks) { for (Mark m : marks) {
try { try {
getTrackedRace().getOrCreateTrack(m).lockForRead(); getTrackedRace().getOrCreateTrack(m).lockForRead();
for (GPSFix fix : getTrackedRace().getOrCreateTrack(m).getFixes()) { markTracks.put(m, getTrackedRace().getOrCreateTrack(m));
markPassCreator.markPositionChanged(fix, m);
}
} finally { } finally {
getTrackedRace().getOrCreateTrack(m).unlockAfterRead(); getTrackedRace().getOrCreateTrack(m).unlockAfterRead();
} }
nextMarkFix.put(m, markTracks.get(m).getFirstRawFix());
} }
LinkedHashMap<Competitor, GPSFixMoving> nextCompetitorFix = new LinkedHashMap<>();
// Pass in Competitor Fixes LinkedHashMap<Competitor, DynamicGPSFixTrack<Competitor, GPSFixMoving>> competitorTracks = new LinkedHashMap<>();
for (Competitor c : getRace().getCompetitors()) { for (Competitor c : getRace().getCompetitors()) {
try { try {
getTrackedRace().getTrack(c).lockForRead(); getTrackedRace().getTrack(c).lockForRead();
for (GPSFixMoving fix : getTrackedRace().getTrack(c).getFixes()) { competitorTracks.put(c, getTrackedRace().getTrack(c));
markPassCreator.competitorPositionChanged(fix, c);
}
} finally { } finally {
getTrackedRace().getTrack(c).unlockAfterRead(); getTrackedRace().getTrack(c).unlockAfterRead();
} }
nextCompetitorFix.put(c, competitorTracks.get(c).getFirstRawFix());
} }
for (Mark m : marks) {
GPSFix fix = nextMarkFix.get(m);
while (fix != null) {
markPassCreator.markPositionChanged(fix, m);
nextMarkFix.put(m, markTracks.get(m).getFirstFixAfter(fix.getTimePoint()));
fix = nextMarkFix.get(m);
}
}
boolean done = false;
while (!done) {
done = true;
for (Competitor c : getRace().getCompetitors()) {
GPSFixMoving fix = nextCompetitorFix.get(c);
if (fix != null) {
markPassCreator.competitorPositionChanged(fix, c);
fix = competitorTracks.get(c).getFirstFixAfter(fix.getTimePoint());
nextCompetitorFix.put(c, fix);
}
}
for (Competitor c : getRace().getCompetitors()) {
if (!(nextCompetitorFix.get(c) == null)) {
done = false;
break;
}
}
}
// Get results // Get results
System.out.println("Getting Results");
for (Competitor c : getRace().getCompetitors()) { for (Competitor c : getRace().getCompetitors()) {
LinkedHashMap<Waypoint, MarkPassing> passes = new LinkedHashMap<>(); LinkedHashMap<Waypoint, MarkPassing> passes = new LinkedHashMap<>();
for (Waypoint w : waypoints) { for (Waypoint w : waypoints) {
@@ -268,10 +281,10 @@ public class MarkPassingCalculatorTest extends OnlineTracTracBasedTest {
int correctlyNotComputed = 0; int correctlyNotComputed = 0;
int correctPasses = 0; int correctPasses = 0;
int incorrectPasses = 0; int incorrectPasses = 0;
boolean printRight = false; boolean printRight = false;
boolean printWrong = true; boolean printWrong = true;
for (Competitor c : getRace().getCompetitors()) { for (Competitor c : getRace().getCompetitors()) {
numberOfCompetitors++; numberOfCompetitors++;
System.out.println(c.getName() + "\n"); System.out.println(c.getName() + "\n");
@@ -281,27 +294,27 @@ public class MarkPassingCalculatorTest extends OnlineTracTracBasedTest {
if (printWrong) { if (printWrong) {
System.out.println(waypoints.indexOf(w)); System.out.println(waypoints.indexOf(w));
System.out.println("Given is null"); System.out.println("Given is null");
System.out.println(computedPasses.get(c).get(w)+ "\n"); System.out.println(computedPasses.get(c).get(w) + "\n");
} }
} else if (computedPasses.get(c).get(w) == null && !(givenPasses.get(c).get(w) == null)) { } else if (computedPasses.get(c).get(w) == null && !(givenPasses.get(c).get(w) == null)) {
wronglyNotComputed++; wronglyNotComputed++;
if (printWrong) { if (printWrong) {
System.out.println(waypoints.indexOf(w)); System.out.println(waypoints.indexOf(w));
System.out.println("Computed is null"); System.out.println("Computed is null");
System.out.println(givenPasses.get(c).get(w)+ "\n"); System.out.println(givenPasses.get(c).get(w) + "\n");
} }
} else if (givenPasses.get(c).get(w) == null && computedPasses.get(c).get(w) == null) { } else if (givenPasses.get(c).get(w) == null && computedPasses.get(c).get(w) == null) {
correctlyNotComputed++; correctlyNotComputed++;
if (printRight) { if (printRight) {
System.out.println(waypoints.indexOf(w)); System.out.println(waypoints.indexOf(w));
System.out.println("Both null"+ "\n"); System.out.println("Both null" + "\n");
} }
} else { } else {
long timedelta = givenPasses.get(c).get(w).getTimePoint().asMillis() long timedelta = givenPasses.get(c).get(w).getTimePoint().asMillis()
- computedPasses.get(c).get(w).getTimePoint().asMillis(); - computedPasses.get(c).get(w).getTimePoint().asMillis();
if ((Math.abs(timedelta) < tolerance)) { if ((Math.abs(timedelta) < tolerance)) {
correctPasses++; correctPasses++;
if(printRight){ if (printRight) {
System.out.println(waypoints.indexOf(w)); System.out.println(waypoints.indexOf(w));
System.out.println("Calculated: " + computedPasses.get(c).get(w)); System.out.println("Calculated: " + computedPasses.get(c).get(w));
System.out.println("Given: " + givenPasses.get(c).get(w)); System.out.println("Given: " + givenPasses.get(c).get(w));
@@ -320,18 +333,19 @@ public class MarkPassingCalculatorTest extends OnlineTracTracBasedTest {
} }
} }
int totalMarkPasses = numberOfCompetitors*waypoints.size(); int totalMarkPasses = numberOfCompetitors * waypoints.size();
assertEquals(totalMarkPasses, incorrectPasses+correctPasses+wronglyNotComputed+correctlyNotComputed+wronglyComputed); assertEquals(totalMarkPasses, incorrectPasses + correctPasses + wronglyNotComputed + correctlyNotComputed
+ wronglyComputed);
System.out.println("Total theoretical Passes: " + totalMarkPasses); System.out.println("Total theoretical Passes: " + totalMarkPasses);
double accuracy = (double) (correctPasses+correctlyNotComputed) / totalMarkPasses; double accuracy = (double) (correctPasses + correctlyNotComputed) / totalMarkPasses;
System.out.println("Correct comparison: " + correctPasses); System.out.println("Correct comparison: " + correctPasses);
System.out.println("Incorrect comparison: " + incorrectPasses); System.out.println("Incorrect comparison: " + incorrectPasses);
System.out.println("Correctly Null: " + correctlyNotComputed); System.out.println("Correctly Null: " + correctlyNotComputed);
System.out.println("Should be null but arent:" + wronglyComputed); System.out.println("Should be null but arent:" + wronglyComputed);
System.out.println("Should not be null but are: " + wronglyNotComputed); System.out.println("Should not be null but are: " + wronglyNotComputed);
System.out.println("accuracy: " + accuracy); System.out.println("accuracy: " + accuracy);
System.out.println("Computation time: " + (System.currentTimeMillis()-time)/1000 + " s"); System.out.println("Computation time: " + (System.currentTimeMillis() - time) / 1000 + " s");
assertTrue(accuracy > 0.8); assertTrue(accuracy > 0.8);
} }
} }