Skip to content

Commit

Permalink
fix openpsi example error opencog#3032
Browse files Browse the repository at this point in the history
  • Loading branch information
lcultx committed Apr 19, 2018
1 parent 124c12b commit e92a80a
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions examples/openpsi/basic.scm
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
; applicable, and the action is taken, then the goal is fulfilled.
;
; The context is meant to be one or more EvaluationLinks (or boolean
; combinations thereof). If these evaluate to true, then the action
; combinations thereof). If these evaluate to ture, then the action
; will be taken. The action must also be of the form of a predicate,
; (that is, myst be an EvaluationLink, or a boolean combination
; (that is, myst be an EvaluationLink, or a b oolean combination
; thereof). If the action also evaluates to true, then the goal is
; considered to be fulfilled.

Expand All @@ -42,20 +42,35 @@
(stv 0.1 1)
)

(define demand-foo (psi-demand "foo"))
(define demand-bar (psi-demand "bar"))
;(define demand-foo (psi-component "foo"))
(define (demand-foo) (psi-component "foo"))
;(define demand-bar (psi-component "bar"))
(define (demand-bar) (psi-component "bar"))

(define context-foo (list
(Evaluation
(GroundedPredicate "scm: check-situation")
(List (Concept "foo"))
)
))

(define action-foo (Evaluation
(GroundedPredicate "scm: action-doit")
(List (Concept "foo-action"))
))

(define goal-foo (Evaluation
(GroundedPredicate "scm: goal-update")
(List (Concept "foo-goal"))
))

(Member
(psi-rule
(list
(Evaluation (GroundedPredicate "scm: check-situation")
(List (Concept "foo"))))
(Evaluation (GroundedPredicate "scm: action-doit")
(List (Concept "foo-action")))
(Evaluation (GroundedPredicate "scm: goal-update")
(List (Concept "foo-goal")))
context-foo
action-foo
goal-foo
(stv 0.9 1)
demand-foo
(demand-foo)
)
(Concept "demo rule")
)
Expand All @@ -70,26 +85,22 @@
(Evaluation (GroundedPredicate "scm: goal-update")
(List (Concept "bar-goal")))
(stv 0.9 1)
demand-bar
(demand-bar)
)
(Concept "demo rule")
)


; Single-step the psi rule-selection engine `n` times.
; Single-step the psi rule-selection engine.
; This will print a message, single-step the psi rule engine, and
; then sleep for three seconds. The loop repeats until the loop count
; reaches zero.
(define (step-psi n)
(display "\n=================== Stepping psi one step\n")
(psi-step-per-demand)
(psi-step (demand-foo))
(psi-step (demand-bar))
(sleep 3)
(if (< 0 n) (step-psi (- n 1))))

(step-psi 4)
(display "Done running psi")

; Alternately, one can run the psi engine as fast as possible. This
; is not recommended for this demo, because it will clog the output
; with print statements.
; (psi-run-per-demand)
(display "Done running psi\n")

0 comments on commit e92a80a

Please sign in to comment.