ls.solve: Solves a LocalSolver problem on data passed.

Description Usage Arguments Details Value Examples


Prepares input and data for LocalSolver, runs the application and parses its output to get resulting values.


ls.solve(lsp, data)



problem instance created with ls.problem.


named list of data items. Each element of the list should be indexed with the parameter name and should be a number, vector, matrix or array (of dimension 2 or 3) of numbers. The class of the numbers should be either integer (they will be then handled as integer by the LocalSolver) or numeric (LocalSolver will then treat them as elements of class double).


Result of this function is named list of output expressions added to the problem (for description of R data structures form see add.output.expr). Parameters set with set.params are passed to LocalSolver by means of generation(or modification) of LocalSolver param function (see LocalSolver LSP language reference manual for more details).

Make sure you pass integers in data if you want them to be ints in LocalSolver. Otherwise they will be considered doubles.

Errors occurred in model LSP code (passed while creating problem with ls.problem) are handled: They cause error containing original error message and error occurrence context to make it easier to detect potential errors in model LSP code. All other LocalSolver errors (e.g. in output expressions) and interaction errors (between localsolver package and LocalSolver process) are passed to caller without processing.


named list of all output expression values on best solution found.


model.text.lsp <- lsp.model.example('extdata/knapsack.txt')
lsp <- ls.problem(model.text.lsp)
lsp <- set.params(lsp, lsTimeLimit=60)
lsp <- add.output.expr(lsp, "x", 4)
data <- list(nbItems=4L, itemWeights=c(1L,2L,3L,4L), itemValues=c(5,6,7,8), knapsackBound=40L)
result <- ls.solve(lsp, data)

Search within the localsolver package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.