mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-14 16:20:57 +00:00
Fixed Waypoint addition outside of Finder and reworked
ChooserPerformanceTest.
This commit is contained in:
1 parent
3906a4180a
commit
52d0d987aa
9 files changed
+131
-121
No files matched your search
+20
-28
@@ -71,47 +71,39 @@ public class MarkPassingCalculatorPerformanceTest extends AbstractMockedRaceMark
|
||||
|
||||
@Test
|
||||
public void testChooser() {
|
||||
long time = timeToAddCandidatesToChooser(500, 1);
|
||||
long time = timeToAddCandidatesToChooser(500, 1, 25);
|
||||
System.out.println(time);
|
||||
result.put("ChooserPerformance", time);
|
||||
assertTrue(time < 800);
|
||||
}
|
||||
|
||||
private long timeToAddCandidatesToChooser(int numberOfCandidates, int numberToAdd) {
|
||||
List<Candidate> newCans = new ArrayList<>();
|
||||
for (int i = 0; i < numberOfCandidates; i++) {
|
||||
newCans.add(randomCan());
|
||||
}
|
||||
time = System.currentTimeMillis();
|
||||
CandidateChooserImpl c = new CandidateChooserImpl(race);
|
||||
c.calculateMarkPassDeltas(ron, newCans, new ArrayList<Candidate>());
|
||||
time = System.currentTimeMillis() - time;
|
||||
List<Long> times = new ArrayList<>();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
List<Candidate> old = new ArrayList<>();
|
||||
List<Candidate> ne = new ArrayList<>();
|
||||
for (int j = 0; j < numberToAdd; j++) {
|
||||
ne.add(randomCan());
|
||||
private long timeToAddCandidatesToChooser(int numberOfTimesAdding, int numberToAddEachTime, int numberOfRepititions) {
|
||||
long totalTime = 0;
|
||||
for (int i = 0; i < numberOfRepititions; i++) {
|
||||
CandidateChooserImpl c = new CandidateChooserImpl(race);
|
||||
for (int j = 0; j < numberOfTimesAdding; j++) {
|
||||
List<Candidate> newCandidates = new ArrayList<>();
|
||||
for (int k = 0; k < numberToAddEachTime; k++) {
|
||||
newCandidates.add(randomCan());
|
||||
}
|
||||
|
||||
time = System.currentTimeMillis();
|
||||
c.calculateMarkPassDeltas(ron, newCandidates, new ArrayList<Candidate>());
|
||||
totalTime += System.currentTimeMillis() - time;
|
||||
}
|
||||
time = System.currentTimeMillis();
|
||||
c.calculateMarkPassDeltas(ron, ne, old);
|
||||
times.add(System.currentTimeMillis() - time);
|
||||
old = ne;
|
||||
}
|
||||
long total = 0;
|
||||
for (long l : times) {
|
||||
total = total + l;
|
||||
}
|
||||
return total / times.size();
|
||||
return totalTime / numberOfRepititions;
|
||||
}
|
||||
|
||||
private CandidateImpl randomCan() {
|
||||
int id = rnd.nextInt(3);
|
||||
return new CandidateImpl(id + 1, new MillisecondsTimePoint((long) (rnd.nextDouble() * 200000)), 0.5 + 0.5 * rnd.nextDouble(), Util.get(race.getRace().getCourse()
|
||||
.getWaypoints(), id));
|
||||
return new CandidateImpl(id + 1, new MillisecondsTimePoint((long) (rnd.nextDouble() * 200000)),
|
||||
0.5 + 0.5 * rnd.nextDouble(), Util.get(race.getRace().getCourse().getWaypoints(), id));
|
||||
}
|
||||
|
||||
private GPSFixMoving rndFix() {
|
||||
DegreePosition position = new DegreePosition(0.001 - rnd.nextDouble() * 0.001, 0.0002 - rnd.nextDouble() * 0.0004);
|
||||
DegreePosition position = new DegreePosition(0.001 - rnd.nextDouble() * 0.001,
|
||||
0.0002 - rnd.nextDouble() * 0.0004);
|
||||
TimePoint p = new MillisecondsTimePoint((long) (rnd.nextDouble() * 200000));
|
||||
SpeedWithBearing speed = new KnotSpeedWithBearingImpl(rnd.nextInt(11), new DegreeBearingImpl(rnd.nextInt(360)));
|
||||
return new GPSFixMovingImpl(position, p, speed);
|
||||
|
||||
+3
-3
@@ -255,7 +255,7 @@ public class MarkPassingWhiteBoxTest extends AbstractMockedRaceMarkPassingTest {
|
||||
|
||||
race.recordFix(ron, fix1);
|
||||
race.recordFix(ron, fix2);
|
||||
|
||||
|
||||
CandidateFinder finder = new CandidateFinderImpl(race);
|
||||
Waypoint newWaypoint = new WaypointImpl(reaching, PassingInstruction.Port);
|
||||
Course course = race.getRace().getCourse();
|
||||
@@ -267,7 +267,7 @@ public class MarkPassingWhiteBoxTest extends AbstractMockedRaceMarkPassingTest {
|
||||
|
||||
// The process of adding
|
||||
course.addWaypoint(4, newWaypoint);
|
||||
Pair<Iterable<Candidate>, Iterable<Candidate>> addedCans = finder.addWaypoint(newWaypoint, 4).get(ron);
|
||||
Pair<List<Candidate>, List<Candidate>> addedCans = finder.updateWaypoints(Arrays.asList(newWaypoint), new ArrayList<Waypoint>(), 4).get(ron);
|
||||
assertEquals(Util.size(addedCans.getA()), 1);
|
||||
for (Candidate c : addedCans.getA()) {
|
||||
assertEquals(c.getWaypoint(), newWaypoint);
|
||||
@@ -280,7 +280,7 @@ public class MarkPassingWhiteBoxTest extends AbstractMockedRaceMarkPassingTest {
|
||||
|
||||
// The Process of removing
|
||||
course.removeWaypoint(4);
|
||||
Pair<Iterable<Candidate>, Iterable<Candidate>> removedCans = finder.removeWaypoint(newWaypoint, 4).get(ron);
|
||||
Pair<List<Candidate>, List<Candidate>> removedCans = finder.updateWaypoints(new ArrayList<Waypoint>(), Arrays.asList(newWaypoint), 4).get(ron);
|
||||
assertEquals(Util.size(removedCans.getB()), 1);
|
||||
for (Candidate c : removedCans.getB()) {
|
||||
assertEquals(c.getWaypoint(), newWaypoint);
|
||||
|
||||
+4
@@ -24,4 +24,8 @@ public interface CandidateChooser {
|
||||
|
||||
void removeFixedPassing(Competitor c, Waypoint w);
|
||||
|
||||
void suppressMarkPassings(Competitor c, Waypoint firstSuppressedWaypoint);
|
||||
|
||||
void stopSuppressingMarkPassings(Competitor c);
|
||||
|
||||
}
|
||||
+2
-3
@@ -34,8 +34,7 @@ public interface CandidateFinder {
|
||||
* {@link Candidate}s are needed instead of just the deltas.
|
||||
*/
|
||||
Pair<Iterable<Candidate>, Iterable<Candidate>> getAllCandidates(Competitor c);
|
||||
|
||||
Map<Competitor, Pair<List<Candidate>, List<Candidate>>> updateWaypoints(Iterable<Waypoint> addedWaypoints, Iterable<Waypoint> removedWaypoints, Integer smallestIndex);
|
||||
|
||||
Map<Competitor, Pair<Iterable<Candidate>, Iterable<Candidate>>> addWaypoint(Waypoint w, int index);
|
||||
|
||||
Map<Competitor, Pair<Iterable<Candidate>, Iterable<Candidate>>> removeWaypoint(Waypoint w, int index);
|
||||
}
|
||||
+20
-14
@@ -90,8 +90,9 @@ public class MarkPassingCalculator {
|
||||
boolean finished = false;
|
||||
Map<Competitor, List<GPSFix>> competitorFixes = new HashMap<>();
|
||||
Map<Mark, List<GPSFix>> markFixes = new HashMap<>();
|
||||
Map<Waypoint, Integer> addedWaypoints = new HashMap<>();
|
||||
Map<Waypoint, Integer> removedWaypoints = new HashMap<>();
|
||||
List<Waypoint> addedWaypoints = new ArrayList<>();
|
||||
List<Waypoint> removedWaypoints = new ArrayList<>();
|
||||
Integer smallestChangedWaypointIndex = null;
|
||||
List<MarkPassing> fixedMarkPassings = new ArrayList<>();
|
||||
List<MarkPassing> removedMarkPassings = new ArrayList<>();
|
||||
while (!finished) {
|
||||
@@ -108,17 +109,21 @@ public class MarkPassingCalculator {
|
||||
finished = true;
|
||||
} else {
|
||||
fixInsertion.storePositionUpdate(competitorFixes, markFixes, addedWaypoints, removedWaypoints,
|
||||
fixedMarkPassings, removedMarkPassings);
|
||||
smallestChangedWaypointIndex, fixedMarkPassings, removedMarkPassings);
|
||||
}
|
||||
}
|
||||
if (!suspended) {
|
||||
for (Entry<Waypoint, Integer> way : removedWaypoints.entrySet()) {
|
||||
finder.removeWaypoint(way.getKey(), way.getValue());
|
||||
// TODO Interplay between changing waypoints and setting fixed passes?
|
||||
if (smallestChangedWaypointIndex != null) {
|
||||
Map<Competitor, Pair<List<Candidate>, List<Candidate>>> candidateDeltas = finder
|
||||
.updateWaypoints(addedWaypoints, removedWaypoints, smallestChangedWaypointIndex);
|
||||
chooser.removeWaypoints(removedWaypoints);
|
||||
for (Entry<Competitor, Pair<List<Candidate>, List<Candidate>>> entry : candidateDeltas
|
||||
.entrySet()) {
|
||||
Pair<List<Candidate>, List<Candidate>> pair = entry.getValue();
|
||||
chooser.calculateMarkPassDeltas(entry.getKey(), pair.getA(), pair.getB());
|
||||
}
|
||||
}
|
||||
for (Entry<Waypoint, Integer> way : addedWaypoints.entrySet()) {
|
||||
finder.addWaypoint(way.getKey(), way.getValue());
|
||||
}
|
||||
|
||||
updateFixedMarkPassings(fixedMarkPassings, removedMarkPassings);
|
||||
computeMarkPasses(competitorFixes, markFixes);
|
||||
competitorFixes.clear();
|
||||
@@ -241,8 +246,8 @@ public class MarkPassingCalculator {
|
||||
listener.getQueue().add(new StorePositionUpdateStrategy() {
|
||||
@Override
|
||||
public void storePositionUpdate(Map<Competitor, List<GPSFix>> competitorFixes,
|
||||
Map<Mark, List<GPSFix>> markFixes, Map<Waypoint, Integer> addedWaypoints,
|
||||
Map<Waypoint, Integer> removedWaypoints, List<MarkPassing> fixMarkPassing,
|
||||
Map<Mark, List<GPSFix>> markFixes, List<Waypoint> addedWaypoints, List<Waypoint> removedWaypoints,
|
||||
Integer smallestChangedWaypointIndex, List<MarkPassing> fixMarkPassing,
|
||||
List<MarkPassing> removeFixedMarkPassing) {
|
||||
}
|
||||
});
|
||||
@@ -260,11 +265,12 @@ public class MarkPassingCalculator {
|
||||
chooser.calculateMarkPassDeltas(c, allCandidates.getA(), allCandidates.getB());
|
||||
}
|
||||
}
|
||||
|
||||
public void addFixedPassing(MarkPassing m){
|
||||
|
||||
public void addFixedPassing(MarkPassing m) {
|
||||
listener.addFixedPassing(m);
|
||||
}
|
||||
public void removeFixedPassing(MarkPassing m){
|
||||
|
||||
public void removeFixedPassing(MarkPassing m) {
|
||||
listener.removeFixedPassing(m);
|
||||
}
|
||||
}
|
||||
+22
-16
@@ -29,8 +29,8 @@ public class MarkPassingUpdateListener extends AbstractRaceChangeListener implem
|
||||
private final StorePositionUpdateStrategy endMarker = new StorePositionUpdateStrategy() {
|
||||
@Override
|
||||
public void storePositionUpdate(Map<Competitor, List<GPSFix>> competitorFixes,
|
||||
Map<Mark, List<GPSFix>> markFixes, Map<Waypoint, Integer> addedWaypoints,
|
||||
Map<Waypoint, Integer> removedWaypoints, List<MarkPassing> fixMarkPassing,
|
||||
Map<Mark, List<GPSFix>> markFixes, List<Waypoint> addedWaypoints, List<Waypoint> removedWaypoints,
|
||||
Integer smallestChangedWaypointIndex, List<MarkPassing> fixMarkPassing,
|
||||
List<MarkPassing> removeFixedMarkPassing) {
|
||||
}
|
||||
};
|
||||
@@ -53,8 +53,8 @@ public class MarkPassingUpdateListener extends AbstractRaceChangeListener implem
|
||||
queue.add(new StorePositionUpdateStrategy() {
|
||||
@Override
|
||||
public void storePositionUpdate(Map<Competitor, List<GPSFix>> competitorFixes,
|
||||
Map<Mark, List<GPSFix>> markFixes, Map<Waypoint, Integer> addedWaypoints,
|
||||
Map<Waypoint, Integer> removedWaypoints, List<MarkPassing> fixMarkPassing,
|
||||
Map<Mark, List<GPSFix>> markFixes, List<Waypoint> addedWaypoints, List<Waypoint> removedWaypoints,
|
||||
Integer smallestChangedWaypointIndex, List<MarkPassing> fixMarkPassing,
|
||||
List<MarkPassing> removeFixedMarkPassing) {
|
||||
List<GPSFix> list = competitorFixes.get(competitor);
|
||||
if (list == null) {
|
||||
@@ -71,8 +71,8 @@ public class MarkPassingUpdateListener extends AbstractRaceChangeListener implem
|
||||
queue.add(new StorePositionUpdateStrategy() {
|
||||
@Override
|
||||
public void storePositionUpdate(Map<Competitor, List<GPSFix>> competitorFixes,
|
||||
Map<Mark, List<GPSFix>> markFixes, Map<Waypoint, Integer> addedWaypoints,
|
||||
Map<Waypoint, Integer> removedWaypoints, List<MarkPassing> fixMarkPassing,
|
||||
Map<Mark, List<GPSFix>> markFixes, List<Waypoint> addedWaypoints, List<Waypoint> removedWaypoints,
|
||||
Integer smallestChangedWaypointIndex, List<MarkPassing> fixMarkPassing,
|
||||
List<MarkPassing> removeFixedMarkPassing) {
|
||||
List<GPSFix> list = markFixes.get(mark);
|
||||
if (list == null) {
|
||||
@@ -97,10 +97,13 @@ public class MarkPassingUpdateListener extends AbstractRaceChangeListener implem
|
||||
queue.add(new StorePositionUpdateStrategy() {
|
||||
@Override
|
||||
public void storePositionUpdate(Map<Competitor, List<GPSFix>> competitorFixes,
|
||||
Map<Mark, List<GPSFix>> markFixes, Map<Waypoint, Integer> addedWaypoints,
|
||||
Map<Waypoint, Integer> removedWaypoints, List<MarkPassing> fixMarkPassing,
|
||||
Map<Mark, List<GPSFix>> markFixes, List<Waypoint> addedWaypoints, List<Waypoint> removedWaypoints,
|
||||
Integer smallestChangedWaypointIndex, List<MarkPassing> fixMarkPassing,
|
||||
List<MarkPassing> removeFixedMarkPassing) {
|
||||
addedWaypoints.put(waypointThatGotAdded, zeroBasedIndex);
|
||||
addedWaypoints.add(waypointThatGotAdded);
|
||||
if (smallestChangedWaypointIndex == null || smallestChangedWaypointIndex > zeroBasedIndex) {
|
||||
smallestChangedWaypointIndex = zeroBasedIndex;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -110,10 +113,13 @@ public class MarkPassingUpdateListener extends AbstractRaceChangeListener implem
|
||||
queue.add(new StorePositionUpdateStrategy() {
|
||||
@Override
|
||||
public void storePositionUpdate(Map<Competitor, List<GPSFix>> competitorFixes,
|
||||
Map<Mark, List<GPSFix>> markFixes, Map<Waypoint, Integer> addedWaypoints,
|
||||
Map<Waypoint, Integer> removedWaypoints, List<MarkPassing> fixMarkPassing,
|
||||
Map<Mark, List<GPSFix>> markFixes, List<Waypoint> addedWaypoints, List<Waypoint> removedWaypoints,
|
||||
Integer smallestChangedWaypointIndex, List<MarkPassing> fixMarkPassing,
|
||||
List<MarkPassing> removeFixedMarkPassing) {
|
||||
removedWaypoints.put(waypointThatGotRemoved, zeroBasedIndex);
|
||||
removedWaypoints.add(waypointThatGotRemoved);
|
||||
if (smallestChangedWaypointIndex == null || smallestChangedWaypointIndex > zeroBasedIndex) {
|
||||
smallestChangedWaypointIndex = zeroBasedIndex;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -122,8 +128,8 @@ public class MarkPassingUpdateListener extends AbstractRaceChangeListener implem
|
||||
queue.add(new StorePositionUpdateStrategy() {
|
||||
@Override
|
||||
public void storePositionUpdate(Map<Competitor, List<GPSFix>> competitorFixes,
|
||||
Map<Mark, List<GPSFix>> markFixes, Map<Waypoint, Integer> addedWaypoints,
|
||||
Map<Waypoint, Integer> removedWaypoints, List<MarkPassing> fixedMarkPassing,
|
||||
Map<Mark, List<GPSFix>> markFixes, List<Waypoint> addedWaypoints, List<Waypoint> removedWaypoints,
|
||||
Integer smallestChangedWaypointIndex, List<MarkPassing> fixedMarkPassing,
|
||||
List<MarkPassing> removeFixedMarkPassing) {
|
||||
fixedMarkPassing.add(m);
|
||||
}
|
||||
@@ -134,8 +140,8 @@ public class MarkPassingUpdateListener extends AbstractRaceChangeListener implem
|
||||
queue.add(new StorePositionUpdateStrategy() {
|
||||
@Override
|
||||
public void storePositionUpdate(Map<Competitor, List<GPSFix>> competitorFixes,
|
||||
Map<Mark, List<GPSFix>> markFixes, Map<Waypoint, Integer> addedWaypoints,
|
||||
Map<Waypoint, Integer> removedWaypoints, List<MarkPassing> fixedMarkPassing,
|
||||
Map<Mark, List<GPSFix>> markFixes, List<Waypoint> addedWaypoints, List<Waypoint> removedWaypoints,
|
||||
Integer smallestChangedWaypointIndex, List<MarkPassing> fixedMarkPassing,
|
||||
List<MarkPassing> removeFixedMarkPassing) {
|
||||
removeFixedMarkPassing.add(m);
|
||||
|
||||
|
||||
+4
-2
@@ -18,6 +18,8 @@ public interface StorePositionUpdateStrategy {
|
||||
* Adds its fix either to <code>competitorFixes</code> or <code>markFixes</code>, depending what the fix is for. If
|
||||
* no fixes exist yet for that object, a new entry is created.
|
||||
*/
|
||||
void storePositionUpdate(Map<Competitor, List<GPSFix>> competitorFixes, Map<Mark, List<GPSFix>> markFixes, Map<Waypoint, Integer> addedWaypoints, Map<Waypoint, Integer> removedWaypoints,
|
||||
List<MarkPassing> fixMarkPassing, List<MarkPassing> removeFixedMarkPassing);
|
||||
void storePositionUpdate(Map<Competitor, List<GPSFix>> competitorFixes, Map<Mark, List<GPSFix>> markFixes,
|
||||
List<Waypoint> addedWaypoints, List<Waypoint> removedWaypoints,
|
||||
Integer smallestChangedWaypointIndex, List<MarkPassing> fixMarkPassing,
|
||||
List<MarkPassing> removeFixedMarkPassing);
|
||||
}
|
||||
+17
-4
@@ -51,6 +51,7 @@ public class CandidateChooserImpl implements CandidateChooser {
|
||||
private Map<Competitor, Map<Candidate, Set<Edge>>> allEdges = new HashMap<>();
|
||||
private Map<Competitor, Set<Candidate>> candidates = new HashMap<>();
|
||||
private Map<Competitor, NavigableSet<Candidate>> fixedPassings = new HashMap<>();
|
||||
private Map<Competitor, Waypoint> suppressedPassings = new HashMap<>();
|
||||
private TimePoint raceStartTime;
|
||||
private final CandidateWithSettableTime start;
|
||||
private final Candidate end;
|
||||
@@ -107,8 +108,6 @@ public class CandidateChooserImpl implements CandidateChooser {
|
||||
|
||||
@Override
|
||||
public void removeWaypoints(Iterable<Waypoint> ways) {
|
||||
// TODO Decrease Index of all Candidates + Increase for added!!
|
||||
// TODO Recalculate Edges (LegEstimation!!)
|
||||
for (Competitor c : currentMarkPasses.keySet()) {
|
||||
for (Waypoint w : ways) {
|
||||
currentMarkPasses.get(c).remove(w);
|
||||
@@ -250,13 +249,15 @@ public class CandidateChooserImpl implements CandidateChooser {
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
currentPasses.clear();
|
||||
List<MarkPassing> newMarkPassings = new ArrayList<>();
|
||||
for (Candidate can : mostLikelyCandidates) {
|
||||
if (can != start && can != end) {
|
||||
newMarkPassings.add(new MarkPassingImpl(can.getTimePoint(), can.getWaypoint(), c));
|
||||
MarkPassingImpl newMarkPassing = new MarkPassingImpl(can.getTimePoint(), can.getWaypoint(), c);
|
||||
currentPasses.put(newMarkPassing.getWaypoint(), newMarkPassing);
|
||||
newMarkPassings.add(newMarkPassing);
|
||||
}
|
||||
}
|
||||
|
||||
logger.fine("Updating MarkPasses for " + c);
|
||||
race.updateMarkPassings(c, newMarkPassings);
|
||||
}
|
||||
@@ -352,4 +353,16 @@ public class CandidateChooserImpl implements CandidateChooser {
|
||||
p = t;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suppressMarkPassings(Competitor c, Waypoint firstSuppressedWaypoint) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopSuppressingMarkPassings(Competitor c) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
+39
-51
@@ -169,11 +169,10 @@ public class CandidateFinderImpl implements CandidateFinder {
|
||||
return new Pair<Iterable<Candidate>, Iterable<Candidate>>(newCans, wrongCans);
|
||||
}
|
||||
|
||||
private Map<Competitor, Pair<Iterable<Candidate>, Iterable<Candidate>>> invalidateAfterCourseChange(
|
||||
int indexOfChange) {
|
||||
Map<Competitor, Pair<Iterable<Candidate>, Iterable<Candidate>>> result = new HashMap<>();
|
||||
private Map<Competitor, Pair<List<Candidate>, List<Candidate>>> invalidateAfterCourseChange(int indexOfChange) {
|
||||
Map<Competitor, Pair<List<Candidate>, List<Candidate>>> result = new HashMap<>();
|
||||
Course course = race.getRace().getCourse();
|
||||
for(Competitor c : race.getRace().getCompetitors()){
|
||||
for (Competitor c : race.getRace().getCompetitors()) {
|
||||
distanceCache.get(c).clear();
|
||||
xteCache.get(c).clear();
|
||||
}
|
||||
@@ -189,7 +188,8 @@ public class CandidateFinderImpl implements CandidateFinder {
|
||||
for (Waypoint w : changedWaypoints) {
|
||||
Map<List<GPSFix>, Candidate> xteCans = xteCandidates.get(c).get(w);
|
||||
badCans.addAll(xteCans.values());
|
||||
xteCans.clear();;
|
||||
xteCans.clear();
|
||||
;
|
||||
Map<GPSFix, Candidate> distanceCans = distanceCandidates.get(c).get(w);
|
||||
badCans.addAll(distanceCans.values());
|
||||
distanceCans.clear();
|
||||
@@ -197,59 +197,48 @@ public class CandidateFinderImpl implements CandidateFinder {
|
||||
Set<GPSFix> allFixes = getAllFixes(c);
|
||||
newCans.addAll(checkForDistanceCandidateChanges(c, allFixes, changedWaypoints).getA());
|
||||
newCans.addAll(checkForXTECandidatesChanges(c, allFixes, changedWaypoints).getA());
|
||||
result.put(c, new Pair<Iterable<Candidate>, Iterable<Candidate>>(newCans, badCans));
|
||||
result.put(c, new Pair<List<Candidate>, List<Candidate>>(newCans, badCans));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Competitor, Pair<Iterable<Candidate>, Iterable<Candidate>>> addWaypoint(Waypoint w, int index) {
|
||||
public Map<Competitor, Pair<List<Candidate>, List<Candidate>>> updateWaypoints(Iterable<Waypoint> addedWaypoints,
|
||||
Iterable<Waypoint> removedWaypoints, Integer smallestIndex) {
|
||||
Course course = race.getRace().getCourse();
|
||||
processNewWaypoint(w, course.getFirstWaypoint(), course.getLastWaypoint());
|
||||
return invalidateAfterCourseChange(index);
|
||||
for (Waypoint w : addedWaypoints) {
|
||||
processNewWaypoint(w, course.getFirstWaypoint(), course.getLastWaypoint());
|
||||
}
|
||||
Map<Competitor, List<Candidate>> removedWaypointCandidates = removeWaypoints(removedWaypoints);
|
||||
Map<Competitor, Pair<List<Candidate>, List<Candidate>>> newAndUpdatedCandidates = invalidateAfterCourseChange(smallestIndex);
|
||||
for (Entry<Competitor, List<Candidate>> entry : removedWaypointCandidates.entrySet()) {
|
||||
newAndUpdatedCandidates.get(entry.getKey()).getB().addAll(entry.getValue());
|
||||
}
|
||||
return newAndUpdatedCandidates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Competitor, Pair<Iterable<Candidate>, Iterable<Candidate>>> removeWaypoint(Waypoint w, int index) {
|
||||
private Map<Competitor, List<Candidate>> removeWaypoints(Iterable<Waypoint> waypoints) {
|
||||
// TODO Clear caches?
|
||||
passingInstructions.remove(w);
|
||||
Map<Competitor, Pair<Iterable<Candidate>, Iterable<Candidate>>> result = new HashMap<>();
|
||||
Map<Competitor, List<Candidate>> candidatesOfRemovedWaypoint = new HashMap<>();
|
||||
Iterable<Competitor> competitors = race.getRace().getCompetitors();
|
||||
for (Competitor c : competitors) {
|
||||
List<Candidate> badCans = new ArrayList<>();
|
||||
Map<Waypoint, Map<List<GPSFix>, Candidate>> xteCans = xteCandidates.get(c);
|
||||
badCans.addAll(xteCans.get(w).values());
|
||||
xteCans.remove(w);
|
||||
Map<Waypoint, Map<GPSFix, Candidate>> distanceCans = distanceCandidates.get(c);
|
||||
badCans.addAll(distanceCans.get(w).values());
|
||||
distanceCans.remove(w);
|
||||
candidatesOfRemovedWaypoint.put(c, badCans);
|
||||
Map<Competitor, List<Candidate>> result = new HashMap<>();
|
||||
for (Competitor c : race.getRace().getCompetitors()) {
|
||||
result.put(c, new ArrayList<Candidate>());
|
||||
}
|
||||
Map<Competitor, Pair<Iterable<Candidate>, Iterable<Candidate>>> changes = invalidateAfterCourseChange(index);
|
||||
|
||||
for (Competitor c : competitors) {
|
||||
Iterable<Candidate> added = changes.get(c).getA();
|
||||
List<Candidate> removed = new ArrayList<>();
|
||||
Util.addAll(changes.get(c).getB(), removed);
|
||||
removed.addAll(candidatesOfRemovedWaypoint.get(c));
|
||||
result.put(c, new Pair<Iterable<Candidate>, Iterable<Candidate>>(added, removed));
|
||||
for (Waypoint w : waypoints) {
|
||||
passingInstructions.remove(w);
|
||||
for (Entry<Competitor, List<Candidate>> entry : result.entrySet()) {
|
||||
Competitor c = entry.getKey();
|
||||
List<Candidate> badCans = entry.getValue();
|
||||
Map<Waypoint, Map<List<GPSFix>, Candidate>> xteCans = xteCandidates.get(c);
|
||||
badCans.addAll(xteCans.get(w).values());
|
||||
xteCans.remove(w);
|
||||
Map<Waypoint, Map<GPSFix, Candidate>> distanceCans = distanceCandidates.get(c);
|
||||
badCans.addAll(distanceCans.get(w).values());
|
||||
distanceCans.remove(w);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* private List<Mark> getUniqueMarksOfWaypoints(Collection<Waypoint> waypoints) { List<Mark> allMarks = new
|
||||
* ArrayList<>(); List<Mark> uniqueMarks = new ArrayList<>(); for (Waypoint w : waypoints) { if
|
||||
* (passingInstructions.get(w) == PassingInstruction.Line) { allMarks.add(lineMarks.get(w)); } else {
|
||||
* Util.addAll(w.getMarks(), allMarks); } } List<Waypoint> otherWaypoints = new ArrayList<>(); for (Waypoint w :
|
||||
* race.getRace().getCourse().getWaypoints()) { if (!waypoints.contains(w)) { otherWaypoints.add(w); } }
|
||||
* Iterator<Mark> it = allMarks.iterator(); while (it.hasNext()) { Mark m = it.next(); boolean unique = true; for
|
||||
* (Waypoint way : otherWaypoints) { if (Util.contains(way.getMarks(), m)) { unique = false; break; } } if (unique)
|
||||
* { uniqueMarks.add(m); } } return uniqueMarks; }
|
||||
*/
|
||||
|
||||
private void processNewWaypoint(Waypoint w, Waypoint firstWaypoint, Waypoint lastWaypoint) {
|
||||
PassingInstruction instruction = w.getPassingInstructions();
|
||||
if (instruction == PassingInstruction.None || instruction == null) {
|
||||
@@ -604,8 +593,8 @@ public class CandidateFinderImpl implements CandidateFinder {
|
||||
|
||||
/**
|
||||
* Determines whether a candidate is on the correct side of a waypoint. This is defined by the crossing information.
|
||||
* The cross-track error of <code>p</code> to the crossing Position and the crossing Bearing rotated by 90� need to
|
||||
* be negative. If the passing Instructions are line, it checks whether the boat passed between the two marks.
|
||||
* The cross-track error of <code>p</code> to the crossing Position and the crossing Bearing rotated by 90� need
|
||||
* to be negative. If the passing Instructions are line, it checks whether the boat passed between the two marks.
|
||||
*/
|
||||
private boolean isOnCorrectSideOfWaypoint(Waypoint w, Position p, TimePoint t, boolean portMark) {
|
||||
boolean result = true;
|
||||
@@ -716,10 +705,10 @@ public class CandidateFinderImpl implements CandidateFinder {
|
||||
break;
|
||||
case Gate:
|
||||
Pair<Mark, Mark> posGate = getPortAndStarboardMarks(t, w);
|
||||
Position portGatePosition = posGate.getA() == null ? null :
|
||||
race.getOrCreateTrack(posGate.getA()).getEstimatedPosition(t, false);
|
||||
Position starboardGatePosition = posGate.getB() == null ? null :
|
||||
race.getOrCreateTrack(posGate.getB()).getEstimatedPosition(t, false);
|
||||
Position portGatePosition = posGate.getA() == null ? null : race.getOrCreateTrack(posGate.getA())
|
||||
.getEstimatedPosition(t, false);
|
||||
Position starboardGatePosition = posGate.getB() == null ? null : race.getOrCreateTrack(posGate.getB())
|
||||
.getEstimatedPosition(t, false);
|
||||
distances.add(portGatePosition != null ? p.getDistance(portGatePosition) : null);
|
||||
distances.add(starboardGatePosition != null ? p.getDistance(starboardGatePosition) : null);
|
||||
|
||||
@@ -740,7 +729,6 @@ public class CandidateFinderImpl implements CandidateFinder {
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
if (singleMark) {
|
||||
Position markPosition = race.getOrCreateTrack(w.getMarks().iterator().next())
|
||||
|
||||
Reference in new issue
Block a user