Diff of /doc/source/logic_programming/plans.txt [5cabfd] .. [4dca5a] Maximize Restore

  Switch to unified view

a/doc/source/logic_programming/plans.txt b/doc/source/logic_programming/plans.txt
...
...
154
`.krb file`_, see `Bc_rule Syntax`_.
154
`.krb file`_, see `Bc_rule Syntax`_.
155
155
156
Running the Example
156
Running the Example
157
========================
157
========================
158
158
159
.. This code is hidden.  It will add '' to sys.path, change to the doc.examples
160
   directory and store the directory path in __file__ for the code section
161
   following:
162
   >>> import sys
163
   >>> if '' not in sys.path: sys.path.insert(0, '')
164
   >>> import os
165
   >>> os.chdir("../../examples")
166
   >>> __file__ = os.getcwd()
167
159
The plan is created as a byproduct of proving_ the goal:
168
The plan is created as a byproduct of proving_ the goal:
160
169
161
    >>> from pyke import knowledge_engine
170
    >>> from pyke import knowledge_engine
171
162
    >>> engine = knowledge_engine.engine('doc.examples')
172
    >>> engine = knowledge_engine.engine(__file__)
163
    >>> engine.activate('plan_example')
173
    >>> engine.activate('plan_example')
164
    >>> no_vars, plan1 = engine.prove_1('plan_example', 'transfer',
174
    >>> no_vars, plan1 = \
165
    ...                                 (('bruce', 'checking'),
175
    ...   engine.prove_1_goal(
166
    ...                                  ('bruce', 'savings')),
176
    ...     'plan_example.transfer((bruce, checking), (bruce, savings))')
167
    ...                                 0)
168
177
169
``plan1`` is now a program to transfer X amount
178
``plan1`` is now a program to transfer X amount
170
from 'bruce', 'checking' to 'bruce', 'savings'.  Using the above rule names
179
from 'bruce', 'checking' to 'bruce', 'savings'.  Using the above rule names
171
as function names, plan1 looks like this:
180
as function names, plan1 looks like this:
172
181
...
...
196
These were specified as `pattern variables`_ in the code and are cooked_
205
These were specified as `pattern variables`_ in the code and are cooked_
197
into the plan along with the function call graph.
206
into the plan along with the function call graph.
198
207
199
Let's create a second program:
208
Let's create a second program:
200
209
201
    >>> no_vars, plan2 = engine.prove_1('plan_example', 'transfer',
210
    >>> no_vars, plan2 = \
202
    ...                                 (('bruce', 'checking'),
211
    ...   engine.prove_1_goal(
212
    ...     'plan_example.transfer((bruce, checking), '
203
    ...                                  ('my_other_bank', 'bruce', 'savings')),
213
    ...                           '(my_other_bank, bruce, savings))')
204
    ...                                 0)
205
214
206
``plan2`` is now a program to transfer X amount
215
``plan2`` is now a program to transfer X amount
207
from 'my_other_bank', 'bruce', 'checking' to 'bruce', 'savings'.
216
from 'my_other_bank', 'bruce', 'checking' to 'bruce', 'savings'.
208
Plan2 looks like this:
217
Plan2 looks like this:
209
218
...
...
222
    deposit 200 to central_accts ach_send_acct
231
    deposit 200 to central_accts ach_send_acct
223
    send 200 to bank my_other_bank acct bruce savings
232
    send 200 to bank my_other_bank acct bruce savings
224
233
225
And the final use case:
234
And the final use case:
226
235
227
    >>> no_vars, plan3 = engine.prove_1('plan_example', 'transfer',
236
    >>> no_vars, plan3 = \
228
    ...                                 (('my_other_bank', 'bruce', 'checking'),
237
    ...   engine.prove_1_goal(
238
    ...     'plan_example.transfer((my_other_bank, bruce, checking), '
229
    ...                                  ('bruce', 'savings')),
239
    ...                           '(bruce, savings))')
230
    ...                                 0)
231
    >>> plan3(150)
240
    >>> plan3(150)
232
    get 150 from bank my_other_bank acct bruce checking
241
    get 150 from bank my_other_bank acct bruce checking
233
    withdraw 150 from central_accts ach_recv_acct
242
    withdraw 150 from central_accts ach_recv_acct
234
    deposit 150 to bruce savings
243
    deposit 150 to bruce savings
235
244