Skip to content

Commit

Permalink
NextEventQueue: do not crash if no events are defined
Browse files Browse the repository at this point in the history
This is most likely an operator error, but we should handle it gracefully.

12:18:56.255 E n.n.BaseCalc - neurord.numeric.grid.AdaptiveGridCalc@6c9f5c0d: failed (seed=123)
12:18:56.255 E n.SDCalc - Trial 0 failed!
 java.lang.ArrayIndexOutOfBoundsException: 0
        at neurord.numeric.grid.NextEventQueue$PriorityTree.first(NextEventQueue.java:142) ~[classes/:?]
        at neurord.numeric.grid.NextEventQueue.advance(NextEventQueue.java:1999) ~[classes/:?]
        at neurord.numeric.grid.AdaptiveGridCalc.advance(AdaptiveGridCalc.java:108) ~[classes/:?]
        at neurord.numeric.grid.GridCalc._run(GridCalc.java:151) ~[classes/:?]
        at neurord.numeric.BaseCalc.run(BaseCalc.java:121) ~[classes/:?]
        at neurord.SDCalc.run(SDCalc.java:87) [classes/:?]
        at neurord.StochDiff.main(StochDiff.java:184) [classes/:?]

↓

12:26:26.944 W n.n.g.NextEventQueue - Event queue is empty — no diffusion, reaction, or stimulation events
  • Loading branch information
keszybz committed Dec 16, 2016
1 parent afccf82 commit ce6327d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/neurord/numeric/grid/NextEventQueue.java
Expand Up @@ -139,7 +139,11 @@ public int compare(T a, T b) {
}

T first() {
return this.nodes[0];
if (this.nodes.length == 0)
return null;
T node = this.nodes[0];
assert node != null;
return node;
}

void reposition(String prefix, T node) {
Expand Down Expand Up @@ -1993,12 +1997,20 @@ public static NextEventQueue create(int[][] particles,
*
* @returns Time of soonest event.
*/
private static boolean _warned_empty = false;
public double advance(double time, double tstop, double timelimit,
int[][] eventStatistics,
List<IGridCalc.Happening> events) {
NextEvent ev = this.queue.first();
assert ev != null;
double now = ev.time;
final NextEvent ev = this.queue.first();
final double now;
if (ev == null) {
if (!_warned_empty) {
log.warn("Event queue is empty — no diffusion, reaction, or stimulation events");
_warned_empty = true;
}
now = Double.POSITIVE_INFINITY;
} else
now = ev.time;
assert now >= time: ev;

if (now > tstop) {
Expand Down

0 comments on commit ce6327d

Please sign in to comment.