forked from opencog/opencog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.scm
More file actions
95 lines (84 loc) · 2.42 KB
/
Copy pathbasic.scm
File metadata and controls
95 lines (84 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
;
; Basic example of OpenPsi usage
;
;
; Psi rules have the general form
;
; ImplicationLink <TV>
; SequentialAndLink
; <context>
; <action>
; <goal>
;
; The intended meaning of these rules is that if the context is
; 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
; will be taken. The action must also be of the form of a predicate,
; (that is, myst be an EvaluationLink, or a boolean combination
; thereof). If the action also evaluates to true, then the goal is
; considered to be fulfilled.
(use-modules (opencog) (opencog openpsi))
(define (check-situation atom)
(display "Checking the current situation: ")
(display atom)
(stv 1 1)
)
;; Return true only if the result of performing the action
;; actually fulfilled the goal.
(define (action-doit atom)
(display "Taking the action: ")
(display atom)
(stv 1 1)
)
(define (goal-update atom)
(display "Updating the goal for: ")
(display atom)
(stv 0.1 1)
)
(define demand-foo (psi-demand "foo"))
(define demand-bar (psi-demand "bar"))
(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")))
(stv 0.9 1)
demand-foo
)
(Concept "demo rule")
)
(Member
(psi-rule
(list
(Evaluation (GroundedPredicate "scm: check-situation")
(List (Concept "bar"))))
(Evaluation (GroundedPredicate "scm: action-doit")
(List (Concept "bar-action")))
(Evaluation (GroundedPredicate "scm: goal-update")
(List (Concept "bar-goal")))
(stv 0.9 1)
demand-bar
)
(Concept "demo rule")
)
; Single-step the psi rule-selection engine `n` times.
; 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)
(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)