EntityMap#

template<class EntityClass>
class EntityMap#

Represents a synchronised list of AMPL entities.

It can be obtained using the functions AMPL::getVariables(), AMPL::getConstraints(), AMPL::getSets(), AMPL::getObjectives(), AMPL::getParameters().

The collection cannot be modified by the user (entities cannot be added nor deleted) and is linked to an AMPL object. When the corresponding AMPL entities are modified (through AMPL::eval() or any other operation which influences the number of entities), the collection is automatically invalidated. It is updated lazily at the next access.

If the corresponding AMPL object is not running anymore, or it is null, an exception is thrown on all operations.

Public Functions

inline EntityClass operator[](fmt::CStringRef name) const#

Entity access Returns the entity identified by the specified name.

Parameters:

name – Name of the entity to be found

Throws:

An – std::out_of_range exception if the specified parameter does not exist

Returns:

The entity with the corresponding name

inline iterator begin() const#

Return an iterator to the beginning of this collection.

Use together with end() to iterate through the contents of this list.

An example, printing the names of all the variables defined in the AMPL object named ampl:

for (ampl::Variable v: ampl.getVariables())
  std::cout << v.name() << "\n";

inline iterator end() const#

Return iterator to the end of this collection.

inline iterator find(fmt::CStringRef name) const#

Searches the container for an entity with the specified name and returns an iterator to it if found, otherwise it returns an iterator to end().

An example which checks if the variable x is defined in the AMPL object called ampl:

ampl::EntityMap<Variable> vars = ampl.getVariables();
ampl::EntityMap<Variable>::iterator it = vars.find("x");
if(it == vars.end())
  std::cout << "Variable x does not exist\n");

Parameters:

name – The name of the entity to be found

Returns:

An iterator to the entity, if an Entity with specified key is found, or end() otherwise.

class iterator#

Iterator used to access the entities in the list.

See also

begin(), end() and find()