agenda는 시뮬레이션 시간을 명시적인 데이터로 만든다.
시간표가 붙은 동작을 정렬된 agenda에 넣으면 등록 순서와 달라도 가장 이른 시뮬레이션 시간부터 처리할 수 있습니다.
시뮬레이션은 등록된 순서를 따르지 않고 다음 사건을 어떻게 고를까요?
- Represent an event as explicit time and action data
- Insert events in nondecreasing timestamp order
- Preserve scheduling order between events at the same time
- Accumulate state by processing the earliest event first
schedule walks an already ordered agenda until the new time belongs before the current event. Equal timestamps do not satisfy the strict less-than test, so a new event at that time is inserted after events already there. The returned list exposes both simulated time and tie order.
propagate removes the earliest event, applies its numeric change to signal, and records the resulting state beside that event time. The agenda models logical simulation time rather than waiting for a wall clock, and these examples do not model simultaneous-event physics beyond their explicit insertion rule.
(begin
(define (schedule time action agenda)
(let ((event (list time action)))
(cond ((null? agenda) (list event))
((< time (car (car agenda))) (cons event agenda))
(else
(cons (car agenda)
(schedule time action (cdr agenda)))))))
(define agenda
(schedule 5 'close
(schedule 2 'sense
(schedule 5 'open '()))))
agenda)- 출력
- —
- 값
- —
- 진단
- —
The first program returns ((2 sense) (5 open) (5 close)). The second returns ((2 1) (4 4) (5 14)).
Follow schedule comparisons until each event reaches its timestamp position. Then watch propagate remove times 2, 4, and 5 in order while signal becomes 1, 4, and 14. These traces describe this agenda and its explicit tie rule only.
힌트를 보기 전에 프로그램을 바꿔 보세요.
Schedule an event named reset at time 1 in the first program. Predict its position without changing the insertion rule.
힌트 하나 보기
The new timestamp is earlier than every event already in the agenda.