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.


LSExternalFunction Delegate

delegate long localsolver.LSIntExternalFunction(LSExternalArgumentValues argumentValues)

Integer external function delegate. To use your own integer functions with LocalSolver, you have to proceed in 3 steps:

  1. Implement the delegate in a method. The method must take a LSExternalArgumentValues and must return an integer value. The argument values contain the values of the expressions passed to the function. A distinction is made between integer arguments (bool, int) and floating point arguments (double).

  2. Instantiate the function as an LSExpression with LSModel.CreateIntExternalFunction or the dedicated shortcut LSModel.IntExternalFunction.

  3. Pass arguments to your function and call it. For that, you have to create expressions of type LSOperator.Call. The first operand must be the LSExpression corresponding to your external function. The other operands must be LSExpressions that will be used as arguments. Their value will be made accessible to your external function through the LSExternalArgumentValues.

Note 1: Most of the time your external function will be called when the solver is in state LSState.Running. Do not attempt to call any method of the solver (to retrieve statistics, values of LSExpressions or whatever) in that state or an exception will be thrown.

Note 2: Your functions must be thread-safe. According to the “nbThreads” parameter, LocalSolver can be multi-threaded. In that case, your external functions must be thread safe. If you cannot guarantee the thread-safety of your code, we strongly recommend you to limit the search of LocalSolver to one thread with LSParam.SetNbThreads.

Note 3: You can provide additional data for your function (such as lower and upper bounds) with the help of the LSExternalContext associated with your function (see LSExpression.GetExternalContext).

See:

LSModel.CreateIntExternalFunction

See:

LSOperator.Call

See:

LSOperator.ExternalFunction

Since:

9.5

delegate double localsolver.LSDoubleExternalFunction(LSExternalArgumentValues argumentValues)

Double external function delegate. To use your own double functions with LocalSolver, you have to proceed in 3 steps:

  1. Implement the delegate in a method. The method must take a LSExternalArgumentValues and must return a double value. The argument values contain the values of the expressions passed to the function. A distinction is made between integer arguments (bool, int) and floating point arguments (double).

  2. Instantiate the function as an LSExpression with LSModel.CreateDoubleExternalFunction or the dedicated shortcut LSModel.DoubleExternalFunction.

  3. Pass arguments to your function and call it. For that, you have to create expressions of type LSOperator.Call. The first operand must be the LSExpression corresponding to your external function. The other operands must be LSExpressions that will be used as arguments. Their value will be made accessible to your external function through the LSExternalArgumentValues.

Note 1: Most of the time your external function will be called when the solver is in state LSState.Running. Do not attempt to call any method of the solver (to retrieve statistics, values of LSExpressions or whatever) in that state or an exception will be thrown.

Note 2: Your functions must be thread-safe. According to the “nbThreads” parameter, LocalSolver can be multi-threaded. In that case, your external functions must be thread safe. If you cannot guarantee the thread-safety of your code, we strongly recommend you to limit the search of LocalSolver to one thread with LSParam.SetNbThreads.

Note 3: You can provide additional data for your function (such as lower and upper bounds) with the help of the LSExternalContext associated with your function (see LSExpression.GetExternalContext).

See:

LSModel.CreateDoubleExternalFunction

See:

LSOperator.Call

See:

LSOperator.ExternalFunction

delegate long[] localsolver.LSIntArrayExternalFunction(LSExternalArgumentValues argumentValues)

Integer array external function delegate. To use integer array external functions with LocalSolver, you have to proceed in 3 steps:

  1. Implement the delegate in a method. The method must take a LSExternalArgumentValues and must return an integer array value. The argument values contain the values of the expressions passed to the function. A distinction is made between integer arguments (bool, int) and floating point arguments (double).

  2. Instantiate the function as an LSExpression with LSModel.CreateIntArrayExternalFunction or the dedicated shortcut LSModel.IntArrayExternalFunction.

  3. Pass arguments to your function and call it. For that, you have to create expressions of type LSOperator.Call. The first operand must be the LSExpression corresponding to your external function. The other operands must be LSExpressions that will be used as arguments. Their value will be made accessible to your external function through the LSExternalArgumentValues.

Note 1: Most of the time your external function will be called when the solver is in state LSState.Running. Do not attempt to call any method of the solver (to retrieve statistics, values of LSExpressions or whatever) in that state or an exception will be thrown.

Note 2: Your functions must be thread-safe. According to the “nbThreads” parameter, LocalSolver can be multi-threaded. In that case, your external functions must be thread safe. If you cannot guarantee the thread-safety of your code, we strongly recommend you to limit the search of LocalSolver to one thread with LSParam.SetNbThreads.

Note 3: To optimize performance, you can return the same array object per thread from one call to another.

Note 4: You can provide additional data for your function (such as lower and upper bounds) with the help of the LSExternalContext associated with your function (see LSExpression.GetExternalContext).

Since:

11.0

See:

LSModel.CreateIntArrayExternalFunction

See:

LSOperator.Call

See:

LSOperator.ExternalFunction

delegate double[] localsolver.LSDoubleArrayExternalFunction(LSExternalArgumentValues argumentValues)

Double array external function delegate. To use double array external functions with LocalSolver, you have to proceed in 3 steps:

  1. Implement the delegate in a method. The method must take a LSExternalArgumentValues and must return a double array value. The argument values contain the values of the expressions passed to the function. A distinction is made between integer arguments (bool, int) and floating point arguments (double).

  2. Instantiate the function as an LSExpression with LSModel.CreateDoubleArrayExternalFunction or the dedicated shortcut LSModel.DoubleArrayExternalFunction.

  3. Pass arguments to your function and call it. For that, you have to create expressions of type LSOperator.Call. The first operand must be the LSExpression corresponding to your external function. The other operands must be LSExpressions that will be used as arguments. Their value will be made accessible to your external function through the LSExternalArgumentValues.

Note 1: Most of the time your external function will be called when the solver is in state LSState.Running. Do not attempt to call any method of the solver (to retrieve statistics, values of LSExpressions or whatever) in that state or an exception will be thrown.

Note 2: Your functions must be thread-safe. According to the “nbThreads” parameter, LocalSolver can be multi-threaded. In that case, your external functions must be thread safe. If you cannot guarantee the thread-safety of your code, we strongly recommend you to limit the search of LocalSolver to one thread with LSParam.SetNbThreads.

Note 3: To optimize performance, you can return the same array object per thread from one call to another.

Note 4: You can provide additional data for your function (such as lower and upper bounds) with the help of the LSExternalContext associated with your function (see LSExpression.GetExternalContext).

Since:

11.0

See:

LSModel.CreateDoubleArrayExternalFunction

See:

LSOperator.Call

See:

LSOperator.ExternalFunction