ECOS_csolve | R Documentation |
The function ECOS_csolve
is a wrapper around the ecos
csolve
C function. Conic constraints are specified using the
G
and h
parameters and can be NULL
and zero
length vector respectively indicating an absence of conic
constraints. Similarly, equality constraints are specified via
A
and b
parameters with NULL
and empty vector
values representing a lack of such constraints. At most one of the
pair (G , h)
or (A, b)
is allowed to be absent.
ECOS_csolve(
c = numeric(0),
G = NULL,
h = numeric(0),
dims = list(l = integer(0), q = NULL, e = integer(0)),
A = NULL,
b = numeric(0),
bool_vars = integer(0),
int_vars = integer(0),
control = ecos.control()
)
c |
the coefficients of the objective function; the length of
this determines the number of variables |
G |
the inequality constraint matrix in one of three forms: a
plain matrix, simple triplet matrix, or compressed column
format, e.g. dgCMatrix-class. Can also be
|
h |
the right hand size of the inequality constraint. Can be empty numeric vector. |
dims |
is a list of three named elements: |
A |
the optional equality constraint matrix in one of three
forms: a plain matrix, simple triplet matrix, or compressed
column format, e.g. dgCMatrix-class. Can be
|
b |
the right hand side of the equality constraint, must be
specified if |
bool_vars |
the indices of the variables, 1 through |
int_vars |
the indices of the variables, 1 through |
control |
is a named list that controls various optimization parameters; see ecos.control. |
a list of 8 named items
primal variables
dual variables for equality constraints
slacks for Gx + s <= h
, s \in K
dual variables for inequality constraints s \in K
gives information about the status of solution
a named integer vector containing four elements
0=ECOS_OPTIMAL
, 1=ECOS_PINF
,
2=ECOS_DINF
, 10=ECOS_INACC_OFFSET
, -1=ECOS_MAXIT
,
-2=ECOS_NUMERICS
, -3=ECOS_OUTCONE
, -4=ECOS_SIGINT
,
-7=ECOS_FATAL
. See ECOS_exitcodes
.
the number of iterations used
the number of iterations for mixed integer problems
a non-zero number if a numeric error occurred
a named numeric vector containing
value of primal objective
value of dual objective
primal residual on inequalities and equalities
dual residual
primal infeasibility measure
dual infeasibility measure
primal infeasibility residual
dual infeasibility residual
duality gap
relative duality gap
Unknown at the moment to this R package maintainer.
a named numeric vector of timing information consisting of
the total runtime in ecos
the time for setup of the problem
the time to solve the problem
A call to this function will solve the problem:
minimize c^Tx
, subject to Ax = b
, and h - G*x \in K
.
Variables can be constrained to be boolean (1 or 0) or integers. This is indicated
by specifying parameters bool_vars
and/or int_vars
respectively. If so
indicated, the solutions will be found using a branch and bound algorithm.
## githubIssue98
cat("Basic matrix interface\n")
Gmat <- matrix(c(0.416757847405471, 2.13619609566845, 1.79343558519486, 0, 0,
0, 0, -1, 0, 0, 0, 0.056266827226329, -1.64027080840499, 0.841747365656204,
0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0.416757847405471, 2.13619609566845,
1.79343558519486, 0, 0, 0, -1, 0, 0, 0, 0, 0.056266827226329, -1.64027080840499,
0.841747365656204, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0), ncol = 5L)
c <- as.numeric(c(0, 0, 0, 0, 1))
h <- as.numeric(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
dims <- list(l = 6L, q = 5L, e = 0L)
ECOS_csolve(c = c, G = Gmat, h = h,
dims = dims,
A = NULL, b = numeric(0))
cat("Simple Triplet Matrix interface, if you have package slam\n")
if (requireNamespace("slam")) {
ECOS_csolve(c = c, G = slam::as.simple_triplet_matrix(Gmat), h = h,
dims = dims,
A = NULL, b = numeric(0))
}
if (requireNamespace("Matrix")) {
ECOS_csolve(c = c, G = Matrix::Matrix(Gmat), h = h,
dims = dims,
A = NULL, b = numeric(0))
}
## Larger problems using saved data can be found in the test suite.
## Here is one
if (requireNamespace("Matrix")) {
MPC01 <- readRDS(system.file("testdata", "MPC01_1.RDS", package = "ECOSolveR"))
G <- Matrix::sparseMatrix(x = MPC01$Gpr, i = MPC01$Gir, p = MPC01$Gjc,
dims = c(MPC01$m, MPC01$n), index1 = FALSE)
h <- MPC01$h
dims <- lapply(list(l = MPC01$l, q=MPC01$q, e=MPC01$e), as.integer)
retval <- ECOS_csolve(c = MPC01$c, G=G, h = h, dims = dims, A = NULL, b = NULL,
control = ecos.control(verbose=1L))
retval$retcodes
retval$infostring
retval$summary
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.