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

Methods to access the instances which are part of this Entity

InstanceClass 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

InstanceClass 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

InstanceClass get(VariantRef v1) const

Get the instance with the specified index.

InstanceClass get(VariantRef v1, VariantRef v2) const

Get the instance with the specified index.

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

Get the instance with the specified index.

InstanceClass 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

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

Public Types

typedef SetInstance::MemberRange MemberRange

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

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

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

Public Functions

InstanceRange instances() const

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

std::size_t arity() const

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

DataFrame getValues() const

Get values of this set in a DataFrame.

Valid only for non indexed sets.

See
SetInstance::getValues()

MemberRange members() const

Get of this Set.

Valid only for non indexed sets.

See
SetInstance::members()

std::size_t size() const

Get the number of tuples in this set.

Valid only for non indexed sets.

bool contains(TupleRef t) const

Check wether this set instance contains the specified Tuple.

Valid only for non indexed sets.

Parameters

void setValues(internal::Args objects, std::size_t n)

Set values.

Valid only for non indexed sets.

See
SetInstance::setValues()

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

Set values.

Valid only for non indexed sets.

See
SetInstance::setValues()

void setValues(DataFrame data)

Set values.

Valid only for non indexed sets.

See
SetInstance::setValues()

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.

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

iterator begin() const

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

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 SetInstance if found, otherwise InstanceRange::end.