| Prev | Start of Chapter | Next Chapter | Contents | Index | (12 out of 12)

Understanding How Blocks Evaluate

To understand how blocks in a diagram evaluate, you need to understand how NOL:

Invoking an Individual Block

NOL invokes a block when:

Note that NOL performs inference path filtering, which means an input inference path only invokes a downstream block if the belief value changes.

If a block is invoked during a sweep, NOL evaluates the block on the current sweep. If a block is invoked when no sweep is in progress, NOL evaluates the block on the next sweep. The important thing to note is that block invocation happens independently of block evaluation.

If a block located on the subworkspace of an encapsulation is invoked, NOL invokes the encapsulation block, and any superior encapsulations, until all the invocations are on workspaces that contain blocks other than encapsulation block subworkspaces.

Sweeping Blocks on a Diagram

NOL evaluates a diagram by sweeping invoked blocks. A sweep is when NOL searches for invoked blocks, evaluates them, and continues until no more blocks are left to evaluate.

NOL performs three types of sweeps:

For each type of sweep, NOL follows certain rules to check blocks for invocations and evaluate these blocks.

Sweeping Diagrams with Entry Points

An entry point sweep occurs when NOL evaluates all invoked entry points and propagates the entry point's current value. If the entry point receives several values between sweeps, only the last value that the entry point receives is passed downstream.

You can control the frequency of entry point sweeps in the Environment Settings under the Preferences menu. By default, entry point sweeps happen once every second. For more information, see "Setting the Sweep Interval".

Sweeping Diagrams Based on Events

Certainevents cause NOL to begin a sweep immediately. These events include:

NOL invokes signal generators and clocks according to their own internal timing mechanisms. When these blocks are invoked, an event-response sweep happens immediately.

All clocks and signal generators scheduled to fire within the same quarter-second are grouped together into the same sweep.

Sweeping Diagrams Based on Manual Evaluation of Blocks

When you evaluate a block manually by using the evaluate menu choice or by using the override menu choice, a manual sweep happens immediately.

Manual invocations are never mixed with other types of invocations, because typically each manual invocation is associated with a specific G2 window. Each override or manual evaluation results in a manual sweep, which is handled separately from any other scheduled activities.

Sweeping the Diagram

When NOL sweeps a diagram, it first checks all workspaces in an arbitrary order to see if there are any blocks on these workspaces that have been invoked.

If such a workspace has an invocation, NOL sweeps the workspace in the order described in "Evaluating Blocks on Individual Workspaces". Blocks that have an invocation evaluate, which might lead to the invocation of other blocks, which are also evaluated in the current sweep.

When an encapsulation block evaluates, NOL sweeps its subworkspace. When NOL is finished sweeping the subworkspace, evaluation returns to the superior workspace.

NOL continues to evaluate blocks until no more invocations exist, at which time the sweep ends.

Evaluating Blocks on Individual Workspaces

To understand the order of evaluation of blocks on an individual workspace, you can think of each block on a workspace as having a number, which is the order in which NOL checks for invocations on the workspace.

If the blocks on a workspace contain no feedback loops, NOL searches for blocks in a depth-first order, ignoring all connection posts, except those that connect to connection posts on the same workspace. For a detailed description of depth-first ordering, see Introduction to Algorithms, T.H. Cormen, C. E. Leiserson, R.L. Rivest, McGraw-Hill, 1990.

If a block branches to one of multiple output paths along multiple parallel lines, NOL arbitrarily chooses one path and continues numbering sequentially in a depth-first manner until it has ordered all blocks along the path. NOL then backs up to the block with a decision point and picks up the sequential numbering of blocks along the other path.

If a diagram contains blocks with multiple input paths, in general, the block with multiple inputs is always evaluated after all of its input blocks evaluate, and any of its inputs can cause the block to evaluate. This means that, in general, blocks with multiple inputs only evaluate once per sweep. The exception is blocks that have the attribute Multiple Invocations set to queue or ok, in which case the block can evaluate more than once per sweep.

The result is a list in which all upstream blocks have a lower number than all downstream blocks, including blocks with multiple input paths. Numbering starts at zero at a block that has no upstream blocks and continues sequentially until every block on the workspace has been accounted for. If a diagram contains multiple blocks with no upstream blocks, NOL arbitrarily chooses one of these blocks as a starting point.

Capabilities and restrictions are always numbered sequentially directly after the blocks to which they are attached, so they always evaluate directly after the block to which they are attached.

This diagram shows how NOL numbers blocks on a simple diagram with two parallel paths in a depth-first order:


This diagram shows how NOL numbers blocks on a diagram that contains a block with multiple inputs, in this example, block D:


Inside of feedback loops, no upstream/downstream relationships exist, thus feedback loops are numbered in two steps. First, the blocks in the loop are numbered via a depth-first search, according to the explanation above. Next, NOL backs up to the block that begins the loop and "promotes" the blocks in the loop so that they appear consecutively in the list, without changing their relative order. In this way, the loop processes until it is finished before the downstream blocks evaluate. When a diagram contains nested loops, the same "promotion" process assures that the inner loop finishes evaluating before each evaluation of the outer loop.

This diagram shows how NOL numbers blocks on a diagram with a loop:


When blocks evaluate, an "evaluation pointer" advances from block to block, following the serial numbering of blocks in ascending order. If the pointer arrives at an invoked block, the block evaluates. If the pointer arrives at a block that has not been invoked, the pointer moves to the next block. The only time the pointer moves back in the series is when there is a path from a high-numbered block to a low-numbered block, at which point evaluation returns to the low-numbered block only if it has a pending invocation. Evaluation then continues from the low- numbered block. Evaluation on the workspace ends when the evaluation pointer reaches the last block in the list.

Asynchronous blocks, like delay blocks, do not hold up evaluation. When these types of blocks begin evaluation, the evaluation pointer moves directly to the next block. When the delay is finished, a new evaluation sweep begins.

| Prev | Start of Chapter | Next Chapter | Contents | Index | (12 out of 12)

Copyright © 1996, Gensym Corporation, Inc.