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
Iterator for entities, represented by an iterator pointing to elements of type std::pair<Tuple, InstanceClass>
Methods to access the instances which are part of this Entity
-
inline ObjectiveInstance get() const#
Get the instance corresponding to a scalar entity.
- Throws:
runtime_error – if the entity has been deleted in the underlying AMPL interpreter
logic_error – if the entity is not scalar
- Returns:
The corresponding instance.
-
inline ObjectiveInstance operator[](Tuple index) const#
-
inline iterator begin() const#
-
inline iterator end() const#
-
inline std::enable_if<is_parameter_instance<T>::value, void>::type setInstances() const#
-
inline void setSuffix(std::string suffix, double value)#
Public Functions
-
inline double getDoubleSuffix(std::string suffix)#
-
inline std::string getStringSuffix(std::string suffix)#
-
inline double value() const#
Get the value of the objective instance.
-
inline std::string astatus() const#
Return the AMPL status.
-
inline std::string sstatus() const#
Return the solver status.
-
inline int exitcode() const#
Exit code returned by solver after most recent solve with this objective.
-
inline std::string message() const#
Result message returned by solver after most recent solve with this objective.
-
inline std::string result() const#
Result string returned by solver after most recent solve with this objective.
-
inline void drop()#
Drop this objective.
-
inline void restore()#
Restore this objective (if it had been dropped, no effect otherwise).
-
inline bool minimization() const#
Get the sense of this objective.
- Returns:
true if minimize, false if maximize
-
StringArray getIndexingSets() const#
Get the AMPL string representation of the sets on which this entity is indexed.
The obtained vector can be modified without any effect to the entity.
- Returns:
The string representation of the indexing sets for this entity or an empty array if the entity is scalar
-
DataFrame getValues() const#
Get the principal values of this entity as a DataFrame. The specific returned value depends on the type of entity (see list below).
- For:
Variables and Objectives it returns the suffix
valParameters it returns their values
Constraints it returns the suffix
dualSets it returns all the of the set. Note that it does not
apply to indexed sets. See SetInstance::getValues
- Returns:
A DataFrame containing the values for all instances
-
DataFrame getValues(StringArgs suffixes) const#
Get the specified suffixes value for all instances in a DataFrame.
- Parameters:
suffixes – Suffixes to get
- Returns:
A DataFrame containing the specified values
-
std::size_t indexarity() const#
Get the indexarity of this entity (sum of the dimensions of the indexing sets).
This value indicates the arity of the Tuple to be passed to the method BasicEntity::get() in order to access an instance of this entity. See the following AMPL examples
var x; # indexarity = 0 var y {1..2}; # indexarity = 1 var z {1..2,3..4}; # indexarity = 2 var zz {{(1, 2)}}; # indexarity = 2
- Returns:
The sum of the dimensions of the indexing sets or 0 if the entity is not indexed
-
bool isScalar() const#
Check whether this entity is scalar.
Equivalent to testing whether indexarity() is equal to zero.
- Returns:
True if the entity is scalar (not indexed over any set)
-
std::string name() const#
Get the name of this entity.
-
std::size_t numInstances() const#
Get the number of instances in this entity.
-
void setValues(DataFrame data)#
Set the values of this entiy to the correponding values of a DataFrame indexed over the same sets (or a subset). This function assigns the values in the first data column of the passed dataframe to the entity the function is called from. In particular, the statement:
x.setValues(y.getValues());
is semantically equivalent to the AMPL statement:
let {s in S} x[s] := y[s];
- Parameters:
data – The data to set the entity to
-
std::string toString() const#
Returns a string representation of this entity (its declaration).
-
StringArray xref() const#
Get the names of all entities which depend on this one.
- Returns:
An array with the names of all entities which depend on this one.
-
inline ObjectiveInstance get() const#