Time Control
abses.core.time_driver.time_condition ¶
A decorator to run a method based on a time condition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition
|
dict
|
A dictionary containing conditions to check against the |
required |
when_run
|
bool
|
If True, the decorated method will run when the condition is met. If False, the decorated method will not run when the condition is met. |
True
|
Example
class TestActor(Actor):
@time_condition(condition={"month": 1, "day": 1}, when_run=True)
def happy_new_year(self):
print("Today is 1th, January, Happy new year!")
parameters = {"time": {"start": "1996-12-24", "days": 1}}
model = MainModel(parameters=parameters)
agent = model.agents.new(TestActor, 1, singleton=True)
for _ in range(10):
print(f"Time now is {model.time}")
model.time.go()
agent.happy_new_year()
1998-01-01) if we run this model longer... It means, the function will be called when the condition is fully satisfied.
Source code in abses/core/time_driver.py
abses.core.time_driver.TimeDriver ¶
Bases: BaseModelElement, TimeDriverProtocol
TimeDriver provides the functionality to manage time.
A wrapper around datetime that adds simulation-specific functionality while providing access to all datetime attributes and methods.
Source code in abses/core/time_driver.py
fmt
cached
property
¶
String format of datetime. If the datetime is a date object, return the date format. Otherwise, return the datetime format.
expected_ticks
property
¶
Returns the expected ticks.
If the end_at is an integer or None, return the end_at. Otherwise, calculate the expected ticks.
should_end
property
¶
Should the model end or not. If the end_dt is a datetime object, return True if the current time is greater than or equal to the end_dt. If the end_dt is an integer, return True if the current tick is greater than or equal to the end_dt.
history
property
¶
Returns the history of the time driver. The history is a pandas Series object with the datetime as the index.
end_at
property
writable
¶
The real-world time or the ticks when the model should be end.
If the end time is a datetime object, it will be converted to a DateTime object. If the end time is an integer, it will be interpreted as a number of ticks.
dt
property
writable
¶
Current simulation time.
If assigned a start/duration/end time, it will be a datetime object representing the current simulation time. Otherwise, it will be a datetime object representing the tick-updated time.
to ¶
Specific the current time.
If the time is a string, it will be converted to a datetime object. If the time is an integer, it will be interpreted as a number of ticks.