Browse Source

Automaton: Retrieve location id by name

Former-commit-id: d8aa9c1ba3
tempestpy_adaptions
sjunges 9 years ago
parent
commit
7fcf598e86
  1. 10
      src/storage/jani/Automaton.cpp
  2. 10
      src/storage/jani/Automaton.h

10
src/storage/jani/Automaton.cpp

@ -39,12 +39,18 @@ namespace storm {
return locations; return locations;
} }
void Automaton::addLocation(Location const& location) {
uint64_t Automaton::addLocation(Location const& location) {
STORM_LOG_THROW(!this->hasLocation(location.getName()), storm::exceptions::WrongFormatException, "Cannot add location with name '" << location.getName() << "', because a location with this name already exists."); STORM_LOG_THROW(!this->hasLocation(location.getName()), storm::exceptions::WrongFormatException, "Cannot add location with name '" << location.getName() << "', because a location with this name already exists.");
locationToIndex.emplace(location.getName(), locations.size()); locationToIndex.emplace(location.getName(), locations.size());
locations.push_back(location); locations.push_back(location);
return locations.size() - 1;
} }
uint64_t Automaton::getLocationId(std::string const& name) const {
assert(hasLocation(name));
return locationToIndex.at(name);
}
void Automaton::setInitialLocation(std::string const& name) { void Automaton::setInitialLocation(std::string const& name) {
auto it = locationToIndex.find(name); auto it = locationToIndex.find(name);
STORM_LOG_THROW(it != locationToIndex.end(), storm::exceptions::InvalidArgumentException, "Cannot make unknown location '" << name << "' the initial location."); STORM_LOG_THROW(it != locationToIndex.end(), storm::exceptions::InvalidArgumentException, "Cannot make unknown location '" << name << "' the initial location.");

10
src/storage/jani/Automaton.h

@ -47,6 +47,14 @@ namespace storm {
* Retrieves whether the automaton has a location with the given name. * Retrieves whether the automaton has a location with the given name.
*/ */
bool hasLocation(std::string const& name) const; bool hasLocation(std::string const& name) const;
/*!
* Get location id for a location with a given name.
* Yields undefined behaviour if no such location exists;
*
* @name the name of the location
*/
uint64_t getLocationId(std::string const& name) const;
/*! /*!
* Retrieves the locations of the automaton. * Retrieves the locations of the automaton.
@ -56,7 +64,7 @@ namespace storm {
/*! /*!
* Adds the given location to the automaton. * Adds the given location to the automaton.
*/ */
void addLocation(Location const& location);
uint64_t addLocation(Location const& location);
/*! /*!
* Uses the location with the given name as the initial location. * Uses the location with the given name as the initial location.

Loading…
Cancel
Save