SetInstance#

class SetInstance : public ampl::Instance#

A SetInstance object stores the information regarding a specific instance of a set.

The instances can be accessed through the function ampl::Set.get of the parent entity.

The set contains a collection of ampl::Tuple

Data can be assigned using setValues or using AMPL::setData and a DataFrame object.

All the accessors in this class throw an std::runtime_error if the instance has been deleted in the underlying AMPL interpreter.

Public Functions

inline std::string toString() const#

Returns a string representation of this set instance.

inline std::size_t size()#

Get the number of tuples in this set instance.

inline std::size_t arity() const#

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

inline bool contains(Tuple t) const#

Check wether this set instance contains the specified Tuple.

Parameters:

tTuple to be found

inline MemberRange members()#

Get all members (tuples) in this set instance.

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

Set the tuples in this set instance using a flattened array.

The size of the array must be a multiple of the arity of this set instance, and each arity elements in the array will be grouped into a Tuple.

Parameters:
  • objects – An array of doubles or strings to be grouped into tuples

  • n – The number of objects in the array

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

Set the tuples in this set instance.

Parameters:
  • objects – An array of tuples

  • n – The number of tuples in the array

inline void setValues(DataFrame data)#

Set the values in this set instance to the indexing values of the passed DataFrame. The number of indexing columns of the parameter must be equal to the arity of this set instance.

For example, considering the following AMPL entities and corresponding C++ objects:

set A := 1..2; param p{i in A} := i+10; set AA;

The following is valid:

ampl::Set A = ampl.getSet(“A”), AA = ampl.getSet(“AA”); AA.setValues(A.getValues()); // A has now the members {1, 2}

inline DataFrame getValues() const#

Get all the tuples in this set instance in a DataFrame.

inline Entity entity() const#

Returns the entity that this instance is part of.

inline Tuple key() const#

Returns the key of this instance.

inline std::string name() const#

Returns the name of this instance.

class MemberRange#

Class to access the members (tuples) in this set instance.

Public Functions

inline iterator begin() const#

Begin iterator.

inline iterator end() const#

End iterator.

inline std::size_t size() const#

Size.

class iterator#

Iterator.

Public Functions

inline Tuple operator*() const#

Dereference — return Tuple BY VALUE.

inline iterator &operator++()#

Prefix increment.

inline iterator operator++(int)#

Postfix increment.