Reads the plain-text solution that `glpsol` writes with `-w` (basic, interior-point or integer, whichever the run produced) into data frames. That file identifies rows and columns by index only; pass the problem file written by `–wglp` in the same run to attach their names.

glpsol_read_solution(file, names = NULL)

Arguments

file

Path to the solution file written by `glpsol -w`.

names

Optional path to the problem file written by `glpsol –wglp` in the same run. Its `n i`/`n j` lines give the row and column names.

Value

A list of class `"glpsol_solution"` with * `kind`: `"basic"`, `"interior"` or `"integer"`, * `status`: `"optimal"`, `"feasible"`, `"infeasible"`, `"no feasible"` or `"undefined"`, * `primal_status`, `dual_status`: the two parts of a basic solution's status (`NA` for the other kinds), * `objective`: the objective value, * `problem`, `objective_name`: names from the problem file, if given, * `rows`, `cols`: data frames with `index`, `name`, `status`, `primal` and `dual`. `status` is the basis status (`"basic"`, `"lower"`, `"upper"`, `"free"`, `"fixed"`) and is `NA` for non-basic solution kinds; `dual` is `NA` for integer solutions.

See also

[glpsol_run()]

Examples

mod <- system.file("models", "transp.mod", package = "glpsol")
out <- tempfile("glpsol-"); dir.create(out)
sol <- file.path(out, "transp.txt")
glp <- file.path(out, "transp.glp")

glpsol_run(c("-m", mod, "-w", sol, "--wglp", glp), echo = FALSE)
s <- glpsol_read_solution(sol, names = glp)
s$status
#> [1] "optimal"
s$objective
#> [1] 153.675
s$cols[, c("name", "primal", "dual")]
#>                    name primal  dual
#> 1   x[Seattle,New-York]     50 0.000
#> 2    x[Seattle,Chicago]    300 0.000
#> 3     x[Seattle,Topeka]      0 0.036
#> 4 x[San-Diego,New-York]    275 0.000
#> 5  x[San-Diego,Chicago]      0 0.009
#> 6   x[San-Diego,Topeka]    275 0.000

unlink(out, recursive = TRUE)