LocalSolver logo
is now
Hexaly logo

We're excited to share that we are moving forward. We're leaving behind the LocalSolver brand and transitioning to our new identity: Hexaly. This represents a leap forward in our mission to enable every organization to make better decisions faster when faced with operational and strategic challenges.

This page is for an old version of Hexaly Optimizer. We recommend that you update your version and read the documentation for the latest stable release.

LSCollection Class

class localsolver.LSCollection

Value type for collection expressions (lists or sets). Such a value is obtained with LSExpression.GetCollectionValue(). It represents a reference to the value of a variable and the value of this variable is modified when the LSCollection object is modified.

Since:5.5
See:LSModel
See:LSExpression
See:LSOperator.List

Summary

Methods
Add Adds the given value to this collection.
Clear Removes all values of this collection.
Count Returns the number of values in the collection.
Get Gets the value at the given position.
Contains Returns true if the collection contains the given value, false otherwise.
GetEnumerator Gets the enumerator for the content of this collection.
ToString Returns a string representation of the values in the collection in the format { val0, val1, ..., valN }.
Overloaded operators
this Indexer.

Instance methods

void Add(long val)

Adds the given value to this collection. Only allowed in state Stopped. This function will fail if the given value is outside of the domain of the list or if this value is already included in this list (keep in mind that a list cannot contain twice the same value).

Arguments:val (long) – The value to be added.
void Clear()

Removes all values of this collection. Only allowed in state Stopped.

int Count()

Returns the number of values in the collection. Elements in collections are indexed from 0 to count()-1.

Returns:Number of values in the collection.
Return type:int
long Get(int position)

Gets the value at the given position.

Arguments:position (int) – The considered position (must be non negative and strictly smaller than the number of values in the collection).
Returns:The value at the given position
Return type:long
bool Contains(long value)

Returns true if the collection contains the given value, false otherwise.

Arguments:value (long) – Element whose presence in this collection is to be tested.
Returns:True if the collection contains the value
Return type:bool
IEnumerator<long> GetEnumerator()
IEnumerator GetEnumerator()

Gets the enumerator for the content of this collection.

string ToString()

Returns a string representation of the values in the collection in the format { val0, val1, ..., valN }.

Returns:A String representation of the collection
Return type:string

Overloaded operators and indexers

long this(int position)

Indexer. Gets the value at the given position.

Arguments:position (int) – The considered position. Must be non negative and striclty smaller than the number of values in the collection.
Returns:The value at the given position
Return type:long