mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-25 13:33:59 +00:00
first attempt trying to simply avoid NPE; but a more solid fix is required as I'm not sure how to ideally recover from the situation here
This commit is contained in:
1 parent
8e39f5b58a
commit
e63237745e
1 file changed
+47
-29
+47
-29
@@ -82,7 +82,19 @@ public class CandidateChooserImpl implements CandidateChooser {
|
||||
TreeSet<Candidate> fixedPasses = new TreeSet<Candidate>(new Comparator<Candidate>() {
|
||||
@Override
|
||||
public int compare(Candidate o1, Candidate o2) {
|
||||
return o1.getOneBasedIndexOfWaypoint() - o2.getOneBasedIndexOfWaypoint();
|
||||
final int result;
|
||||
if (o1 == null) {
|
||||
if (o2 == null) {
|
||||
result = 0;
|
||||
} else {
|
||||
result = -1;
|
||||
}
|
||||
} else if (o2 == null) {
|
||||
result = 1;
|
||||
} else {
|
||||
result = o1.getOneBasedIndexOfWaypoint() - o2.getOneBasedIndexOfWaypoint();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
fixedPassings.put(c, fixedPasses);
|
||||
@@ -152,9 +164,11 @@ public class CandidateChooserImpl implements CandidateChooser {
|
||||
break;
|
||||
}
|
||||
}
|
||||
fixedPassings.get(c).remove(toRemove);
|
||||
removeCandidates(c, Arrays.asList(toRemove));
|
||||
findShortestPath(c);
|
||||
if (toRemove != null) {
|
||||
fixedPassings.get(c).remove(toRemove);
|
||||
removeCandidates(c, Arrays.asList(toRemove));
|
||||
findShortestPath(c);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -294,30 +308,34 @@ public class CandidateChooserImpl implements CandidateChooser {
|
||||
0, race.getRace().getCourse().getNumberOfWaypoints()), 0.0));
|
||||
while (!endFound) {
|
||||
Util.Pair<Edge, Double> cheapestEdgeWithCost = currentEdgesCheapestFirst.pollFirst();
|
||||
Edge currentCheapestEdge = cheapestEdgeWithCost.getA();
|
||||
Double currentCheapestCost = cheapestEdgeWithCost.getB();
|
||||
// If the shortest path to this candidate is already known the new edge is not added.
|
||||
if (!candidateWithParentAndSmallestTotalCost.containsKey(currentCheapestEdge.getEnd())) {
|
||||
// The cheapest edge taking us to currentCheapestEdge.getEnd() is found. Remember it.
|
||||
candidateWithParentAndSmallestTotalCost.put(currentCheapestEdge.getEnd(), new Util.Pair<Candidate, Double>(
|
||||
currentCheapestEdge.getStart(), currentCheapestCost));
|
||||
if (logger.isLoggable(Level.FINEST)) {
|
||||
logger.finest("Added "+ currentCheapestEdge + "as cheapest edge for " + c);
|
||||
}
|
||||
endFound = currentCheapestEdge.getEnd() == endOfFixedInterval;
|
||||
if (!endFound) {
|
||||
// the end of the segment was not yet found; add edges leading away from
|
||||
// currentCheapestEdge.getEnd(), summing up their cost with the cost required
|
||||
// to reach currentCheapestEdge.getEnd()
|
||||
Set<Edge> edgesForNewCandidate = allCompetitorEdges.get(currentCheapestEdge.getEnd());
|
||||
if (edgesForNewCandidate != null) {
|
||||
for (Edge e : edgesForNewCandidate) {
|
||||
int oneBasedIndexOfEndOfEdge = e.getEnd().getOneBasedIndexOfWaypoint();
|
||||
// only add edge if it stays within the current segment, not exceeding
|
||||
// the next fixed mark passing
|
||||
if (oneBasedIndexOfEndOfEdge <= indexOfEndOfFixedInterval
|
||||
&& (oneBasedIndexOfEndOfEdge < oneBasedIndexOfSuppressedWaypoint || e.getEnd() == end)) {
|
||||
currentEdgesCheapestFirst.add(new Util.Pair<Edge, Double>(e, currentCheapestCost + e.getCost()));
|
||||
if (cheapestEdgeWithCost == null) {
|
||||
endFound = true;
|
||||
} else {
|
||||
Edge currentCheapestEdge = cheapestEdgeWithCost.getA();
|
||||
Double currentCheapestCost = cheapestEdgeWithCost.getB();
|
||||
// If the shortest path to this candidate is already known the new edge is not added.
|
||||
if (!candidateWithParentAndSmallestTotalCost.containsKey(currentCheapestEdge.getEnd())) {
|
||||
// The cheapest edge taking us to currentCheapestEdge.getEnd() is found. Remember it.
|
||||
candidateWithParentAndSmallestTotalCost.put(currentCheapestEdge.getEnd(), new Util.Pair<Candidate, Double>(
|
||||
currentCheapestEdge.getStart(), currentCheapestCost));
|
||||
if (logger.isLoggable(Level.FINEST)) {
|
||||
logger.finest("Added "+ currentCheapestEdge + "as cheapest edge for " + c);
|
||||
}
|
||||
endFound = currentCheapestEdge.getEnd() == endOfFixedInterval;
|
||||
if (!endFound) {
|
||||
// the end of the segment was not yet found; add edges leading away from
|
||||
// currentCheapestEdge.getEnd(), summing up their cost with the cost required
|
||||
// to reach currentCheapestEdge.getEnd()
|
||||
Set<Edge> edgesForNewCandidate = allCompetitorEdges.get(currentCheapestEdge.getEnd());
|
||||
if (edgesForNewCandidate != null) {
|
||||
for (Edge e : edgesForNewCandidate) {
|
||||
int oneBasedIndexOfEndOfEdge = e.getEnd().getOneBasedIndexOfWaypoint();
|
||||
// only add edge if it stays within the current segment, not exceeding
|
||||
// the next fixed mark passing
|
||||
if (oneBasedIndexOfEndOfEdge <= indexOfEndOfFixedInterval
|
||||
&& (oneBasedIndexOfEndOfEdge < oneBasedIndexOfSuppressedWaypoint || e.getEnd() == end)) {
|
||||
currentEdgesCheapestFirst.add(new Util.Pair<Edge, Double>(e, currentCheapestCost + e.getCost()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -448,7 +466,7 @@ public class CandidateChooserImpl implements CandidateChooser {
|
||||
|
||||
private void removeCandidates(Competitor c, Iterable<Candidate> wrongCandidates) {
|
||||
for (Candidate can : wrongCandidates) {
|
||||
logger.finest("Removing all edges containing " + can.toString() + "of "+ c);
|
||||
logger.finest("Removing all edges containing " + can + "of "+ c);
|
||||
candidates.get(c).remove(can);
|
||||
Map<Candidate, Set<Edge>> edges = allEdges.get(c);
|
||||
edges.remove(can);
|
||||
|
||||
Reference in new issue
Block a user