roadrunner  2.6.0
Fast simulator for SBML models
rrExecutableModel.h
Go to the documentation of this file.
1 
2 // == PREAMBLE ================================================
3 
4 // * Licensed under the Apache License, Version 2.0; see README
5 
6 // == FILEDOC =================================================
7 
14 # ifndef rrExecutableModelH
15 # define rrExecutableModelH
16 
17 // == INCLUDES ================================================
18 
19 #include "rrOSSpecifics.h"
20 #include "rrException.h"
21 #include "sbml/SBMLDocument.h"
22 
23 #include <stdint.h>
24 #include <string>
25 #include <vector>
26 #include <list>
27 #include <ostream>
28 
29 
30 #include "tr1proxy/rr_memory.h"
31 
32 // == CODE ====================================================
33 
34 namespace rr {
35 
36  class ExecutableModel;
37 
54  class EventListener {
55  public:
56  enum Result {
57  HALT_SIMULATION = (0x1 << 0), // => 0x00000001
58  };
59  virtual uint onTrigger(ExecutableModel *model, size_t eventIndex, const std::string &eventId) = 0;
60 
61  virtual uint onAssignment(ExecutableModel *model, size_t eventIndex, const std::string &eventId) = 0;
62 
63  protected:
64  ~EventListener() {};
65  };
66 
71  typedef cxx11_ns::shared_ptr<EventListener> EventListenerPtr;
72 
73  class EventListenerException : public std::exception {
74  public:
75  explicit EventListenerException(uint resultCode) :
76  resultCode(resultCode) {
77  msg = "EventHandlerException, resultCode: ";
78 
79  switch (resultCode) {
80  case EventListener::HALT_SIMULATION:
81  msg += "HALT_SIMULATION";
82  break;
83  }
84  }
85 
86  virtual ~EventListenerException() throw() {
87  };
88 
89  virtual const char *what() const throw() {
90  return msg.c_str();
91  }
92 
93  uint getResultCode() const {
94  return resultCode;
95  }
96 
97  private:
98  uint resultCode;
99  std::string msg;
100  };
101 
102 
118  class RR_DECLSPEC ExecutableModel {
119  public:
126  ExecutableModel();
127 
128  virtual std::string getExecutableModelDesc() const = 0;
129 
133  virtual std::string getModelName() = 0;
134 
135  virtual void setTime(double _time) = 0;
136 
137  virtual double getTime() = 0;
138 
139 
145  virtual void reset() = 0;
146 
147 
148 
149 
150 
151 
157  virtual int getNumDepFloatingSpecies() = 0;
158 
162  virtual int getNumFloatingSpecies() = 0;
163 
164  virtual int getFloatingSpeciesIndex(const std::string &eid) = 0;
165 
166  virtual std::string getFloatingSpeciesId(size_t index) = 0;
167 
172  virtual int getNumIndFloatingSpecies() = 0;
173 
182  virtual int getFloatingSpeciesAmounts(size_t len, int const *indx,
183  double *values) = 0;
184 
185  /*
186  * Set the floating species amounts.
187  *
188  * @param[in] len the length of the indx and values arrays.
189  * @param[in] indx an array of length len of floating species.
190  * @param[in] values an array of at least length len which store the
191  * floating species amounts.
192  */
193  virtual int setFloatingSpeciesAmounts(size_t len, int const *indx,
194  const double *values) = 0;
195 
196  /*
197  * Set the floating species amounts.
198  *
199  * @param[in] len the length of the indx and values arrays.
200  * @param[in] indx an array of length len of floating species.
201  * @param[in] values an array of at least length len which store the
202  * floating species amounts.
203  * @param[in] strict whether to throw if the value cannot be set.
204  */
205  virtual int setFloatingSpeciesAmounts(size_t len, int const* indx,
206  const double* values, bool strict) = 0;
207 
216  virtual int getFloatingSpeciesAmountRates(size_t len, int const *indx,
217  double *values) = 0;
218 
219 
228  virtual int getFloatingSpeciesConcentrationRates(size_t len, int const *indx,
229  double *values) = 0;
230 
239  virtual int getFloatingSpeciesConcentrations(size_t len, int const *indx,
240  double *values) = 0;
241 
250  virtual int setFloatingSpeciesConcentrations(size_t len, int const *indx,
251  double const *values) = 0;
252 
263  virtual int setFloatingSpeciesInitConcentrations(size_t len, int const *indx,
264  double const *values) = 0;
265 
270  virtual int getFloatingSpeciesInitConcentrations(size_t len, int const *indx,
271  double *values) = 0;
272 
283  virtual int setFloatingSpeciesInitAmounts(size_t len, int const *indx,
284  double const *values) = 0;
285 
290  virtual int getFloatingSpeciesInitAmounts(size_t len, int const *indx,
291  double *values) = 0;
292 
293 
294 
295 
299 
300 
301 
307  virtual int getNumBoundarySpecies() = 0;
308 
309  virtual int getBoundarySpeciesIndex(const std::string &eid) = 0;
310 
311  virtual std::string getBoundarySpeciesId(size_t index) = 0;
312 
321  virtual int getBoundarySpeciesAmounts(size_t len, int const *indx,
322  double *values) = 0;
323 
324 
333  virtual int getBoundarySpeciesConcentrations(size_t len, int const *indx,
334  double *values) = 0;
335 
344  virtual int setBoundarySpeciesConcentrations(size_t len, int const *indx,
345  double const *values) = 0;
346 
347  /*
348  * Set the boundary species amounts.
349  *
350  * @param[in] len the length of the indx and values arrays.
351  * @param[in] indx an array of length len of boundary species.
352  * @param[in] values an array of at least length len which store the
353  * boundary species amounts.
354  */
355  virtual int setBoundarySpeciesAmounts(size_t len, int const* indx,
356  double const* values) = 0;
357 
358  /*
359  * Set the boundary species amounts.
360  *
361  * @param[in] len the length of the indx and values arrays.
362  * @param[in] indx an array of length len of boundary species.
363  * @param[in] values an array of at least length len which store the
364  * boundary species amounts.
365  * @param[in] strict whether to throw if the value cannot be set.
366  */
367  virtual int setBoundarySpeciesAmounts(size_t len, int const* indx,
368  double const* values, bool strict) = 0;
369 
380  virtual int setBoundarySpeciesInitConcentrations(size_t len, int const* indx,
381  double const* values) = 0;
382 
387  virtual int getBoundarySpeciesInitConcentrations(size_t len, int const* indx,
388  double* values) = 0;
389 
400  virtual int setBoundarySpeciesInitAmounts(size_t len, int const* indx,
401  double const* values) = 0;
402 
407  virtual int getBoundarySpeciesInitAmounts(size_t len, int const* indx,
408  double* values) = 0;
409 
410 
411 
412 
413 
416 
417 
418 
423  virtual int getNumGlobalParameters() = 0;
424 
428  virtual int getGlobalParameterIndex(const std::string &eid) = 0;
429 
433  virtual std::string getGlobalParameterId(size_t index) = 0;
434 
443  virtual int getGlobalParameterValues(size_t len, int const *indx,
444  double *values) = 0;
445 
446  /*
447  * Set the global parameter values.
448  *
449  * @param[in] len the length of the indx and values arrays.
450  * @param[in] indx an array of length len of parameters.
451  * @param[in] values an array of at least length len which store the
452  * parameter values.
453  */
454  virtual int setGlobalParameterValues(size_t len, int const *indx,
455  const double *values) = 0;
456 
457  /*
458  * Set the global parameter values.
459  *
460  * @param[in] len the length of the indx and values arrays.
461  * @param[in] indx an array of length len of parameters.
462  * @param[in] values an array of at least length len which store the
463  * parameter values.
464  * @param[in] strict whether to throw if the value cannot be set.
465  */
466  virtual int setGlobalParameterValues(size_t len, int const* indx,
467  const double* values, bool strict) = 0;
468 
474  virtual int setGlobalParameterInitValues(size_t len, int const *indx,
475  double const *values) = 0;
476 
481  virtual int getGlobalParameterInitValues(size_t len, int const *indx,
482  double *values) = 0;
483 
484 
485 
486 
487 
490 
491 
493 
495  virtual int getNumCompartments() = 0;
496 
497  virtual int getCompartmentIndexForFloatingSpecies(size_t index) = 0;
498 
499  virtual int getCompartmentIndexForBoundarySpecies(size_t index) = 0;
500 
501  virtual int getCompartmentIndex(const std::string &eid) = 0;
502 
503  virtual std::string getCompartmentId(size_t index) = 0;
504 
513  virtual int getCompartmentVolumes(size_t len, int const *indx,
514  double *values) = 0;
515 
516  /*
517  * Set the compartment volumes.
518  *
519  * @param[in] len the length of the indx and values arrays.
520  * @param[in] indx an array of length len of compartments.
521  * @param[in] values an array of at least length len which store the
522  * compartment values.
523  */
524  virtual int setCompartmentVolumes(size_t len, int const *indx,
525  const double *values) = 0;
526 
527  /*
528  * Set the compartment volumes.
529  *
530  * @param[in] len the length of the indx and values arrays.
531  * @param[in] indx an array of length len of compartments.
532  * @param[in] values an array of at least length len which store the
533  * compartment values.
534  * @param[in] strict whether to throw if the value cannot be set.
535  */
536  virtual int setCompartmentVolumes(size_t len, int const* indx,
537  const double* values, bool strict) = 0;
538 
549  virtual int setCompartmentInitVolumes(size_t len, int const *indx,
550  double const *values) = 0;
551 
556  virtual int getCompartmentInitVolumes(size_t len, int const *indx,
557  double *values) = 0;
558 
559 
560 
561 
562 
565 
566 
567 
577  virtual void getIds(int types, std::list<std::string> &ids) = 0;
578 
582  virtual int getSupportedIdTypes() = 0;
583 
588  virtual double getValue(const std::string &id) = 0;
589 
593  virtual void setValue(const std::string &id, double value) = 0;
594 
595 
596 
597 
598 
600  /*
601  * Set stoichiometries.
602  *
603  * @param[in] len the length of the indx and values arrays.
604  * @param[in] indx an array of length len of stoichiometries.
605  * @param[in] values an array of at least length len which store the
606  * stoichiometries.
607  */
608  virtual int setStoichiometries(size_t len, int const *indx,
609  const double *values) = 0;
610 
611  /*
612  * Set the stoichiometries.
613  *
614  * @param[in] len the length of the indx and values arrays.
615  * @param[in] indx an array of length len of stoichiometries.
616  * @param[in] values an array of at least length len which store the
617  * stoichiometries.
618  * @param[in] strict whether to throw if the value cannot be set.
619  */
620  virtual int setStoichiometries(size_t len, int const* indx,
621  const double* values, bool strict) = 0;
622 
623  /*
624  * Set the setStoichiometry.
625  *
626  * @param[in] index the index of the stoichiometry.
627  * @param[in] value of stoichiometry to be set.
628  */
629  virtual int setStoichiometry(int index, double value) = 0;
630 
631  /*
632  * Set the setStoichiometry.
633  *
634  * @param[in] the speciesIndex of stoichiometry.
635  * @param[in] the reactionIndex of stoichiometry.
636  * @param[in] value of stoichiometry to be set.
637  */
638  virtual int setStoichiometry(int speciesIndex, int reactionIndex, double value) = 0;
639 
645  virtual double getStoichiometry(int index) = 0;
646 
652  virtual double getStoichiometry(int speciesIndex, int reactionIndex) = 0;
653 
654 
655  virtual int getNumConservedMoieties() = 0;
656 
657  virtual int getConservedMoietyIndex(const std::string &eid) = 0;
658 
659  virtual std::string getConservedMoietyId(size_t index) = 0;
660 
661  virtual int getConservedMoietyValues(size_t len, int const *indx, double *values) = 0;
662 
663  virtual int setConservedMoietyValues(size_t len, int const *indx,
664  const double *values) = 0;
665 
666  virtual int getNumRateRules() = 0;
667 
674  virtual std::vector<std::string> getRateRuleSymbols() const = 0;
675 
676 
680  virtual int getNumReactions() = 0;
681 
686  virtual int getReactionIndex(const std::string &eid) = 0;
687 
691  virtual std::string getReactionId(size_t index) = 0;
692 
697  virtual int getStoichiometryIndex(const std::string&) = 0;
698 
703  virtual int getStoichiometryIndex(const std::string&, const std::string&) = 0;
704 
708  virtual std::string getStoichiometryId(size_t index) = 0 ;
709 
718  virtual int getReactionRates(size_t len, int const *indx,
719  double *values) = 0;
720 
728  virtual void getRateRuleValues(double *rateRuleValues) = 0;
729 
739  virtual int getRateRuleRates(size_t len, int const* indx, double* values);
740 
744  virtual std::string getStateVectorId(size_t index) = 0;
745 
762  virtual int getStateVector(double *stateVector) = 0;
763 
773  virtual int setStateVector(const double *stateVector) = 0;
774 
791  virtual void getStateVectorRate(double time, const double *y, double *dydt = 0) = 0;
792 
793  virtual void testConstraints() = 0;
794 
795  virtual std::string getInfo() = 0;
796 
797  virtual void print(std::ostream &stream) = 0;
798 
799 
800 
802 
804  virtual int getNumEvents() = 0;
805 
817  virtual int getEventTriggers(size_t len, const int *indx, unsigned char *values) = 0;
818 
819 
832  virtual int applyEvents(double timeEnd, const unsigned char *previousEventStatus,
833  const double *initialState, double *finalState) = 0;
834 
835 
847  virtual void getEventRoots(double time, const double *y, double *gdot) = 0;
848 
849  virtual void getPiecewiseTriggerRoots(double time, const double* y, double* gdot) = 0;
850 
851  virtual double getNextPendingEventTime(bool pop) = 0;
852 
853  virtual int getPendingEventSize() = 0;
854 
855  virtual void resetEvents() = 0;
856 
860  virtual int getNumPiecewiseTriggers() = 0;
861 
862 
863 
870  virtual ~ExecutableModel() {};
871 
872 
873 
874 
881  virtual int getEventIndex(const std::string &eid) = 0;
882 
883  virtual std::string getEventId(size_t index) = 0;
884 
885  virtual void getEventIds(std::list<std::string>&) = 0;
886 
887  virtual void getAssignmentRuleIds(std::list<std::string>&) = 0;
888 
889  virtual void getRateRuleIds(std::list<std::string>&) = 0;
890 
891  virtual void getInitialAssignmentIds(std::list<std::string>&) = 0;
892 
893  virtual void setEventListener(size_t index, EventListenerPtr eventHandler) = 0;
894 
895  virtual EventListenerPtr getEventListener(size_t index) = 0;
896 
910  virtual double getFloatingSpeciesAmountRate(size_t index,
911  const double *reactionRates) = 0;
912 
917  virtual void reset(int options) = 0;
918 
923  virtual void setRandomSeed(int64_t) = 0;
924 
928  virtual int64_t getRandomSeed() = 0;
929 
936  virtual double getRandom() = 0;
937 
941  virtual uint32_t getFlags() const = 0;
942 
947  virtual void setFlags(uint32_t) = 0;
948 
955  INTEGRATION = (0x1 << 0), // => 0x00000001
956 
960  OPTIMIZE_REACTION_RATE_SELECTION = (0x1 << 1), // => 0x00000010
961  };
962 
967 
968  /*
969  * Writes "Saving state not implemented for this model type" to out if not implemented for the underlying
970  * model type
971  */
972  virtual void saveState(std::ostream &out) {
973  out << "Saving state not implemented for this model type";
974  }
975 
976  virtual void setIntegrationStartTime(double time);
977 
978  friend class RoadRunner;
979 
980  protected:
981 
982  double mIntegrationStartTime;
983 
987  void setIntegration(bool value) {
988  uint32_t flags = getFlags();
989  if (value) {
990  flags |= INTEGRATION;
991  } else {
992  flags &= ~INTEGRATION;
993  }
994  setFlags(flags);
995  }
996 
997 
998  };
999 
1000 
1001 
1002 
1006  RR_DECLSPEC std::ostream &operator<<(std::ostream &stream, ExecutableModel *model);
1007 }
1008 #endif // rrExecutableModelH
Definition: rrExecutableModel.h:73
Notifies the user of SBML events.
Definition: rrExecutableModel.h:54
Base class for all code generation systems; allows compiling and evaluating the model.
Definition: rrExecutableModel.h:118
virtual void getStateVectorRate(double time, const double *y, double *dydt=0)=0
the state std::vector y is the rate rule values and floating species concentrations concatenated.
ExecutableModelFlags
Definition: rrExecutableModel.h:949
virtual void getIds(int types, std::list< std::string > &ids)=0
populates a given list with all the ids that this class can accept.
virtual int getBoundarySpeciesConcentrations(size_t len, int const *indx, double *values)=0
get the boundary species concentrations
virtual int setBoundarySpeciesConcentrations(size_t len, int const *indx, double const *values)=0
set the boundary species concentrations
virtual double getRandom()=0
Get a uniform random number between 0 and 1 created by the RNG.
virtual int getSupportedIdTypes()=0
returns a bit field of the ids that this class supports.
virtual int getFloatingSpeciesInitAmounts(size_t len, int const *indx, double *values)=0
Get the initial amounts of the floating species, uses the same indexing as the other floating species...
virtual void reset()=0
Loads the initial conditions into the current model state.
virtual double getStoichiometry(int index)=0
Get the current stiochiometry value with the given index.
virtual int setFloatingSpeciesInitConcentrations(size_t len, int const *indx, double const *values)=0
Set the initial concentrations of the floating species.
virtual int getNumDepFloatingSpecies()=0
dependent species are defined by rules and the only way to change them is by changing the values on w...
virtual void getEventRoots(double time, const double *y, double *gdot)=0
evaluate the event 'roots' – when events transition form triggered - non-triggered or triggered to no...
virtual std::string getStoichiometryId(size_t index)=0
get the name of the specified stoichiometry
virtual int setBoundarySpeciesInitConcentrations(size_t len, int const *indx, double const *values)=0
Set the initial concentrations of the boundary species.
virtual int getStoichiometryIndex(const std::string &)=0
get the index of a named stoichiometry
virtual void setFlags(uint32_t)=0
Set certain options that determine the state of the ExecutableModel, these are listed in.
virtual int getReactionRates(size_t len, int const *indx, double *values)=0
get the std::vector of reaction rates.
virtual int getStoichiometryIndex(const std::string &, const std::string &)=0
get the index of a named stoichiometry
virtual double getFloatingSpeciesAmountRate(size_t index, const double *reactionRates)=0
Get the amount rate of change for the i'th floating species given a reaction rates std::vector.
virtual int setStateVector(const double *stateVector)=0
sets the internal model state to the provided packed state std::vector.
virtual int getEventTriggers(size_t len, const int *indx, unsigned char *values)=0
get the event status, false if the even is not triggered, true if it is.
virtual int getFloatingSpeciesInitConcentrations(size_t len, int const *indx, double *values)=0
Get the initial concentrations of the floating species, uses the same indexing as the other floating ...
virtual std::string getModelName()=0
get the name of the model
virtual int getNumBoundarySpecies()=0
get the number of boundary species.
virtual int setGlobalParameterInitValues(size_t len, int const *indx, double const *values)=0
Set the initial value of the global parameter.
virtual std::string getGlobalParameterId(size_t index)=0
id of the indexed global parameter.
virtual int getStateVector(double *stateVector)=0
The state std::vector is a std::vector of elements that are defined by differential equations (rate r...
virtual int64_t getRandomSeed()=0
get the seed used by the RNG.
virtual int setBoundarySpeciesInitAmounts(size_t len, int const *indx, double const *values)=0
Set the initial amounts of the boundary species.
virtual ~ExecutableModel()
need a virtual destructor as object implementing this interface can be deleted directly,...
Definition: rrExecutableModel.h:870
virtual void getRateRuleValues(double *rateRuleValues)=0
get the 'values' i.e.
virtual int setCompartmentInitVolumes(size_t len, int const *indx, double const *values)=0
Set the initial volumes of the compartments.
virtual uint32_t getFlags() const =0
Get the current set of flags.
virtual int getReactionIndex(const std::string &eid)=0
get the index of a named reaction
virtual int getBoundarySpeciesAmounts(size_t len, int const *indx, double *values)=0
get the boundary species amounts
virtual int getGlobalParameterInitValues(size_t len, int const *indx, double *values)=0
Get the initial amounts of the global parameter, uses the same indexing as the other global parameter...
virtual int getCompartmentVolumes(size_t len, int const *indx, double *values)=0
get the compartment volumes
virtual std::vector< std::string > getRateRuleSymbols() const =0
Gets the symbols defined by rate rules, i.e. returns all x such that x' = f(x) is a rule which define...
virtual int getNumFloatingSpecies()=0
total number of floating species.
virtual int getNumPiecewiseTriggers()=0
We do root-finding for 'piecewise triggers': those times in a piecewise function that transition from...
virtual void setRandomSeed(int64_t)=0
set the seed used by the random number generator.
virtual int getNumGlobalParameters()=0
get the number of global parameters
virtual int getFloatingSpeciesConcentrationRates(size_t len, int const *indx, double *values)=0
get the floating species concentration rates
virtual int setFloatingSpeciesInitAmounts(size_t len, int const *indx, double const *values)=0
Set the initial amounts of the floating species.
virtual int getBoundarySpeciesInitAmounts(size_t len, int const *indx, double *values)=0
Get the initial amounts of the boundary species, uses the same indexing as the other boundary species...
virtual int getGlobalParameterIndex(const std::string &eid)=0
index of the global parameter id, -1 if it does not exist.
virtual std::string getStateVectorId(size_t index)=0
get the id of an element of the state std::vector.
virtual int getFloatingSpeciesAmounts(size_t len, int const *indx, double *values)=0
get the floating species amounts
virtual void reset(int options)=0
reset the model accordign to a bitfield specified by the SelectionRecord::SelectionType values.
virtual void setValue(const std::string &id, double value)=0
sets the value coresponding to the given selection stringl
virtual int getNumReactions()=0
get the number of reactions the model has
virtual int getNumIndFloatingSpecies()=0
independent species do are not defined by rules, they typically participate in reactions and can have...
void computeAllRatesOfChange()
for source compatability
Definition: rrExecutableModel.h:966
virtual int getFloatingSpeciesAmountRates(size_t len, int const *indx, double *values)=0
get the floating species amount rates
virtual int applyEvents(double timeEnd, const unsigned char *previousEventStatus, const double *initialState, double *finalState)=0
Itterate through all of the current and pending events and apply them.
virtual int getEventIndex(const std::string &eid)=0
Gets the index for an event id.
virtual std::string getReactionId(size_t index)=0
get the name of the specified reaction
virtual double getValue(const std::string &id)=0
gets the value for the given id std::string.
void setIntegration(bool value)
is integration is currently proceeding.
Definition: rrExecutableModel.h:987
virtual int setFloatingSpeciesConcentrations(size_t len, int const *indx, double const *values)=0
set the floating species concentrations
virtual int getBoundarySpeciesInitConcentrations(size_t len, int const *indx, double *values)=0
Get the initial concentrations of the boundary species, uses the same indexing as the other boundary ...
virtual int getGlobalParameterValues(size_t len, int const *indx, double *values)=0
get the global parameter values
virtual double getStoichiometry(int speciesIndex, int reactionIndex)=0
Get the current stiochiometry value for the given species / reaction.
virtual int getCompartmentInitVolumes(size_t len, int const *indx, double *values)=0
Get the initial volume of the compartments, uses the same indexing as the other compartment methods.
virtual int getFloatingSpeciesConcentrations(size_t len, int const *indx, double *values)=0
get the floating species concentrations
C_DECL_SPEC bool rrcCallConv saveState(RRHandle handle, const char *filename)
Save a road runner instance's state to a platform-specific binary file.
C_DECL_SPEC char *rrcCallConv getInfo(RRHandle handle)
Retrieve info about current state of roadrunner, e.g. loaded model, conservationAnalysis etc.
cxx11_ns::shared_ptr< EventListener > EventListenerPtr
listeners are shared objects, so use std smart pointers to manage them.
Definition: rrExecutableModel.h:71