Updating Relations While a KB is Running
You can change a relation definition while the KB is running, paused, or reset. In general, when G2 is not reset, changing a relation definition changes any instances of that relation definition accordingly. For example, if you change the name of a relation definition while relations of that name exist, G2 renames the relations.
Note: We do not recommend making significant changes to relation definitions while your KB is running and while relations exist, because G2's short-term performance can be significantly degraded.
The following headings describe special precautions that you should take when making changes to relation definitions while your KB is not reset and while existing relations exist.
Updating the First Class and Second Class
If you update the
Second-class attributes of a relation definition, G2 preserves existing relations based on the new class, as long as the new class is a superior class of the existing class; otherwise, it may delete existing relations if an item conflicts with the new class.
Updating the Type of Relation
If you change the cardinality of a relation to be more restrictive, for example, changing a many-to-one relation to a one-to-one relation, G2 removes all relation instances that conflict with the new relation type, leaving only one. G2 chooses the remaining relation arbitrarily from the original set.
Updating Symmetric Relations
For relations whose
Relation-is-symmetric attribute is
yes, the effect on existing relations of changing the
Relation-is-symmetric attributes can be more complex, depending on the classes of items that you specify.
If the items participating in the relation are subclasses of both the first class and the second class, and you change the definition such that G2 must delete one or more relations, G2 arbitrarily determines which item is the relation source and which item is the relation target.
Updating Relations While Executing Procedures
If a statement or action in a procedure refers to a relation, and you make a change to the relation definition while the procedure is executing that statement, the procedure continues to execute using the existing relation. Any changes to the relation are not visible to the procedure's execution.
For example, given a
for statement in a procedure that refers to a set of items based on their relation to another item, if you change the definition of that relation while the loop is processing, G2 neither adds to nor removes from the definition of the set of items.
Similarly, if a local name in a procedure refers to an item that participates in an instance of a relation, and you change the definition of the relation while the procedure is executing, G2 uses the existing value of the local name.
Updating a Relation While a Rule is Executing
If a rule refers to a relation, and you change its relation definition while the rule is executing, the rule continues executing using the existing relation.
Note: Changing the definition of a relation can cause G2 to remove relations. For each relation that is removed for this reason, G2 generates a
ceases to be related event. In turn, generating these events causes G2 to invoke
whenever rules that refer to these events. For more information, see Invoking Rules using Relations.
Updating a Relation When Saving a KB Snapshot File
After you begin saving the current KB to a KB snapshot file (by invoking the
g2-snapshot system procedure), if you change a relation definition, G2 first writes any relations affected by the change to the file before changing relations in the current KB.
Copyright © 1997 Gensym Corporation, Inc.