void SwitchNodeParent_bn ( int  link_index,   node_bn*  node,   node_bn*  new_parent )

Makes node new_parent a parent of node by replacing the existing parent at the link_indexth position, without modifying node's equation, or any of node's tables (such as CPT table or function table).

The new parent must be compatible with the old (e.g., same number of states), or an explanatory error will be generated, and no action taken.

NULL can be passed for new_parent, in which case the corresponding link will not be removed, but will become disconnected. If that link was not already named, then its name will become the name of the parent it was disconnected from. To determine whether a link is disconnected, see GetNodeKind_bn.

If the link was disconnected, this function may be used to re-connect it, by passing non-NULL for new_parent.

The parents of node are numbered from 0 to one less than the number of parents, and the ordering can be obtained using GetNodeParents_bn. Sometimes it is more useful to be able to pass a parent node instead of link_index, if you know there is exactly one link from the parent node to child. This can be accomplished with the SwitchNodeParent example below.

Version:

This function is available in all versions.

See also:

GetNodeParents_bn    Can be used to determine a suitable value for link_index
AddLink_bn    Adds a link between two nodes
DeleteLink_bn    Removes a link between two nodes
GetNodeKind_bn    To determine if a link is disconnected (returns DISCONNECTED_NODE)

Example:

The following function is available in NeticaEx.c:
// Switches the link from parent -> child to go from new_parent -> child. // Assumes there is already exactly one link from parent to child. // void SwitchNodeParent (node_bn* parent, node_bn* child, node_bn* new_parent){ int link_index = IndexOfNodeInList (parent, GetNodeParents_bn (child)); SwitchNodeParent_bn (link_index, child, new_parent); }