SetInstance

class ampl::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

std::size_t size() const

Get the number of tuples in this set instance.

bool contains(TupleRef t) const

Check wether this set instance contains the specified Tuple.

Parameters

MemberRange members() const

Get all members (tuples) in this set instance.

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

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

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}

DataFrame getValues() const

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

class MemberRange

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

Public Functions

MemberRange(internal::SetInstance *impl_)

Constructor.

iterator begin() const

Returns an iterator to the beginning of the members collection.

iterator end() const

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

class iterator

Iterator.

Public Functions

TupleRef operator*() const

Dereference operator.

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

iterator &operator++()

Postfix increment.

iterator operator++(int)

Increment.

bool operator==(const iterator &other) const

Equality operator.

bool operator!=(const iterator &other) const

Inequality operator.