Interface Propagator

  • All Known Subinterfaces:
    PropagationQueue<T>
    All Known Implementing Classes:
    StaticPropagationQueue

    public interface Propagator
    Propagator is an interface that exposes the PropagationQueue to BavetConstraintSession. It does not include the methods for inserting/updating/retracting facts, as the session accesses them via the AbstractNode.

    Nodes come in layers, and each layer has a unique index. Nodes in higher layers receive their inputs from nodes in lower layers. Propagation starts from the lowest layer (0) and goes up. Layer N+1 only starts propagating after layer N has completed its propagation, that is after propagateRetracts(), propagateUpdates() and propagateInserts() have been called on every node in the layer. This happens in and is guaranteed by BavetConstraintSession.calculateScore(int).

    Nodes in a layer do not propagate entirely independently. In fact, we first call propagateRetracts() on all nodes in the layer, then propagateUpdates() and finally propagateInserts(). This order of operations is necessary to ensure consistent data in the higher layer nodes.

    Example: consider a join node that joins two different classes of facts, say A and B. The join node has two inputs, one for each type of fact. Both of these inputs are in the same layer, say layer 1. This puts the join node in layer 2. If we had the left input propagate updates and inserts before the right input propagates retracts, a situation could occur where the left input is attempting to join with something that will later be retracted. And this, in turn, could result in a runtime exception, because the right input data at that point is stale. By running retracts on all nodes in a layer first, and then all updates and then all inserts, we make sure that the join node always has up-to-date data. And due to the fact that propagation is done in layers, the join propagations will only ever be triggered after its inputs have completed their propagation.

    As this is critical to the correctness of Bavet, there is specific test coverage for these corner cases.

    See Also:
    More information about propagation.
    • Method Detail

      • propagateRetracts

        void propagateRetracts()
        Starts the propagation event. Must be followed by propagateUpdates().
      • propagateEverything

        default void propagateEverything()
        Convenience method for cases where the node layer only contains a single node, and therefore it can be propagated all at once.