libSBML C API
5.18.0
|
The rule type AlgebraicRule_t is derived from the parent class Rule_t. It is used to express equations that are neither assignments of model variables nor rates of change. AlgebraicRule_t does not add any attributes to the basic Rule_t; its role is simply to distinguish this case from the other cases.
In the context of a simulation, algebraic rules are in effect at all times, t 0. For purposes of evaluating expressions that involve the delay "csymbol" (see the SBML specification), algebraic rules are considered to apply also at t 0. Please consult the relevant SBML specification for additional information about the semantics of assignments, rules, and entity values for simulation time t 0.
An SBML model must not be overdetermined. The ability to define arbitrary algebraic expressions in an SBML model introduces the possibility that a model is mathematically overdetermined by the overall system of equations constructed from its rules, reactions and events. Therefore, if an algebraic rule is introduced in a model, for at least one of the entities referenced in the rule's "math" element the value of that entity must not be completely determined by other constructs in the model. This means that at least this entity must not have the attribute "constant"=true
and there must also not be a rate rule or assignment rule for it. Furthermore, if the entity is a Species_t object, its value must not be determined by reactions, which means that it must either have the attribute "boundaryCondition"=true
or else not be involved in any reaction at all. These restrictions are explained in more detail in the SBML specification documents.
In SBML Levels 2 and 3, Reaction_t object identifiers can be referenced in the "math" expression of an algebraic rule, but reaction rates can never be determined by algebraic rules. This is true even when a reaction does not contain a KineticLaw_t structure. (In such cases of missing kinetic law definitions, the model is valid but incomplete; the rates of reactions lacking kinetic laws are simply undefined, and not determined by the algebraic rule.)
In SBML Level 2 and Level 3 Version 1, the "math" subelement of the AlgebraicRule_t is required. In SBML Level 3 Version 2, this rule is relaxed, and the subelement is optional. If an AlgebraicRule_t with no "math" child is present in the model, no additional mathematical constraints on the model are added by the rule. This may represent a situation where the model itself is unfinished, or the missing information may be provided by an SBML Level 3 package.
Finally, any symbol that appears as the target of a rateOf csymbol (AST_FUNCTION_RATE_OF, introduced in SBML Level 3 Version 2) may not be determined by an AlgebraicRule_t. This is because the rateOf csymbol is defined as applying only to symbols whose rates of change are easily determinable.
Users should note that these rules about what symbols may not be determined by an AlgebraicRule_t may be used to discover what symbol is being determined by an AlgebraicRule_t. If three symbols appear in the math element of an AlgebraicRule_t, the first of which is flagged constant=true
, and the second of which appears as the target of a rateOf csymbol, one may conclude that the AlgebraicRule_t must be used to determine the value of the third symbol. This is, in fact, a principle use (outside of validation) of the constant attribute: its use in allowing software to properly identify the dependent variable in an AlgebraicRule_t.
In SBML Level 3 as well as Level 2, rules are separated into three subclasses for the benefit of model analysis software. The three subclasses are based on the following three different possible functional forms (where x is a variable, f is some arbitrary function returning a numerical result, V is a vector of variables that does not include x, and W is a vector of variables that may include x):
Algebraic: | left-hand side is zero | 0 = f(W) |
Assignment: | left-hand side is a scalar: | x = f(V) |
Rate: | left-hand side is a rate-of-change: | dx/dt = f(W) |
In their general form given above, there is little to distinguish between assignment and algebraic rules. They are treated as separate cases for the following reasons:
The approach taken to covering these cases in SBML is to define an abstract Rule_t structure containing a subelement, "math", to hold the right-hand side expression, then to derive subtypes of Rule_t that add attributes to distinguish the cases of algebraic, assignment and rate rules. The "math" subelement must contain a MathML expression defining the mathematical formula of the rule. This MathML formula must return a numerical value. The formula can be an arbitrary expression referencing the variables and other entities in an SBML model.
Each of the three subclasses of Rule_t (AssignmentRule_t, AlgebraicRule_t, RateRule_t) inherit the the "math" subelement and other fields from SBase_t. The AssignmentRule_t and RateRule_t classes add an additional attribute, "variable". See the definitions of AssignmentRule_t, AlgebraicRule_t and RateRule_t for details about the structure and interpretation of each one.
An important design goal of SBML rule semantics is to ensure that a model's simulation and analysis results will not be dependent on when or how often rules are evaluated. To achieve this, SBML needs to place two restrictions on rule use. The first concerns algebraic loops in the system of assignments in a model, and the second concerns overdetermined systems.
The combined set of InitialAssignment_t, AssignmentRule_t and KineticLaw_t objects in a model constitute a set of assignment statements that should be considered as a whole. (A KineticLaw_t object is counted as an assignment because it assigns a value to the symbol contained in the "id" attribute of the Reaction_t object in which it is defined.) This combined set of assignment statements must not contain algebraic loops—dependency chains between these statements must terminate. To put this more formally, consider a directed graph in which nodes are assignment statements and directed arcs exist for each occurrence of an SBML species, compartment or parameter symbol in an assignment statement's "math" subelement. Let the directed arcs point from the statement assigning the symbol to the statements that contain the symbol in their "math" subelement expressions. This graph must be acyclic.
Similarly, the combined set of RateRule_t and Reaction_t objects constitute a set of definitions for the rates of change of various model entities (namely, the objects identified by the values of the 'variable' attributes of the RateRule_t objects, and the 'species' attributes of the SpeciesReference_t objects in each Reaction_t). In SBML Level 3 Version 2, these rates of change may be referenced directly using the rateOf csymbol, but may not thereby contain algebraic loops—dependency chains between these statements must terminate. More formally, consider a directed graph in which the nodes are the definitions of different variables' rates of change, and directed arcs exist for each occurrence of a variable referenced by a rateOf csymbol from any RateRule_t or KineticLaw_t object in the model. Let the directed arcs point from the variable referenced by the rateOf csymbol (call it x) to the variable(s) determined by the 'math' expression in which x appears. This graph must be acyclic.
SBML does not specify when or how often rules should be evaluated. Eliminating algebraic loops ensures that assignment statements can be evaluated any number of times without the result of those evaluations changing. As an example, consider the set of equations x = x + 1, y = z + 200 and z = y + 100. If this set of equations were interpreted as a set of assignment statements, it would be invalid because the rule for x refers to x (exhibiting one type of loop), and the rule for y refers to z while the rule for z refers back to y (exhibiting another type of loop). Conversely, the following set of equations would constitute a valid set of assignment statements: x = 10, y = z + 200, and z = x + 100.
An SBML model must not be overdetermined; that is, a model must not define more equations than there are unknowns in a model. A valid SBML model that does not contain AlgebraicRule_t structures cannot be overdetermined.
LibSBML implements the static analysis procedure described in Appendix B of the SBML Level 3 specification for assessing whether a model is overdetermined.
(In summary, assessing whether a given continuous, deterministic, mathematical model is overdetermined does not require dynamic analysis; it can be done by analyzing the system of equations created from the model. One approach is to construct a bipartite graph in which one set of vertices represents the variables and the other the set of vertices represents the equations. Place edges between vertices such that variables in the system are linked to the equations that determine them. For algebraic equations, there will be edges between the equation and each variable occurring in the equation. For ordinary differential equations (such as those defined by rate rules or implied by the reaction rate definitions), there will be a single edge between the equation and the variable determined by that differential equation. A mathematical model is overdetermined if the maximal matchings of the bipartite graph contain disconnected vertexes representing equations. If one maximal matching has this property, then all the maximal matchings will have this property; i.e., it is only necessary to find one maximal matching.)
SBML Level 1 uses a different scheme than SBML Level 2 and Level 3 for distinguishing rules; specifically, it uses an attribute whose value is drawn from an enumeration of 3 values. LibSBML supports this using methods that work a libSBML enumeration type, RuleType_t, whose values are listed below.
Public Member Functions | |
AlgebraicRule_t * | AlgebraicRule_clone (AlgebraicRule_t *ar) |
Creates a deep copy of the given AlgebraicRule_t structure. More... | |
AlgebraicRule_t * | AlgebraicRule_create (unsigned int level, unsigned int version) |
Creates a new AlgebraicRule_t structure using the given SBML level and version values. More... | |
AlgebraicRule_t * | AlgebraicRule_createWithNS (SBMLNamespaces_t *sbmlns) |
Creates a new AlgebraicRule_t structure using the given SBMLNamespaces_t structure, sbmlns . More... | |
void | AlgebraicRule_free (AlgebraicRule_t *ar) |
Frees the given AlgebraicRule_t structure. More... | |
const char * | AlgebraicRule_getFormula (const AlgebraicRule_t *r) |
const ASTNode_t * | AlgebraicRule_getMath (const AlgebraicRule_t *ar) |
Gets the mathematical expression of this AlgebraicRule_t structure as an ASTNode_t structure. More... | |
int | AlgebraicRule_hasRequiredAttributes (const AlgebraicRule_t *ar) |
Predicate returning 1 (true) or 0 (false) depending on whether all the required attributes of the given AlgebraicRule_t structure have been set. More... | |
int | AlgebraicRule_hasRequiredElements (const AlgebraicRule_t *ar) |
Predicate returning 1 (true) or 0 (false) depending on whether all the required sub-elements of the given AlgebraicRule_t structure have been set. More... | |
int | AlgebraicRule_isSetFormula (const AlgebraicRule_t *r) |
int | AlgebraicRule_isSetMath (const AlgebraicRule_t *ar) |
Predicate returning 1 (true) if the given AlgebraicRule_t structure's "math" is set. More... | |
int | AlgebraicRule_setFormula (AlgebraicRule_t *r, const char *formula) |
Sets the formula of this AlgebraicRule_t to a copy of string. More... | |
int | AlgebraicRule_setMath (AlgebraicRule_t *ar, const ASTNode_t *math) |
Sets the mathematical expression of the given AlgebraicRule_t structure. More... | |
AlgebraicRule_t * AlgebraicRule_clone | ( | AlgebraicRule_t * | ar | ) |
Creates a deep copy of the given AlgebraicRule_t structure.
ar | the AlgebraicRule_t structure to be copied. |
AlgebraicRule_t * AlgebraicRule_create | ( | unsigned int | level, |
unsigned int | version | ||
) |
Creates a new AlgebraicRule_t structure using the given SBML level
and version
values.
level | an unsigned int, the SBML level to assign to this AlgebraicRule_t structure. |
version | an unsigned int, the SBML version to assign to this AlgebraicRule_t structure. |
AlgebraicRule_t * AlgebraicRule_createWithNS | ( | SBMLNamespaces_t * | sbmlns | ) |
Creates a new AlgebraicRule_t structure using the given SBMLNamespaces_t structure, sbmlns
.
sbmlns | an SBMLNamespaces_t structure. |
void AlgebraicRule_free | ( | AlgebraicRule_t * | ar | ) |
Frees the given AlgebraicRule_t structure.
ar | the AlgebraicRule_t structure to be freed. |
const char * AlgebraicRule_getFormula | ( | const AlgebraicRule_t * | r | ) |
const ASTNode_t * AlgebraicRule_getMath | ( | const AlgebraicRule_t * | ar | ) |
Gets the mathematical expression of this AlgebraicRule_t structure as an ASTNode_t structure.
ar | the AlgebraicRule_t structure. |
int AlgebraicRule_hasRequiredAttributes | ( | const AlgebraicRule_t * | ar | ) |
Predicate returning 1
(true) or 0
(false) depending on whether all the required attributes of the given AlgebraicRule_t structure have been set.
ar | the AlgebraicRule_t structure to check. |
1
(true) if all the required attributes for this structure have been defined, 0
(false) otherwise. int AlgebraicRule_hasRequiredElements | ( | const AlgebraicRule_t * | ar | ) |
Predicate returning 1
(true) or 0
(false) depending on whether all the required sub-elements of the given AlgebraicRule_t structure have been set.
ar | the AlgebraicRule_t structure to check. |
1
(true) if all the required sub-elements for this structure have been defined, 0
(false) otherwise. int AlgebraicRule_isSetFormula | ( | const AlgebraicRule_t * | r | ) |
1
(true) if the formula (or equivalently the math) for this AlgebraicRule_t is set, 0
(false) otherwise. int AlgebraicRule_isSetMath | ( | const AlgebraicRule_t * | ar | ) |
Predicate returning 1
(true) if the given AlgebraicRule_t structure's "math" is set.
ar | the AlgebraicRule_t structure. |
1
(true) if the "math" of this AlgebraicRule_t structure is set, 0
(false) otherwise. int AlgebraicRule_setFormula | ( | AlgebraicRule_t * | r, |
const char * | formula | ||
) |
Sets the formula of this AlgebraicRule_t to a copy of string.
int AlgebraicRule_setMath | ( | AlgebraicRule_t * | ar, |
const ASTNode_t * | math | ||
) |
Sets the mathematical expression of the given AlgebraicRule_t structure.
ar | the AlgebraicRule_t structure. |
math | an ASTNode_t structure to be assigned as the "math" subelement of this AlgebraicRule_t. |