Objective

class Objective : public ampl::BasicEntity<ObjectiveInstance>

Represents an AMPL objective.

Note that, in case of a scalar objective, all the properties (corresponding to AMPL suffixes) of the objective instance can be accessed through methods like Objective::value(). The methods have the same name of the corresponding AMPL suffixes. See http://www.ampl.com/NEW/suffbuiltin.html for a list of the available suffixes.

All these methods throw an std::logic_error if called for a non scalar objective and an std::runtime_error if called on an entity which has been deleted in the underlying intepreter.

The instances, represented by the class ObjectiveInstance can be accessed via the operator Objective::operator[](), via the methods Objective::get() or via the iterators provided.

To gain access to all the values in an entity (for all instances and all suffixes for that entities), see Entity::getValues() and the DataFrame class.

Instance access

Methods to access the instances which are part of this Entity

ObjectiveInstance get() const

Get the instance corresponding to a scalar entity.

Return
The corresponding instance.
Exceptions
  • runtime_error: if the entity has been deleted in the underlying AMPL interpreter
  • logic_error: if the entity is not scalar

ObjectiveInstance get(TupleRef index) const

Get the instance with the specified index.

Return
The corresponding instance
Parameters
  • index: The tuple specifying the index
Exceptions
  • out_of_range: if an instance with the specified index does not exist
  • out_of_range: if the entity has been deleted in the underlying AMPL interpreter
  • ampl::UnsupportedOperationException: if the entity is scalar

ObjectiveInstance get(VariantRef v1) const

Get the instance with the specified index.

ObjectiveInstance get(VariantRef v1, VariantRef v2) const

Get the instance with the specified index.

ObjectiveInstance get(VariantRef v1, VariantRef v2, VariantRef v3) const

Get the instance with the specified index.

ObjectiveInstance get(VariantRef v1, VariantRef v2, VariantRef v3, VariantRef v4) const

Get the instance with the specified index.

Return
The corresponding instance
Parameters
  • v1: The VariantRef specifying the first element of the indexing tuple
  • v2: The VariantRef specifying the second element of the indexing tuple
  • v3: The VariantRef specifying the third element of the indexing tuple
  • v4: The VariantRef specifying the fourth element of the indexing tuple
Exceptions
  • out_of_range: if an instance with the specified index does not exist
  • runtime_error: if the entity has been deleted in the underlying AMPL interpreter
  • ampl::UnsupportedOperationException: if the entity is scalar

ObjectiveInstance operator[](TupleRef index) const
ObjectiveInstance operator[](VariantRef v1) const

Public Types

typedef internal::CountedIterator<internal::EntityWrapper<ObjectiveInstance>> iterator

Iterator for entities, represented by an iterator pointing to elements of type std::pair<TupleRef, InstanceClass>

Public Functions

double value() const

Get the value of the objective instance.

std::string astatus() const

Return the AMPL status.

std::string sstatus() const

Return the solver status.

int exitcode() const

Exit code returned by solver after most recent solve with this objective.

std::string message() const

Result message returned by solver after most recent solve with this objective.

std::string result() const

Result string returned by solver after most recent solve with this objective.

void drop()

Drop this objective.

void restore()

Restore this objective (if it had been dropped, no effect otherwise)

bool minimization() const

Get the sense of this objective.

Return
true if minimize, false if maximize

iterator begin() const

Get an iterator pointing to the first instance in this entity.

iterator end() const

Get an iterator pointing after the last instance in this entity.

iterator find(TupleRef t) const

Searches the current entity for an instance with the specified index.

Return
an iterator to the wanted entity if found, otherwise an iterator to BasicEntity::end.