MATSIM
SteppableScheduler.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * SteppableScheduler.java
5  * *
6  * *********************************************************************** *
7  * *
8  * copyright : (C) 2019 by the members listed in the COPYING, *
9  * LICENSE and WARRANTY file. *
10  * email : info at matsim dot org *
11  * *
12  * *********************************************************************** *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * See also COPYING, LICENSE and WARRANTY file *
19  * *
20  * *********************************************************************** */
21 
22  package org.matsim.core.mobsim.messagequeue;
23 
25 
26 import jakarta.inject.Inject;
27 
28 public class SteppableScheduler extends Scheduler implements Steppable {
29 
30  private Message lookahead;
31  private boolean finished = false;
32 
33  @Inject
35  super(queue);
36  }
37 
38  @Override
39  public void doSimStep(double time) {
40  finished = false; // I don't think we can restart once the queue has run dry, but just in case.
41 
42  // "lookahead" is, I think, just a cache of the next message in the queue, to avoid having to retreive it again.
43  // yyyy looks like a potential bug to me if some other message gets inserted with an earlier message arrival time? kai, feb'19
44  // yes, I also think this works only if all messages are known in advance. marcel, march 2025
45  if (lookahead != null && time < lookahead.getMessageArrivalTime()) {
46  return;
47  }
48  if (lookahead != null) {
49  lookahead.handleMessage();
50  lookahead = null;
51  }
52  while (!queue.isEmpty()) {
54  if (m != null && m.getMessageArrivalTime() <= time) {
55  m.handleMessage();
56  } else {
57  lookahead = m;
58  return;
59  }
60  }
61  finished = true; // queue has run dry.
62  }
63 
64  public boolean isFinished() {
65  return finished;
66  }
67 
68 }