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.

LSNativeContext Class

class localsolver.LSNativeContext

Context for native functions. Native context are used to query the values of the arguments passed to native functions.

Since:6.0

Summary

Methods
count Returns the number of values in the current context.
is_bool Returns true if the value at the given position is a boolean.
is_int Returns true if the value at the given position is an integer.
is_double Returns true if the value at the given position is a double.
is_collection Returns true if the value at the given position is a collection (list or set).
is_array Returns true if the value at the given position is an array.
get Returns the value at the given position.
Special methods
__len__ Returns the number of values in the current context.
__getitem__ Returns the value at the given position.

Instance methods

LSNativeContext.count()

Returns the number of values in the current context.

LSNativeContext.is_bool(pos)

Returns true if the value at the given position is a boolean. You can retrieve the value with get().

Parameters:pos – Position of the value to query.
Returns:True if the value at the given position is a boolean.
Return type:bool
LSNativeContext.is_int(pos)

Returns true if the value at the given position is an integer. You can retrieve the value with get().

Parameters:pos – Position of the value to query.
Returns:True if the value at the given position is an integer.
Return type:bool
LSNativeContext.is_double(pos)

Returns true if the value at the given position is a double. You can retrieve the value with get().

Parameters:pos – Position of the value to query.
Returns:True if the value at the given position is a double.
Return type:bool
LSNativeContext.is_collection(pos)

Returns true if the value at the given position is a collection (list or set). You can retrieve the value with get().

Parameters:pos – Position of the value to query.
Returns:True if the value at the given position is an array.
Return type:bool
LSNativeContext.is_array(pos)

Returns true if the value at the given position is an array. You can retrieve the value with get().

Parameters:pos – Position of the value to query.
Returns:True if the value at the given position is an array.
Return type:bool
LSNativeContext.get(pos)

Returns the value at the given position. The returned value can be a double or an integer depending on the type of the value.

Parameters:pos – Position of the value to query.
Returns:Value
Return type:int or double

Special operators and methods

LSNativeContext.__len__()

Returns the number of values in the current context. This method allows users to call len() function directly on the native context without using the count() method.

LSNativeContext.__getitem__(pos)

Returns the value at the given position. This method allows users to use [] operator directly on the native context without using the get() method.

Parameters:pos – Position of the value to query.
Returns:Value
Return type:int or double