1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- (defstruct model
- clock
- response ; hold response from model
- )
- (defun evaluate-program (program)
- (let* ((result (run-experiment program))
- (result-response (first result))
- (result-time (second result)))
- (if (and (equalp "hello" result-response)
- (< result-time 800)
- (< 400 result-time))
- 0
- 1)))
- (defun run-experiment (program)
- (let ((md (make-model :clock 0 :response "")))
- (interpret program md)
- (list (model-response md)
- (model-clock md))))
- (defun interpret (operator md)
- (case (operator-label operator)
- (:respond-hello
- (incf (model-clock md) 500)
- (setf (model-response md) "hello"))
- (:respond-bye
- (incf (model-clock md) 500)
- (setf (model-response md) "bye"))
- (:seq
- (interpret (first (operator-children operator)) md)
- (interpret (second (operator-children operator)) md))
- (otherwise
- (error "interpret: unknown operator ~a" (operator-label operator)))))
- (defstruct operator
- label
- children
- )
- ;; Example models - each model has a unique control program
- (defun run-and-show (program name)
- (let* ((result (run-experiment program))
- (result-response (first result))
- (result-time (second result)))
- (format t "Model 1~&")
- (format t "-- response is ~a at ~a ms~&" result-response result-time)
- (format t "-- evaluation is ~a~&" (evaluate-program program))))
- ;; - simplest models just respond in one way
- (run-and-show (make-operator :label :respond-hello) "Model 1")
- (run-and-show (make-operator :label :seq
- :children (list (make-operator :label :respond-bye)
- (make-operator :label :respond-hello)))
- "Model 2")
|