001/* ----------------------------------------------------------------------------
002 * This file was automatically generated by SWIG (http://www.swig.org).
003 * Version 2.0.12
004 *
005 * Do not make changes to this file unless you know what you are doing--modify
006 * the SWIG interface file instead.
007 * ----------------------------------------------------------------------------- */
008
009package org.sbml.libsbml;
010
011/** 
012 *  Implementation of SBML's RateRule construct.
013 <p>
014 * The rule type {@link RateRule} is derived from the parent class {@link Rule}.  It is
015 * used to express equations that determine the rates of change of
016 * variables.  The left-hand side (the 'variable' attribute) can refer to
017 * the identifier of a species, compartment, or parameter (but not a
018 * reaction).  The entity identified must have its 'constant' attribute set
019 * to <code>false.</code>  The effects of a {@link RateRule} are in general terms the same,
020 * but differ in the precise details depending on which variable is being
021 * set:
022 <p>
023 * <ul> <li> <em>In the case of a species</em>, a {@link RateRule} sets the rate of
024 * change of the species' quantity (<em>concentration</em> or <em>amount of
025 * substance</em>) to the value determined by the formula in the 'math'
026 * subelement of the {@link RateRule} object.  The overall units of the formula in
027 * 'math' <em>should</em> (in SBML Level&nbsp;2 Version&nbsp;4 and in SBML Level&nbsp;3) or 
028 * <em>must</em> (in SBML releases prior to Level&nbsp;2 version&nbsp;4) be equal to
029 * the unit of <em>species quantity</em> divided by the model-wide unit of
030 * <em>time</em>.  <em>Restrictions</em>: There must not be both a {@link RateRule}
031 * 'variable' attribute and a {@link SpeciesReference} 'species' attribute having
032 * the same value, unless that species has its 'boundaryCondition'
033 * attribute is set to <code>true.</code>  This means a rate rule cannot be defined
034 * for a species that is created or destroyed in a reaction, unless that
035 * species is defined as a boundary condition in the model.
036 <p>
037 * <li> (For SBML Level&nbsp;3 only) <em>In the case of a species
038 * reference</em>, a {@link RateRule} sets the rate of change of the stoichiometry
039 * of the referenced reactant or product to the value determined by the
040 * formula in 'math'.  The unit associated with the value produced by the
041 * 'math' formula should be consistent with the unit 'dimensionless'
042 * divided by the model-wide unit of <em>time</em>.
043 <p>
044 * <li> <em>In the case of a compartment</em>, a {@link RateRule} sets the rate of
045 * change of the compartment's size to the value determined by the formula
046 * in the 'math' subelement of the {@link RateRule} object.  The overall units of
047 * the formula <em>should</em> (in SBML Level&nbsp;2 Version&nbsp;4 and in SBML
048 * Level&nbsp;3) or <em>must</em> (in SBML releases prior to Level&nbsp;2
049 * version&nbsp;4) be the units of the compartment's <em>size</em> divided
050 * by the model-wide unit of <em>time</em>.
051 <p>
052 * <li> <em>In the case of a parameter</em>, a {@link RateRule} sets the rate of
053 * change of the parameter's value to that determined by the formula in the
054 * 'math' subelement of the {@link RateRule} object.  The overall units of the
055 * formula <em>should</em> (in SBML Level&nbsp;2 Version&nbsp;4 and in SBML
056 * Level&nbsp;3) or <em>must</em> (in SBML releases prior to Level&nbsp;2
057 * version&nbsp;4) be the {@link Parameter} object's 'unit' attribute value divided
058 * by the model-wide unit of <em>time</em>.  </ul>
059 <p>
060 * In the context of a simulation, rate rules are in effect for simulation
061 * time <em>t</em> &lt; <em>0</em>.  Please consult the relevant SBML
062 * specification for additional information about the semantics of
063 * assignments, rules, and entity values for simulation time <em>t</em>
064 * &#8804; <em>0</em>.
065 <p>
066 * As mentioned in the description of {@link AssignmentRule}, a model must not
067 * contain more than one {@link RateRule} or {@link AssignmentRule} object having the same
068 * value of 'variable'; in other words, in the set of all assignment rules
069 * and rate rules in an SBML model, each variable appearing in the
070 * left-hand sides can only appear once.  This simply follows from the fact
071 * that an indeterminate system would result if a model contained more than
072 * one assignment rule for the same variable or both an assignment rule and
073 * a rate rule for the same variable.
074 <p>
075 * <p>
076 * <h2>General summary of SBML rules</h2>
077 <p>
078 * In SBML Level&nbsp;3 as well as Level&nbsp;2, rules are separated into three
079 * subclasses for the benefit of model analysis software.  The three
080 * subclasses are based on the following three different possible functional
081 * forms (where <em>x</em> is a variable, <em>f</em> is some arbitrary
082 * function returning a numerical result, <b><em>V</em></b> is a vector of
083 * variables that does not include <em>x</em>, and <b><em>W</em></b> is a
084 * vector of variables that may include <em>x</em>):
085 <p>
086 * <table border='0' cellpadding='0' class='centered' style='font-size: small'>
087 * <tr><td width='120px'><em>Algebraic:</em></td><td width='250px'>left-hand side is zero</td><td><em>0 = f(<b>W</b>)</em></td></tr>
088 * <tr><td><em>Assignment:</em></td><td>left-hand side is a scalar:</td><td><em>x = f(<b>V</b>)</em></td></tr>
089 * <tr><td><em>Rate:</em></td><td>left-hand side is a rate-of-change:</td><td><em>dx/dt = f(<b>W</b>)</em></td></tr>
090 * </table>
091 <p>
092 * In their general form given above, there is little to distinguish
093 * between <em>assignment</em> and <em>algebraic</em> rules.  They are treated as
094 * separate cases for the following reasons:
095 <p>
096 * <ul>
097 * <li> <em>Assignment</em> rules can simply be evaluated to calculate
098 * intermediate values for use in numerical methods.  They are statements
099 * of equality that hold at all times.  (For assignments that are only
100 * performed once, see {@link InitialAssignment}.)
101<p>
102 * <li> SBML needs to place restrictions on assignment rules, for example
103 * the restriction that assignment rules cannot contain algebraic loops.
104 <p>
105 * <li> Some simulators do not contain numerical solvers capable of solving
106 * unconstrained algebraic equations, and providing more direct forms such
107 * as assignment rules may enable those simulators to process models they
108 * could not process if the same assignments were put in the form of
109 * general algebraic equations;
110 <p>
111 * <li> Those simulators that <em>can</em> solve these algebraic equations make a
112 * distinction between the different categories listed above; and
113 <p>
114 * <li> Some specialized numerical analyses of models may only be applicable
115 * to models that do not contain <em>algebraic</em> rules.
116 *
117 * </ul> <p>
118 * The approach taken to covering these cases in SBML is to define an
119 * abstract {@link Rule} structure containing a subelement, 'math', to hold the
120 * right-hand side expression, then to derive subtypes of {@link Rule} that add
121 * attributes to distinguish the cases of algebraic, assignment and rate
122 * rules.  The 'math' subelement must contain a MathML expression defining the
123 * mathematical formula of the rule.  This MathML formula must return a
124 * numerical value.  The formula can be an arbitrary expression referencing
125 * the variables and other entities in an SBML model.
126 <p>
127 * Each of the three subclasses of {@link Rule} (AssignmentRule, {@link AlgebraicRule},
128 * {@link RateRule}) inherit the the 'math' subelement and other fields from {@link SBase}.
129 * The {@link AssignmentRule} and {@link RateRule} classes add an additional attribute,
130 * 'variable'.  See the definitions of {@link AssignmentRule}, {@link AlgebraicRule} and
131 * {@link RateRule} for details about the structure and interpretation of each one.
132 <p>
133 * <h2>Additional restrictions on SBML rules</h2>
134 <p>
135 * An important design goal of SBML rule semantics is to ensure that a
136 * model's simulation and analysis results will not be dependent on when or
137 * how often rules are evaluated.  To achieve this, SBML needs to place two
138 * restrictions on rule use.  The first concerns algebraic loops in the system
139 * of assignments in a model, and the second concerns overdetermined systems.
140 <p>
141 * <h3>A model must not contain algebraic loops</h3>
142 <p>
143 * The combined set of {@link InitialAssignment}, {@link AssignmentRule} and {@link KineticLaw}
144 * objects in a model constitute a set of assignment statements that should be
145 * considered as a whole.  (A {@link KineticLaw} object is counted as an assignment
146 * because it assigns a value to the symbol contained in the 'id' attribute of
147 * the {@link Reaction} object in which it is defined.)  This combined set of
148 * assignment statements must not contain algebraic loops&mdash;dependency
149 * chains between these statements must terminate.  To put this more formally,
150 * consider a directed graph in which nodes are assignment statements and
151 * directed arcs exist for each occurrence of an SBML species, compartment or
152 * parameter symbol in an assignment statement's 'math' subelement.  Let the
153 * directed arcs point from the statement assigning the symbol to the
154 * statements that contain the symbol in their 'math' subelement expressions.
155 * This graph must be acyclic.
156 <p>
157 * SBML does not specify when or how often rules should be evaluated.
158 * Eliminating algebraic loops ensures that assignment statements can be
159 * evaluated any number of times without the result of those evaluations
160 * changing.  As an example, consider the set of equations <em>x = x + 1</em>,
161 * <em>y = z + 200</em> and <em>z = y + 100</em>.  If this set of equations
162 * were interpreted as a set of assignment statements, it would be invalid
163 * because the rule for <em>x</em> refers to <em>x</em> (exhibiting one type
164 * of loop), and the rule for <em>y</em> refers to <em>z</em> while the rule
165 * for <em>z</em> refers back to <em>y</em> (exhibiting another type of loop).
166 * Conversely, the following set of equations would constitute a valid set of
167 * assignment statements: <em>x = 10</em>, <em>y = z + 200</em>, and <em>z = x
168 * + 100</em>.
169 <p>
170 * <h3>A model must not be overdetermined</h3>
171 <p>
172 * An SBML model must not be overdetermined; that is, a model must not
173 * define more equations than there are unknowns in a model.  An SBML model
174 * that does not contain {@link AlgebraicRule} structures cannot be overdetermined.
175 <p>
176 * LibSBML implements the static analysis procedure described in
177 * Appendix&nbsp;B of the SBML Level&nbsp;3 Version&nbsp;1 Core
178 * specification for assessing whether a model is overdetermined.
179 <p>
180 * (In summary, assessing whether a given continuous, deterministic,
181 * mathematical model is overdetermined does not require dynamic analysis; it
182 * can be done by analyzing the system of equations created from the model.
183 * One approach is to construct a bipartite graph in which one set of vertices
184 * represents the variables and the other the set of vertices represents the
185 * equations.  Place edges between vertices such that variables in the system
186 * are linked to the equations that determine them.  For algebraic equations,
187 * there will be edges between the equation and each variable occurring in the
188 * equation.  For ordinary differential equations (such as those defined by
189 * rate rules or implied by the reaction rate definitions), there will be a
190 * single edge between the equation and the variable determined by that
191 * differential equation.  A mathematical model is overdetermined if the
192 * maximal matchings of the bipartite graph contain disconnected vertexes
193 * representing equations.  If one maximal matching has this property, then
194 * all the maximal matchings will have this property; i.e., it is only
195 * necessary to find one maximal matching.)
196 <p>
197 * <h2>Rule types for SBML Level 1</h2>
198 <p>
199 * SBML Level 1 uses a different scheme than SBML Level 2 and Level 3 for
200 * distinguishing rules; specifically, it uses an attribute whose value is
201 * drawn from an enumeration of 3 values.  LibSBML supports this using methods
202 * that work with the enumeration values  listed below.
203 <p>
204 * <ul>
205 * <li> {@link  libsbmlConstants#RULE_TYPE_RATE RULE_TYPE_RATE}: Indicates
206 * the rule is a 'rate' rule.
207 * <li> {@link  libsbmlConstants#RULE_TYPE_SCALAR RULE_TYPE_SCALAR}:
208 * Indicates the rule is a 'scalar' rule.
209 * <li> {@link  libsbmlConstants#RULE_TYPE_INVALID RULE_TYPE_INVALID}:
210 * Indicates the rule type is unknown or not yet set.
211 *
212 * </ul>
213 */
214
215public class RateRule extends Rule {
216   private long swigCPtr;
217
218   protected RateRule(long cPtr, boolean cMemoryOwn)
219   {
220     super(libsbmlJNI.RateRule_SWIGUpcast(cPtr), cMemoryOwn);
221     swigCPtr = cPtr;
222   }
223
224   protected static long getCPtr(RateRule obj)
225   {
226     return (obj == null) ? 0 : obj.swigCPtr;
227   }
228
229   protected static long getCPtrAndDisown (RateRule obj)
230   {
231     long ptr = 0;
232
233     if (obj != null)
234     {
235       ptr             = obj.swigCPtr;
236       obj.swigCMemOwn = false;
237     }
238
239     return ptr;
240   }
241
242  protected void finalize() {
243    delete();
244  }
245
246  public synchronized void delete() {
247    if (swigCPtr != 0) {
248      if (swigCMemOwn) {
249        swigCMemOwn = false;
250        libsbmlJNI.delete_RateRule(swigCPtr);
251      }
252      swigCPtr = 0;
253    }
254    super.delete();
255  }
256
257  
258/**
259   * Creates a new {@link RateRule} using the given SBML <code>level</code> and <code>version</code>
260   * values.
261   <p>
262   * @param level a long integer, the SBML Level to assign to this {@link RateRule}
263   <p>
264   * @param version a long integer, the SBML Version to assign to this
265   * {@link RateRule}
266   <p>
267   * @throws SBMLConstructorException 
268   * Thrown if the given <code>level</code> and <code>version</code> combination, or this kind
269   * of SBML object, are either invalid or mismatched with respect to the
270   * parent {@link SBMLDocument} object.
271   <p>
272   * <p>
273 * @note Upon the addition of an {@link RateRule} object to an {@link SBMLDocument}
274 * (e.g., using {@link Model#addRule(Rule r)}), the SBML Level, SBML
275 * Version and XML namespace of the document <em>override</em> the values used
276 * when creating the {@link RateRule} object via the {@link RateRule} constructors.
277 * This is necessary to ensure that an SBML document has a consistent overall
278 * structure.  Nevertheless, the ability to supply the values at the time of
279 * creation of a {@link RateRule} is an important aid to producing valid SBML.
280 * Knowledge of the intented SBML Level and Version determine whether it is
281 * valid to assign a particular value to an attribute, or whether it is valid
282 * to add an object to an existing {@link SBMLDocument}.
283   */ public
284 RateRule(long level, long version) throws org.sbml.libsbml.SBMLConstructorException {
285    this(libsbmlJNI.new_RateRule__SWIG_0(level, version), true);
286  }
287
288  
289/**
290   * Creates a new {@link RateRule} using the given {@link SBMLNamespaces} object
291   * <code>sbmlns</code>.
292   <p>
293   * <p>
294 * The {@link SBMLNamespaces} object encapsulates SBML Level/Version/namespaces
295 * information.  It is used to communicate the SBML Level, Version, and (in
296 * Level&nbsp;3) packages used in addition to SBML Level&nbsp;3 Core.  A
297 * common approach to using libSBML's {@link SBMLNamespaces} facilities is to create an
298 * {@link SBMLNamespaces} object somewhere in a program once, then hand that object
299 * as needed to object constructors that accept {@link SBMLNamespaces} as arguments. 
300   <p>
301   * @param sbmlns an {@link SBMLNamespaces} object.
302   <p>
303   * @throws SBMLConstructorException 
304   * Thrown if the given <code>level</code> and <code>version</code> combination, or this kind
305   * of SBML object, are either invalid or mismatched with respect to the
306   * parent {@link SBMLDocument} object.
307   <p>
308   * <p>
309 * @note Upon the addition of an {@link RateRule} object to an {@link SBMLDocument}
310 * (e.g., using {@link Model#addRule(Rule r)}), the SBML Level, SBML
311 * Version and XML namespace of the document <em>override</em> the values used
312 * when creating the {@link RateRule} object via the {@link RateRule} constructors.
313 * This is necessary to ensure that an SBML document has a consistent overall
314 * structure.  Nevertheless, the ability to supply the values at the time of
315 * creation of a {@link RateRule} is an important aid to producing valid SBML.
316 * Knowledge of the intented SBML Level and Version determine whether it is
317 * valid to assign a particular value to an attribute, or whether it is valid
318 * to add an object to an existing {@link SBMLDocument}.
319   */ public
320 RateRule(SBMLNamespaces sbmlns) throws org.sbml.libsbml.SBMLConstructorException {
321    this(libsbmlJNI.new_RateRule__SWIG_1(SBMLNamespaces.getCPtr(sbmlns), sbmlns), true);
322  }
323
324  
325/**
326   * Creates and returns a deep copy of this {@link Rule}.
327   <p>
328   * @return a (deep) copy of this {@link Rule}.
329   */ public
330 RateRule cloneObject() {
331    long cPtr = libsbmlJNI.RateRule_cloneObject(swigCPtr, this);
332    return (cPtr == 0) ? null : new RateRule(cPtr, true);
333  }
334
335  
336/**
337   * Predicate returning <code>true</code> if
338   * all the required attributes for this {@link RateRule} object
339   * have been set.
340   <p>
341   * @note In SBML Levels&nbsp;2&ndash;3, the only required attribute for a
342   * {@link RateRule} object is 'variable'.  For Level&nbsp;1, where the equivalent
343   * attribute is known by different names ('compartment', 'species', or
344   * 'name', depending on the type of object), there is an additional
345   * required attribute called 'formula'.
346   <p>
347   * @return <code>true</code> if the required attributes have been set, <code>false</code>
348   * otherwise.
349   */ public
350 boolean hasRequiredAttributes() {
351    return libsbmlJNI.RateRule_hasRequiredAttributes(swigCPtr, this);
352  }
353
354  
355/**
356   * Renames all the <code>SIdRef</code> attributes on this element, including any
357   * found in MathML.
358   <p>
359   * <p>
360 * In SBML, object identifiers are of a data type called <code>SId</code>.
361 * In SBML Level&nbsp;3, an explicit data type called <code>SIdRef</code> was
362 * introduced for attribute values that refer to <code>SId</code> values; in
363 * previous Levels of SBML, this data type did not exist and attributes were
364 * simply described to as 'referring to an identifier', but the effective
365 * data type was the same as <code>SIdRef</code>in Level&nbsp;3.  These and
366 * other methods of libSBML refer to the type <code>SIdRef</code> for all
367 * Levels of SBML, even if the corresponding SBML specification did not
368 * explicitly name the data type.
369   <p>
370   * This method works by looking at all attributes and (if appropriate)
371   * mathematical formulas, comparing the identifiers to the value of 
372   * <code>oldid</code>.  If any matches are found, the matching identifiers are replaced
373   * with <code>newid</code>.  The method does <em>not</em> descend into child elements.
374   <p>
375   * @param oldid the old identifier
376   * @param newid the new identifier
377   */ public
378 void renameSIdRefs(String oldid, String newid) {
379    libsbmlJNI.RateRule_renameSIdRefs(swigCPtr, this, oldid, newid);
380  }
381
382}