SetInstance

class ampl::SetInstance : public ampl::BasicInstance<internal::SetInstance>

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::size_t size() const

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(TupleRef t) const

Check wether this set instance contains the specified Tuple.

Parameters

tTuple to be found

inline MemberRange members() const

Get all members (tuples) in this set instance.

inline void setValues(internal::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.

inline std::string toString() const

Returns a string representation of this instance.

class MemberRange

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

Public Functions

inline explicit MemberRange(internal::SetInstance *impl_)

Constructor.

inline iterator begin() const

Returns an iterator to the beginning of the members collection.

inline iterator end() const

Returns an iterator to the first item after the end of the collection.

inline std::size_t size() const

Returns the size of the collection.

class iterator

Iterator.

Public Functions

inline TupleRef operator*() const

Dereference operator.

Gains access to the ampl::TupleRef which iterators points to.

inline iterator &operator++()

Postfix increment.

inline iterator operator++(int)

Increment.

inline bool operator==(const iterator &other) const

Equality operator.

inline bool operator!=(const iterator &other) const

Inequality operator.