MATSIM
core
mobsim
messagequeue
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
24
import
org
.
matsim
.
core
.
mobsim
.
framework
.
Steppable
;
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
34
public
SteppableScheduler
(
MessageQueue
queue
) {
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
()) {
53
Message
m =
queue
.
getNextMessage
();
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
}
org.matsim.core.mobsim.messagequeue.Scheduler.queue
final MessageQueue queue
Definition:
Scheduler.java:29
org.matsim.core.mobsim.framework
Definition:
AbstractMobsimModule.java:22
org.matsim.core.mobsim.messagequeue.Scheduler
Definition:
Scheduler.java:27
org
org.matsim.core.mobsim.messagequeue.MessageQueue.getNextMessage
Message getNextMessage()
Definition:
MessageQueue.java:45
org.matsim.core.mobsim.messagequeue.SteppableScheduler.finished
boolean finished
Definition:
SteppableScheduler.java:31
org.matsim.core.mobsim.messagequeue.Message.getMessageArrivalTime
double getMessageArrivalTime()
Definition:
Message.java:35
org.matsim.core.mobsim
Definition:
DefaultMobsimModule.java:23
org.matsim.core.mobsim.messagequeue.SteppableScheduler.SteppableScheduler
SteppableScheduler(MessageQueue queue)
Definition:
SteppableScheduler.java:34
org.matsim.core
org.matsim.core.mobsim.messagequeue.SteppableScheduler
Definition:
SteppableScheduler.java:28
org.matsim.core.mobsim.messagequeue.SteppableScheduler.lookahead
Message lookahead
Definition:
SteppableScheduler.java:30
org.matsim.core.mobsim.framework.Steppable
Definition:
Steppable.java:26
org.matsim.core.mobsim.messagequeue.MessageQueue.isEmpty
boolean isEmpty()
Definition:
MessageQueue.java:49
org.matsim.core.mobsim.messagequeue.Message.handleMessage
abstract void handleMessage()
org.matsim.core.mobsim.messagequeue.SteppableScheduler.doSimStep
void doSimStep(double time)
Definition:
SteppableScheduler.java:39
org.matsim
org.matsim.core.mobsim.messagequeue.SteppableScheduler.isFinished
boolean isFinished()
Definition:
SteppableScheduler.java:64
org.matsim.core.mobsim.messagequeue.Message
Definition:
Message.java:27
org.matsim.core.mobsim.messagequeue.MessageQueue
Definition:
MessageQueue.java:32
Generated by
1.8.13