You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-78Lines changed: 13 additions & 78 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,103 +13,38 @@ A Julia package for scheduling tasks in simulation environments with precise tim
13
13
```julia
14
14
using EnvironmentEngine
15
15
16
-
# Schedule a task every 20ms
17
-
every(20ms) do dt
18
-
println("Task executed")
19
-
end
20
-
21
-
# Process scheduled jobs
22
-
update!()
23
-
```
24
-
25
-
This will schedule a task to run every 20 milliseconds. Whenever `update!` is called, `EnvironmentEngine` will sync the clock with the real time and execute the scheduled tasks. A common pattern is the following:
26
-
27
-
```julia
28
-
using EnvironmentEngine
29
-
30
-
# Schedule a task every 200ms
16
+
# Schedule a task every 200 milliseconds
31
17
every(200ms) do dt
32
18
println("Task executed at $(now(global_clock()))")
33
19
end
34
20
35
-
#Process scheduled jobs
36
-
for_next(5s) do
21
+
#Run the scheduler for 1 second
22
+
for_next(1s) do
37
23
update!()
38
24
end
39
25
```
40
26
41
-
## Features
42
-
43
-
-**Timed Jobs**: Execute tasks at regular intervals
44
-
-**ASAP Jobs**: Execute tasks as soon as possible
45
-
-**Event Jobs**: Execute tasks when data arrives on channels
46
-
-**Multiple Clocks**: Machine time or controllable virtual time
47
-
-**Flexible Scheduling**: Global or custom schedulers
48
-
49
27
## Installation
50
28
51
29
```julia
52
30
using Pkg
53
31
Pkg.add("EnvironmentEngine")
54
32
```
55
33
56
-
## Basic Example
57
-
58
-
```julia
59
-
using EnvironmentEngine
60
-
61
-
# Schedule different types of jobs
62
-
every(3ms) do dt
63
-
println("Timed job: $(now(global_clock()))")
64
-
# Irregularly send events
65
-
ifrand() <0.5
66
-
put!(events, "Event $(rand())")
67
-
end
68
-
end
69
-
70
-
# Run this as often and soon as possible
71
-
every(asap) do
72
-
println("ASAP job executed")
73
-
end
74
-
75
-
# Create a channel for event-driven jobs
76
-
events =Channel{String}(Inf)
77
-
78
-
# Run this when an event is received
79
-
every(events) do event
80
-
println("Event received: $event")
81
-
end
82
-
83
-
# Simulate time progression
84
-
for_next(20ms) do
85
-
update!()
86
-
end
87
-
```
88
-
89
-
## Clock Types
90
-
91
-
### Machine Clock
92
-
Uses system time:
93
-
94
-
```julia
95
-
clock =MachineClock()
96
-
println(now(clock)) # Current system time
97
-
```
98
-
99
-
### Virtual Clock
100
-
Controlled time for simulations:
34
+
## Features
101
35
102
-
```julia
103
-
clock =VirtualClock()
104
-
set_time!(clock, 0.0s)
105
-
advance_time!(clock, 50ms)
106
-
println(now(clock)) # 0.05 s
107
-
```
36
+
-**Timed Jobs**: Execute tasks at regular intervals
37
+
-**ASAP Jobs**: Execute tasks as soon as possible
38
+
-**Event Jobs**: Execute tasks when data arrives on channels
39
+
-**Multiple Clocks**: Machine time or controllable virtual time
40
+
-**Flexible Scheduling**: Global or custom schedulers
41
+
-**Multi-threading**: Parallel job execution
108
42
109
43
## Documentation
110
44
111
-
-[Getting Started](https://lazydynamics.github.io/EnvironmentEngine.jl/dev/getting_started/) - Quick setup and basic examples
112
-
-[API Reference](https://lazydynamics.github.io/EnvironmentEngine.jl/dev/api/) - Complete function documentation
45
+
-[Getting Started](https://lazydynamics.github.io/EnvironmentEngine.jl/dev/) - Quick setup and basic examples
Copy file name to clipboardExpand all lines: docs/src/tutorials/clocks_and_time.md
+15Lines changed: 15 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,21 @@ When created, the `MachineClock` is paused by default, and can be resumed and pa
35
35
EnvironmentEngine.MachineClock
36
36
```
37
37
38
+
#### Stretch Factor
39
+
The `MachineClock` has a stretch factor, which is a factor by which the time is stretched. This is useful for building real-time applications, where the time is stretched to make the simulation run faster or slower than the real time. The stretch factor is set to 1.0 by default. If the stretch factor is greater than 1.0, the time will progress faster than the real time. For example, if the stretch factor is 2.0, the time will progress twice as fast as real time. You can set the stretch factor when creating the clock:
40
+
41
+
```@example clocks-machine-fast
42
+
using EnvironmentEngine
43
+
44
+
clock = MachineClock(stretch_factor = 2.0)
45
+
resume!(clock)
46
+
sleep(1.0)
47
+
pause!(clock)
48
+
println(now(clock)) # Current system time, 2.0 seconds
49
+
```
50
+
51
+
This is especially useful for debugging, and when you want to test if your agent has more/less computational resources available than on the machine you are running the simulation on.
0 commit comments