3Inference Environments (Basic)

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

Exit continuation

Agenda

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 with-new-inference-environment 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.

See Section 3.3 Current Inference Environment Fields for more information on accessing the fields of the current inference environment.

data-index – an eq? hash table that provides an index of (non-goal) match nodes for each fact kind. This field is maintained internally.

goal-index – an eq? hash table that provides an index of goal match nodes for each fact kind. This field is maintained internally.

rule-nodes – a list of the rule nodes for the activated rule sets. This field is maintained internally.

exit – 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.

next-assertion-id – the id to be used for the next assertion. This is auto-incremented each time an assertion is created. This field is maintained internally.

assertion-index – 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.

trace – 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.

agenda – 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.

rule – the currently executing rule instance, or false, #f, if no rule is currently being executed.

strategy – 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:

depth – depth first. New rule instances are added to the agenda after all other rule instances of equal (or higher) priority.

breadth – breadth first. New rule instances are added at to the agenda before all of ther rule instance ot equal (or lower) priority.

order – rule order. Rule instances of equal priority on the agenda are ordered according to the order of the rules in their corresponding rule sets.

simplicity – 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.

complex – 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 – random. Rules instances of equal priority on the agenda are in random order.

This may be specified by the user.

parent – the parent inference environment, or false, #f, if this is a top-level inference environment. (See Chapter ???.)

rules-fired – the number of rules instances that have been executed by the current inference.

(make-inference-environemnt[parent])→inference-environment?

parent:(or/cinference-environmentfalse/c)=#f

Returns a new inference environment with the given parent inference environment. The newly created inference environment is empty. That is, there are no rule sets activated, no facts are asserted, user specifiable fields have their default values, and no inference is running in the environment.

default-inference-environment

Contains the inference environment that is used as the default value for the current inference environment (see Section 3.2).

3.2Current Inference Environment

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.

Gets or sets the current inference environment. A guard procedure ensures that the value of current-inference-environment is indeed an inference environment, as determined by inference-environment?, otherwise a type error is raised.

(with-inference-environmentenv

body...+)

Evaluates its body with the current inference environment bound to the value of env.

(with-new-inference-environment

body...+)

Evaluates its body with the current inference environment bound to a newly created inference environment. This is the most common way to create and use a new inference environment.

(with-new-child-inference-environment

body...+)

Evaluates its body with the current inference environment bound to a newly created inference environment that is a child of the current inference environement.

3.3Current Inference Environment Fields

The most common way of accessing the current inference environment fields is using the following procedures.