Set#

class Set : public ampl::BasicEntity<SetInstance>#

Represents an AMPL set.

In case of not indexed sets, this class exposes iterators for accessing its elements. The members of the set are tuples, represented by objects of class ampl::Tuple.

All these methods throw an std::logic_error if called for an indexed set.

In case of indexed sets, you can gain access to the instances (of class ampl::SetInstance) using the methods Set::get(), using the operator Set::operator[]() or via Set::instances(), which returns an InstanceRange providing iterators.

Data can be assigned to the set using the methods Set::setValues (for non-indexed sets only) or using ampl::setData and an object of class ampl::DataFrame.

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 SetInstance 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 SetInstance operator[](Tuple index) const#
inline iterator begin() const#
inline iterator end() const#
inline iterator find(Tuple index) const#
inline std::enable_if<is_parameter_instance<T>::value, void>::type setInstances() const#
inline double getDoubleSuffix(std::string suffix)#
inline std::string getStringSuffix(std::string suffix)#
inline void setSuffix(std::string suffix, double value)#

Public Types

typedef SetInstance::MemberRange MemberRange#

Class to access the members of this set (valid only for non-indexed sets).

Public Functions

inline InstanceRange instances() const#

Get the InstanceRange used to iterate over all the instances in a Set.

inline std::size_t arity() const#

The arity of s, or number of components in each member of this set.

inline DataFrame getValues() const#

Get values of this set in a DataFrame.

Valid only for non indexed sets.

inline MemberRange members() const#

Get of this Set.

Valid only for non indexed sets.

inline std::size_t size() const#

Get the number of tuples in this set.

Valid only for non indexed sets.

inline bool contains(Tuple t) const#

Check wether this set instance contains the specified Tuple.

Valid only for non indexed sets.

Parameters:

tTuple to be found

inline void setValues(Args objects, std::size_t n)#

Set values.

Valid only for non indexed sets.

inline void setValues(const Tuple objects[], std::size_t n)#

Set values.

Valid only for non indexed sets.

inline void setValues(DataFrame data)#

Set values.

Valid only for non indexed sets.

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(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.

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.

void setSuffixes(DataFrame data)#
class InstanceRange#

Class used to iterate over all the instances of a Set. For example, supposing an indexed set set A{1..2}; is defined in an AMPL object named ampl:

ampl::Set A = ampl.getSet("A");
for (ampl::SetInstance s: A.instances())
  std::cout << s.name() << "\n";

Public Types

typedef Set::iterator iterator#

Iterator over instances of an indexed set.

Public Functions

inline iterator begin() const#

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

inline iterator end() const#

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

inline iterator find(Tuple t) const#

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

Returns:

an iterator to the SetInstance if found, otherwise InstanceRange::end.