roadrunner  2.6.0
Fast simulator for SBML models
Public Member Functions | List of all members
rr::RoadRunnerMap Class Reference

Hash table designed for storing RoadRunner models. More...

#include <rrRoadRunnerMap.h>

Public Member Functions

 RoadRunnerMap ()=default
 Default construct a RoadRunnerMap. More...
 
 RoadRunnerMap (const std::vector< std::string > &sbmlStringsOrFiles, unsigned int numThreads)
 Instantiate a RoadRunnerMap from a. More...
 
std::vector< std::string > getKeys () const
 Returns the keys of the map in order of insertion. More...
 
std::vector< RoadRunner * > getValues () const
 return values of the map as a RoadRunnervector. More...
 
std::vector< std::pair< std::string, RoadRunner * > > getItems () const
 get items of this map as vector of std::pair<std::string, RoadRuner*> types. More...
 
void insert (std::unique_ptr< RoadRunner > roadRunner)
 Insert a. More...
 
void insert (const std::string &key, std::unique_ptr< RoadRunner > roadRunner)
 The same as the std::unique_ptr<RoadRunner> overload but with a user provided key. More...
 
void insert (const std::string &sbmlOrFile)
 insert a roadrunner model into the map using the model name as key. More...
 
void insert (const std::string &key, const std::string &sbmlOrFile)
 insert a roadrunner model into the map using a user define key. More...
 
void insert (const std::vector< std::string > &sbmlStringsOrFiles)
 Like the "insert(const std::string &sbmlOrFile);" overload, but pass in a vector of sbml file or sbml strings. More...
 
void erase (const std::string &key)
 remove an element with More...
 
ThreadSafeUnorderedMap::iterator begin ()
 map iterator More...
 
ThreadSafeUnorderedMap::const_iterator begin () const
 
ThreadSafeUnorderedMap::iterator end ()
 
ThreadSafeUnorderedMap::const_iterator end () const
 
ThreadSafeUnorderedMap::iterator find (const std::string &key)
 find item with key equal to More...
 
ThreadSafeUnorderedMap::const_iterator find (const std::string &key) const
 find item with key equal to More...
 
bool empty () const
 return true if the map is empty
 
unsigned int size () const
 returns the number of elements in the map
 
void clear ()
 empty the map so that there are 0 elements left
 
RoadRunneroperator[] (const std::string &key)
 Getter operator. More...
 
RoadRunnerat (const std::string &key)
 get borrowed reference from map for roadrunner model with key equal to More...
 
RoadRunnerat (const std::string &key) const
 
void wait_for_tasks ()
 wait for all tasks to finish before allowing program execution to continue
 
size_t count (const std::string &key)
 count the number of keys with value More...
 
void setNumThreads (unsigned int n)
 Reset the number of threads in the pool. More...
 
unsigned int getNumThreads () const
 get the number of threds in the thread_pool
 

Detailed Description

Hash table designed for storing RoadRunner models.

Expensive operations like building models are done in parallel.

Loading RoadRunner models requires expensive builds, which can be prohibitive when loading many models. RoadRunnerMap is a container for RoadRunner objects which abstracts the process of loading or simulating in parallel.

Constructor & Destructor Documentation

◆ RoadRunnerMap() [1/2]

rr::RoadRunnerMap::RoadRunnerMap ( )
default

Default construct a RoadRunnerMap.

The default number of threads is 1, which can be changed with RoadRunnerMap::setNumThreads.

◆ RoadRunnerMap() [2/2]

rr::RoadRunnerMap::RoadRunnerMap ( const std::vector< std::string > &  sbmlStringsOrFiles,
unsigned int  numThreads 
)
explicit

Instantiate a RoadRunnerMap from a.

Parameters
sbmlStringsOrFilesvector of sbml files, sbml strings or a mix thereof.
numThreadsHow many threads to use, if 1, the overhead of setting up multithreading pool is avoided.

Member Function Documentation

◆ at()

RoadRunner * rr::RoadRunnerMap::at ( const std::string &  key)

get borrowed reference from map for roadrunner model with key equal to

Parameters
key.

returned pointer is owned by the RoadRunnerMap object.

◆ begin()

ThreadSafeUnorderedMap::iterator rr::RoadRunnerMap::begin ( )

map iterator

for (auto&[modelName, rr]: rrm) {
...
}

or

for (auto& [modelName, rr] : rrm) {
actual[i] = rr->getInstanceID();
i++;
}

◆ count()

size_t rr::RoadRunnerMap::count ( const std::string &  key)

count the number of keys with value

Parameters
key.

Because there can be only 1 element with a particular key in the map, the return value of count is guarenteed to be either 0 for not found, or 1 for found.

◆ end()

ThreadSafeUnorderedMap::iterator rr::RoadRunnerMap::end ( )
for (auto it = rrm.begin(); it != rrm.end(); ++it) {
auto&[modelName, rr] = *it;
i++;
}

◆ erase()

void rr::RoadRunnerMap::erase ( const std::string &  key)

remove an element with

Parameters
keyfrom the map

◆ find() [1/2]

ThreadSafeUnorderedMap::iterator rr::RoadRunnerMap::find ( const std::string &  key)

find item with key equal to

Parameters
key.
Returns
iterator to item if found or end if not found

◆ find() [2/2]

ThreadSafeUnorderedMap::const_iterator rr::RoadRunnerMap::find ( const std::string &  key) const

find item with key equal to

Parameters
key. Const version.
Returns
iterator to item if found or end if not found

◆ getItems()

std::vector< std::pair< std::string, RoadRunner * > > rr::RoadRunnerMap::getItems ( ) const

get items of this map as vector of std::pair<std::string, RoadRuner*> types.

pointers are owned by the RoadRunnerMap – so do not delete. O(N).

◆ getKeys()

std::vector< std::string > rr::RoadRunnerMap::getKeys ( ) const

Returns the keys of the map in order of insertion.

Does a linear search over hashmap to build a vector of keys O(N).

◆ getValues()

std::vector< RoadRunner * > rr::RoadRunnerMap::getValues ( ) const

return values of the map as a RoadRunnervector.

the RoadRunner* instances are still owned by the RoadRunnerMap Linear complexity in the size of the map.

◆ insert() [1/5]

void rr::RoadRunnerMap::insert ( const std::string &  key,
const std::string &  sbmlOrFile 
)

insert a roadrunner model into the map using a user define key.

Parameters
keyThe string to use for the key to the roadrunner model you are inserting.
sbmlOrFileeither a sbml string or a valid file path to a sbml file.
See also
void insert(std::unique_ptr<RoadRunner> roadRunner);
void insert(const std::string &key, std::unique_ptr<RoadRunner> roadRunner);
void insert(const std::string &sbmlOrFile);
void insert(const std::vector<std::string> &sbmlStringsOrFiles);

◆ insert() [2/5]

void rr::RoadRunnerMap::insert ( const std::string &  key,
std::unique_ptr< RoadRunner roadRunner 
)

◆ insert() [3/5]

void rr::RoadRunnerMap::insert ( const std::string &  sbmlOrFile)

insert a roadrunner model into the map using the model name as key.

Parameters
sbmlOrFileeither a sbml string or a valid file path to a sbml file.
See also
void insert(std::unique_ptr<RoadRunner> roadRunner);
void insert(const std::string &key, std::unique_ptr<RoadRunner> roadRunner);
void insert(const std::string &key, const std::string &sbmlOrFile);
void insert(const std::vector<std::string> &sbmlStringsOrFiles);

◆ insert() [4/5]

void rr::RoadRunnerMap::insert ( const std::vector< std::string > &  sbmlStringsOrFiles)

Like the "insert(const std::string &sbmlOrFile);" overload, but pass in a vector of sbml file or sbml strings.

See also
void insert(std::unique_ptr<RoadRunner> roadRunner);
void insert(const std::string &key, std::unique_ptr<RoadRunner> roadRunner);
void insert(const std::string &sbmlOrFile);
void insert(const std::string &key, const std::string &sbmlOrFile);

◆ insert() [5/5]

void rr::RoadRunnerMap::insert ( std::unique_ptr< RoadRunner roadRunner)

Insert a.

Parameters
roadRunnerroadrunner model into the map.

The model must already be a unique pointer. The key for accessing the map will be the model name. Loading another model with the same name will overwrite the original.

See also
void insert(const std::string &key, std::unique_ptr<RoadRunner> roadRunner);
void insert(const std::string &sbmlOrFile);
void insert(const std::string &key, const std::string &sbmlOrFile);
void insert(const std::vector<std::string> &sbmlStringsOrFiles);

◆ operator[]()

RoadRunner * rr::RoadRunnerMap::operator[] ( const std::string &  key)

Getter operator.

Returns a borrowed reference to a roadruner model that is owned by the RoadRunnerMap.

◆ setNumThreads()

void rr::RoadRunnerMap::setNumThreads ( unsigned int  n)

Reset the number of threads in the pool.

  • If we are asked for more than 0 threads and we have an existing thread pool, the pool will wait for current tasks to finish before resetting the pool with the new number of threads
  • If we are asked for more than 0 threads and we do not have an existing thread pool, creates one with the requested number of threads
  • If we are asked for 0 threads and we have an existing thread pool, the thread pool is destroyed.
  • If we are asked for 0 threads and we do not have an existing thread pool, does nothing

The documentation for this class was generated from the following files: