public class SimulationClockControl extends Object
The basic design for this scheme is given at https://github.com/powertac/powertac-server/wiki/Time-management. The goal is to produce a tick by calling timeService.updateTime() every n seconds, where n is 3600/timeService.rate. So if timeService.rate is 360, this would be a tick every 10 seconds. Current simulation time is given by the formula time = rate * (systemTime - start) + base where start, base, and rate are simulation parameters.
We assume that the simulator is a single thread, although it may control other threads. That thread waits for the next tick, then does some work. Ideally, that work will be completed in fewer than n seconds, but occasionally it may take longer. Since the broker needs to keep track of time on its own, it needs to know when this happens, and must be informed of the updated start time so that it can compute a simulation time that agrees with the server. In addition, a broker might want to pause the clock in order to allow a user to fill out a dialog or otherwise interact with a user. Given an appropriate set of messages, this event could be handled in much the same way as a server timeslot overrun.
| Modifier and Type | Class and Description |
|---|---|
static class |
SimulationClockControl.Status |
| Modifier and Type | Method and Description |
|---|---|
void |
checkClockDrift()
Compares sim time to sys time, updates start if it's off too much
|
void |
complete()
Indicates that the simulator has completed its work on the current
timeslot.
|
static SimulationClockControl |
getInstance()
Returns the instance, which of course will be null if the singleton
is not yet initialized.
|
static void |
initialize(CompetitionControlService competitionControl,
org.powertac.common.TimeService timeService)
Creates the instance and sets the reference to the timeService.
|
void |
releasePause()
Releases an externally-requested pause.
|
void |
requestPause()
Serves an external pause request.
|
void |
scheduleTick()
Schedules the next tick.
|
void |
setStart(long start)
Sets the sim clock start time, which in turn gets propagated to the
timeService.
|
void |
stop()
Stops the clock.
|
void |
waitForTick(int n)
Blocks the caller until the next tick.
|
void |
waitUntilStop() |
public static void initialize(CompetitionControlService competitionControl, org.powertac.common.TimeService timeService)
public static SimulationClockControl getInstance()
public void setStart(long start)
public void scheduleTick()
public void complete()
public void stop()
public void waitUntilStop()
public void waitForTick(int n)
public void checkClockDrift()
public void requestPause()
public void releasePause()
Copyright © 2014 Power TAC. All Rights Reserved.