ReteEngine 1.0
A rules engine and builder
Loading...
Searching...
No Matches
ReteCore.BetaMemory Class Reference

The BetaMemory class represents a node in a Rete network that stores partial matches (tokens) of facts and propagates them to successor nodes. It implements the IReteNode interface, allowing it to participate in the Rete network, and the ILatentMemory interface, indicating that it can hold tokens that may not yet be fully matched. The BetaMemory is responsible for managing the collection of tokens, handling assertions, retractions, and refreshes of facts, and ensuring that successor nodes are updated accordingly when changes occur. It serves as a crucial component in the Rete algorithm, enabling efficient pattern matching and rule evaluation by maintaining the state of partial matches and facilitating the flow of information through the network. More...

Inheritance diagram for ReteCore.BetaMemory:
ReteCore.IReteNode ReteCore.ILatentMemory

Public Member Functions

void AddSuccessor (IReteNode node)
 Adds a successor node to the list of successors that will receive tokens asserted, retracted, or refreshed through this BetaMemory. This method allows for building the Rete network by connecting nodes together. When a new successor is added, it will start receiving tokens from this BetaMemory whenever operations are performed on it. The method takes an IReteNode as a parameter and adds it to the _successors list, enabling the propagation of tokens to that node in future operations.
void Assert (object fact)
 The Assert method adds a new token to the BetaMemory if it doesn't already exist and propagates it to all successor nodes. It checks for duplicates to avoid redundant processing.
void Retract (object fact)
 The Retract method removes tokens containing the specified fact from the BetaMemory and notifies all successor nodes of the retraction. It identifies tokens that include the retracted fact and ensures that they are removed from the memory, allowing successor nodes to update their state accordingly.
void Refresh (object fact, string propertyName)
 The Refresh method is responsible for updating tokens in the BetaMemory when a fact changes. It identifies tokens that contain the changed fact and propagates the refresh to all successor nodes, allowing them to re-evaluate their conditions based on the updated information. This ensures that the Rete network remains consistent and up-to-date as facts evolve over time.
void DebugPrint (object fact, int level=0)
 The DebugPrint method provides a way to output the current state of the BetaMemory for debugging purposes. It prints the number of tokens currently stored in the memory, along with an optional indentation level to help visualize the structure of the Rete network. This method can be called to inspect the contents of the BetaMemory at any point during execution, allowing developers to understand how facts are being matched and propagated through the network. The fact parameter is not used in this implementation but can be included for future enhancements or specific debugging scenarios.

Public Attributes

List< Token_tokens = new()
 The collection of tokens (partial matches) that have been asserted into this BetaMemory. Each token represents a combination of facts that have matched certain conditions in the Rete network. The collection allows for efficient checking of whether a token is already present, and it serves as the basis for propagating matches to successor nodes when new facts are asserted or existing facts are retracted or refreshed. When a new token is asserted, it is added to this collection if it is not already present, and when a fact is retracted, any tokens containing that fact are removed from the collection. The presence of tokens in this collection determines whether they will be propagated to successor nodes when operations are performed on them.

Properties

IEnumerable< TokenTokens [get]
 A collection of tokens that have been asserted into this BetaMemory. Each token represents a combination of facts that have matched certain conditions in the Rete network. The collection allows for efficient checking of whether a token is already present, and it serves as the basis for propagating matches to successor nodes when new facts are asserted or existing facts are retracted or refreshed. When a new token is asserted, it is added to this collection if it is not already present, and when a fact is retracted, any tokens containing that fact are removed from the collection. The presence of tokens in this collection determines whether they will be propagated to successor nodes when operations are performed on them.

Detailed Description

The BetaMemory class represents a node in a Rete network that stores partial matches (tokens) of facts and propagates them to successor nodes. It implements the IReteNode interface, allowing it to participate in the Rete network, and the ILatentMemory interface, indicating that it can hold tokens that may not yet be fully matched. The BetaMemory is responsible for managing the collection of tokens, handling assertions, retractions, and refreshes of facts, and ensuring that successor nodes are updated accordingly when changes occur. It serves as a crucial component in the Rete algorithm, enabling efficient pattern matching and rule evaluation by maintaining the state of partial matches and facilitating the flow of information through the network.

Member Function Documentation

◆ AddSuccessor()

void ReteCore.BetaMemory.AddSuccessor ( IReteNode node)

Adds a successor node to the list of successors that will receive tokens asserted, retracted, or refreshed through this BetaMemory. This method allows for building the Rete network by connecting nodes together. When a new successor is added, it will start receiving tokens from this BetaMemory whenever operations are performed on it. The method takes an IReteNode as a parameter and adds it to the _successors list, enabling the propagation of tokens to that node in future operations.

Parameters
nodeThe node to add as a successor. Cannot be null.

◆ Assert()

void ReteCore.BetaMemory.Assert ( object fact)

The Assert method adds a new token to the BetaMemory if it doesn't already exist and propagates it to all successor nodes. It checks for duplicates to avoid redundant processing.

Parameters
factThe fact object to be asserted and passed to successor nodes. Cannot be null.

Implements ReteCore.IReteNode.

◆ DebugPrint()

void ReteCore.BetaMemory.DebugPrint ( object fact,
int level = 0 )

The DebugPrint method provides a way to output the current state of the BetaMemory for debugging purposes. It prints the number of tokens currently stored in the memory, along with an optional indentation level to help visualize the structure of the Rete network. This method can be called to inspect the contents of the BetaMemory at any point during execution, allowing developers to understand how facts are being matched and propagated through the network. The fact parameter is not used in this implementation but can be included for future enhancements or specific debugging scenarios.

Parameters
factThe fact object to include in the debug output. Can be any object; its string representation will be printed.
levelThe indentation level to apply to the debug message. Each level increases indentation by spaces. Defaults to 0.

Implements ReteCore.IReteNode.

◆ Refresh()

void ReteCore.BetaMemory.Refresh ( object fact,
string propertyName )

The Refresh method is responsible for updating tokens in the BetaMemory when a fact changes. It identifies tokens that contain the changed fact and propagates the refresh to all successor nodes, allowing them to re-evaluate their conditions based on the updated information. This ensures that the Rete network remains consistent and up-to-date as facts evolve over time.

Parameters
factThe fact object whose property is being refreshed. Cannot be null.
propertyNameThe name of the property to refresh. Cannot be null or empty.

Implements ReteCore.IReteNode.

◆ Retract()

void ReteCore.BetaMemory.Retract ( object fact)

The Retract method removes tokens containing the specified fact from the BetaMemory and notifies all successor nodes of the retraction. It identifies tokens that include the retracted fact and ensures that they are removed from the memory, allowing successor nodes to update their state accordingly.

Parameters
factThe fact object to retract. Cannot be null.

Implements ReteCore.IReteNode.

Property Documentation

◆ Tokens

IEnumerable<Token> ReteCore.BetaMemory.Tokens
get

A collection of tokens that have been asserted into this BetaMemory. Each token represents a combination of facts that have matched certain conditions in the Rete network. The collection allows for efficient checking of whether a token is already present, and it serves as the basis for propagating matches to successor nodes when new facts are asserted or existing facts are retracted or refreshed. When a new token is asserted, it is added to this collection if it is not already present, and when a fact is retracted, any tokens containing that fact are removed from the collection. The presence of tokens in this collection determines whether they will be propagated to successor nodes when operations are performed on them.

Implements ReteCore.ILatentMemory.


The documentation for this class was generated from the following file:
  • ReteCore/BetaMemory.cs