Title: | R API to LocalSolver |
---|---|
Description: | The package converts R data onto input and data for LocalSolver, executes optimization and exposes optimization results as R data. LocalSolver (http://www.localsolver.com/) is an optimization engine developed by Innovation24 (http://www.innovation24.fr/). It is designed to solve large-scale mixed-variable non-convex optimization problems. The localsolver package is developed and maintained by WLOG Solutions (http://www.wlogsolutions.com/en/) in collaboration with Decision Support and Analysis Division at Warsaw School of Economics (http://www.sgh.waw.pl/en/). |
Authors: | Walerian Sokolowski [aut, cre, cph], Wit Jakuczun [aut, cph], Natalia Okinczyc [aut], Bogumil Kaminski [aut] |
Maintainer: | Walerian Sokolowski <[email protected]> |
License: | LGPL-2.1 |
Version: | 2.3 |
Built: | 2024-12-18 06:50:43 UTC |
Source: | CRAN |
Added expression will be printed out by the LocalSolver and
added to ls.solve
result.
add.output.expr(lsp, expr.text.lsp, dimensions = 1)
add.output.expr(lsp, expr.text.lsp, dimensions = 1)
lsp |
problem instance created with
|
expr.text.lsp |
text of expression in LSP language (an objective function, constraint or decision variable name). |
dimensions |
vector of variables expected
dimensions. 1 for a number, length of a vector or
dimensions of resulting matrix or array (see
|
Each added expression is extracted out of LocalSolver
output according to dimensions
provided. Extracted
values are converted into R data structures. If
dimension
is 1 the expression is considered to be a
number. Otherwise the expression is converted to R
array
with dimensions
passed as dim(see
array
).
All output expression values are exposed as
numerics
.
Currently errors in expression and inconsistency in dimensions passed are not detected properly. Handling such situations is planned to be implemented in next localsolver package version.
Updated ls.problem
instance.
model.text.lsp <- lsp.model.example('extdata/knapsack.txt') lsp <- ls.problem(model.text.lsp) lsp <- add.output.expr(lsp, "knapsackWeight") # produces table x[i in 1..5][j in 1..10] in LocalSolver output # and array with dims = c(5,10) under name x in output of ls.solve. lsp <- add.output.expr(lsp, "x", c(5, 10))
model.text.lsp <- lsp.model.example('extdata/knapsack.txt') lsp <- ls.problem(model.text.lsp) lsp <- add.output.expr(lsp, "knapsackWeight") # produces table x[i in 1..5][j in 1..10] in LocalSolver output # and array with dims = c(5,10) under name x in output of ls.solve. lsp <- add.output.expr(lsp, "x", c(5, 10))
add.output.expr
).Remove all output expressions (see:
add.output.expr
).
clear.output.exprs(lsp)
clear.output.exprs(lsp)
lsp |
problem instance created with
|
updated ls.problem instance.
model.text.lsp <- lsp.model.example('extdata/knapsack.txt') lsp <- ls.problem(model.text.lsp) lsp <- add.output.expr(lsp, "knapsackWeight") lsp <- clear.output.exprs(lsp)
model.text.lsp <- lsp.model.example('extdata/knapsack.txt') lsp <- ls.problem(model.text.lsp) lsp <- add.output.expr(lsp, "knapsackWeight") lsp <- clear.output.exprs(lsp)
Data set for google_machine_reassignment demo.
The package converts R data onto input and data for LocalSolver, executes optimization and exposes optimization results as R data.
LocalSolver (http://www.localsolver.com/) is an optimization engine developed by Innovation24 (http://www.innovation24.fr/). It is designed to solve large-scale mixed-variable non-convex optimization problems.
The localsolver package is result of cooperation of WLOG Solutions (http://www.wlogsolutions.com/en/) in collaboration Decision Support and Analysis Division at Warsaw School of Economics (http://www.sgh.waw.pl/en/).
The localsolver package allows for solving optimization problems in R by using the LocalSolver program. It combines efficiency and easiness of model formulation, which characterize the LocalSolver program, with the elasticity of data in R. The model formulation in LSP language is provided by a user as a string or text file, and the input data - as a list. The solution is also a list, with chosen decision variables, constraints and objective function values. Thus the problem can be solved many times (for example, by iterating with different parameter settings) and the result is provided in a form which makes further processing or visualization in R fast and easy.
It is highly recommended that the LocalSolver software is
installed before the R package.
The test version
(limited to 100 decisions and 1000 variables) can be
downloaded from the website:
http://www.localsolver.com/download.html
The
access to the trial license for full version requires
contacting the Innovation24 company. For further
information please visit the website:
http://www.localsolver.com/
Bugs and feature requests can be reported by e-mail: Walerian Sokolowski <[email protected]>. We are also looking forward for any future package development suggestions.
Creates problem instance from model LSP code passed. Detects functions in model LSP code.
ls.problem(model.text.lsp, ls.path = NULL)
ls.problem(model.text.lsp, ls.path = NULL)
model.text.lsp |
text of model formulated in LSP language. |
ls.path |
path to the LocalSolver executable. Optional argument (NULL by default). If not provided, the LocalSolver will be searched by the system in PATH environment variable. |
Functions detected in model LSP code must contain
model
function as it main 'workhorse' function of
LocalSolver model. They can contain param
,
display
and any other custom functions.
Because localsolver package defines input
function
based on data passed to ls.solve
and
output
function base on output expressions added to
problem instance with add.output.expr
these
two(input
and output
) functions cannot occur
in model LSP code passed. Passing them will cause
appropriate error.
For mode details see LocalSolver LSP language reference manual: http://www.localsolver.com/lspreferencemanual.html.
created ls.problem instance.
model.text.lsp <- lsp.model.example('extdata/knapsack.txt') lsp <- ls.problem(model.text.lsp)
model.text.lsp <- lsp.model.example('extdata/knapsack.txt') lsp <- ls.problem(model.text.lsp)
Prepares input and data for LocalSolver, runs the application and parses its output to get resulting values.
ls.solve(lsp, data)
ls.solve(lsp, data)
lsp |
problem instance created with
|
data |
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
http://www.localsolver.com/lspreferencemanual.html
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)
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)
Load LSP model example code.
lsp.model.example(example.file)
lsp.model.example(example.file)
example.file |
example file path relative to packaged root. |
text of model formulated in LSP language.
lsp.model.example('extdata/knapsack.txt')
lsp.model.example('extdata/knapsack.txt')
Prints an object of class ls.problem.
## S3 method for class 'ls.problem' print(x, ...)
## S3 method for class 'ls.problem' print(x, ...)
x |
problem instance created with
|
... |
further arguments passed to or from other methods. |
model.text.lsp <- lsp.model.example('extdata/knapsack.txt') lsp <- ls.problem(model.text.lsp) lsp
model.text.lsp <- lsp.model.example('extdata/knapsack.txt') lsp <- ls.problem(model.text.lsp) lsp
Problem parameters can be set with
set.params
. This method resets all their
values to defaults, which have been described in help for
the set.params
function.
reset.lsp.params(lsp)
reset.lsp.params(lsp)
lsp |
the lsp object whose parameters are to be reset. |
lsp object with all parameters reset to their default values.
modelText <- lsp.model.example('extdata/knapsack.txt') lsp <- ls.problem(modelText) lsp$params lsp <- set.params(lsp, lsTimeLimit=60, lsSeed=7) lsp$params lsp <- reset.lsp.params(lsp) lsp$params
modelText <- lsp.model.example('extdata/knapsack.txt') lsp <- ls.problem(modelText) lsp$params lsp <- set.params(lsp, lsTimeLimit=60, lsSeed=7) lsp$params lsp <- reset.lsp.params(lsp) lsp$params
Updates the chosen parameters of an object of class
ls.problem
.
set.params(lsp, lsTimeLimit = lsp$params$lsTimeLimit, lsIterationLimit = lsp$params$lsIterationLimit, lsTimeBetweenDisplays = lsp$params$lsTimeBetweenDisplays, lsSeed = lsp$params$lsSeed, lsNbThreads = lsp$params$lsNbThreads, lsAnnealingLevel = lsp$params$lsAnnealingLevel, lsVerbosity = lsp$params$lsVerbosity, indexFromZero = lsp$params$indexFromZero)
set.params(lsp, lsTimeLimit = lsp$params$lsTimeLimit, lsIterationLimit = lsp$params$lsIterationLimit, lsTimeBetweenDisplays = lsp$params$lsTimeBetweenDisplays, lsSeed = lsp$params$lsSeed, lsNbThreads = lsp$params$lsNbThreads, lsAnnealingLevel = lsp$params$lsAnnealingLevel, lsVerbosity = lsp$params$lsVerbosity, indexFromZero = lsp$params$indexFromZero)
lsp |
problem instance created with
|
lsTimeLimit |
the number of the seconds which will be spent to optimize the objective function (functions), or a vector of times (in seconds) assigned to each objective function. The length of the vector should correspond to the length of the number of objective functions. |
lsIterationLimit |
the number of iterations made to optimize the objective function (functions), or a vector of iteration numbers assigned to each objective function. The length of the vector should correspond to the length of the number of objective functions. |
lsTimeBetweenDisplays |
the time (in seconds) between successive displays of the information about the search (default: 1) |
lsSeed |
pseudo-random number generator seed (default: 0). |
lsNbThreads |
the number of threads over which the search is paralleled (default: 2). |
lsAnnealingLevel |
simulated annealing level (no annealing: 0, default: 1). |
lsVerbosity |
verbosity (no display: 0, default: 1). |
indexFromZero |
indicates whether the data and
decision variables (vectors and matrices) are to be
indexed from 0. If |
updated ls.problem instance.
model.text.lsp <- lsp.model.example('extdata/knapsack.txt') lsp <- ls.problem(model.text.lsp) lsp <- set.params(lsp, lsTimeLimit=10, lsIterationLimit= 5)
model.text.lsp <- lsp.model.example('extdata/knapsack.txt') lsp <- ls.problem(model.text.lsp) lsp <- set.params(lsp, lsTimeLimit=10, lsIterationLimit= 5)
Exposed for technical reasons. Temporary folder is used to
store files for communication with LocalSolver application.
By default system received temp folder is used. Setting
temporary folder is useful in case ls.solve
is performed in parallel. In that case each call should use
own lsp instance with dedicated temporary folder. In case
of changing this directory, it is important to choose a
path to a folder with write access.
set.temp.dir(lsp, path)
set.temp.dir(lsp, path)
lsp |
problem instance created with
|
path |
the directory, which will be used for temporary data. |
model.text.lsp <- lsp.model.example('extdata/knapsack.txt') lsp <- ls.problem(model.text.lsp) lsp <- set.temp.dir(lsp, tempdir())
model.text.lsp <- lsp.model.example('extdata/knapsack.txt') lsp <- ls.problem(model.text.lsp) lsp <- set.temp.dir(lsp, tempdir())