An inference environment encapsulates the state of an executing inference system. This state information includes the following:
Rule network (nodes, data index, goal, index, rule node list)
Assertion index (2 levels) and next assertion id
Current rule, trace flag, and conflict resolution strategy
It is a good practice to create a new inference environment for all of your inference systems. The facilitates this and is used in all of the examples in this document. The primary advantage is to ensure a clean environment for each new execution of the inference system.
The PLT Scheme Inference Collection supports multiple inference environments existing at the same time.
This chapter describes the features of basic simulation environments.
The inference-environment structure defines an inference environment.
(struct inference-environment (data-index goal-index rule-nodes exit next-assertion-id assertion-index trace agenda rule strategy parent rules-fired)) data-index : hash-eq? goal-index : hash-eq? rule-nodes : (listof ) exit : (or/c procedure? false/c) next-assertion-id : exact-positive-integer? assertion-index : hash-eq? trace : boolean? agenda : (mlistof ) rule : (or/c false/c) strategy : (one-of/c 'depth 'breadth 'order 'simplicity 'complex 'random) parent : (or/c false/c) rules-fired : exact-nonnegative-integer?
See Section 3.3 Current Inference Environment Fields for more information on accessing the fields of the current inference environment.
an eq? hash table that provides an index of (non-goal) match nodes for each fact kind. This field is maintained internally.
an eq? hash table that provides an index of goal match nodes for each fact kind. This field is maintained internally.
a list of the rule nodes for the activated rule sets. This field is maintained internally.
the continuation to exit the inference currently running in the environment, or false, #f, if no inference is currently running in the environment. This field is used internally.
the id to be used for the next assertion. This is auto-incremented each time an assertion is created. This field is maintained internally.
the level-1 assertion index for the environment. Each entry in the level-1 assertion index is a level-2 index. This field is used internally.
if true, #t, information on the current inference (e.g., assertions, deletions, and rule firings) is printed. The default is false, #f. This may be specified by the user.
a list of the rule instances that are currently eligible to fire. This list is maintained in a priority order. The ordering is controlled by the current conflict resolution strategy. This field is used internally.
the currently executing rule instance, or false, #f, if no rule is currently being executed.
the conflict resolution strategy used to order the agenda. This determines the order in which rules or equal priority are fired. The available conflict resolution strategies are:
This may be specified by the user.
depth first. New rule instances are added to the agenda after all other rule instances of equal (or higher) priority.
breadth first. New rule instances are added at to the agenda before all of ther rule instance ot equal (or lower) priority.
rule order. Rule instances of equal priority on the agenda are ordered according to the order of the rules in their corresponding rule sets.
simplest first. Rule instance of equal priority on the agenda are ordered such that the simplest rule instances (i.e., the ones with the fewest preconditions) are first.
most complex first. Rule instance of equal priority on the agenda are ordered such that the most complex rule instances (i.e., the ones with the most preconditions) are first.
random. Rules instances of equal priority on the agenda are in random order.
the parent inference environment, or false, #f, if this is a top-level inference environment. (See Chapter ???.)
the number of rules instances that have been executed by the current inference.
The current inference environment is the inference environment that is the current focus for most of the inference calls. It is both thread and continuation specific.
|( env) → void?|
The most common way of accessing the current inference environment fields is using the following procedures.
|( rule-nodes) → void?|
|rule-nodes : (listof )|
|() → (listof )|
|( next-assertion-id) → void?|
|next-assertion-id : exact-positive-integer?|
|( agenda) → void?|
|agenda : (mlistof )|
|() → (mlistof )|
|( rule) → void?|
|rule : (or/c false/c)|
|() → (or/c false/c)|
|( strategy) → void?|
|strategy : (one-of/c 'depth 'breadth 'order 'simplicity 'complex 'random)|
|→ (one-of/c 'depth 'breadth 'order 'simplicity 'complex 'random)|
|( parent) → void?|
|parent : (or/c false/c)|
|→ (or/c false/c)|