Skip to contents

Get variable values from a solution

Usage

get_solution(solution, expr, type = "primal")

get_solution_(solution, expr, type = "primal")

Arguments

solution

the solution object

expr

a variable expression. You can partially bind indexes.

type

optional, either "primal" or "dual". The default value is "primal". If "primal" it returns the primal solution, otherwise the column duals. Especially the dual values depend on the solver. If no duals are calculated, the function stops with an error message.

Value

a data.frame. One row for each variable instance and a column for each index. Unless it is a single variable, then it returns a single number. Please note that in case of a data.frame there is no guarantee about the ordering of the rows. This could change in future ompr versions. Please always use the indexes to retrieve the correct values.

Examples

if (FALSE) {
library(magrittr)
result <- MIPModel() %>%
  add_variable(x[i], i = 1:5) %>%
  add_variable(y[i, j], i = 1:5, j = 1:5) %>%
  add_constraint(x[i] >= 1, i = 1:5) %>%
  set_bounds(x[i], lb = 3, i = 1:3) %>%
  set_objective(0) %>%
  solve_model(with_ROI("glpk"))
solution <- get_solution(result, x[i])
solution2 <- get_solution(result, y[i, 1])
solution3 <- get_solution(result, y[i, j])
duals <- get_solution(result, x[i], type = "dual")
}