Interface Propagator
-
- All Known Subinterfaces:
PropagationQueue<T>
- All Known Implementing Classes:
StaticPropagationQueue
public interface PropagatorPropagator is an interface that exposes thePropagationQueuetoBavetConstraintSession. It does not include the methods for inserting/updating/retracting facts, as the session accesses them via theAbstractNode.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 afterpropagateRetracts(),propagateUpdates()andpropagateInserts()have been called on every node in the layer. This happens in and is guaranteed byBavetConstraintSession.calculateScore(int).Nodes in a layer do not propagate entirely independently. In fact, we first call
propagateRetracts()on all nodes in the layer, thenpropagateUpdates()and finallypropagateInserts(). 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 Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidpropagateEverything()Convenience method for cases where the node layer only contains a single node, and therefore it can be propagated all at once.voidpropagateInserts()Must by preceded bypropagateRetracts()andpropagateUpdates().voidpropagateRetracts()Starts the propagation event.voidpropagateUpdates()Must be preceded bypropagateRetracts()and followed bypropagateInserts().
-
-
-
Method Detail
-
propagateRetracts
void propagateRetracts()
Starts the propagation event. Must be followed bypropagateUpdates().
-
propagateUpdates
void propagateUpdates()
Must be preceded bypropagateRetracts()and followed bypropagateInserts().
-
propagateInserts
void propagateInserts()
Must by preceded bypropagateRetracts()andpropagateUpdates(). Ends the propagation event and clears the queue.
-
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.
-
-