Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieving the basis solution #444

Closed
matheusdiogenesandrade opened this issue Feb 25, 2024 · 2 comments
Closed

Retrieving the basis solution #444

matheusdiogenesandrade opened this issue Feb 25, 2024 · 2 comments

Comments

@matheusdiogenesandrade
Copy link

Hello.

I am trying to obtain the status of variables in the basis solution. The issue covered this topic with a previous version of this package. But, it seems that the proposed solution doesn't work for the current package version, so, I took the time to try to write my own function for this, but I am struggling in the step for retrieving the corresponding variables mapping.

For instance, let's consider the following use case.

model = direct_model(CPLEX.Optimizer())
@variable(model, y[["a", "b"]])
# constraints

optimize!(model)

c_basis, r_basis = get_basis(model)

# c_basis["a"] =  CPX_AT_LOWER	        0	variable y["a"] at lower bound
#                 CPX_BASIC	        1	variable y["a"] is basic
#                 CPX_AT_UPPER	        2	variable y["a"] at upper bound
#                 CPX_FREE_SUPER	3	variable y["a"] free and nonbasic

A "partial snippet" is given below.

function get_basis(model::Model)
    cval = Vector{Cint}(num_variables(model))
    rval = Vector{Cint}(num_constraints(model))

    ret = CPXgetbase(model.moi_backend.env, model.moi_backend.lp, cval, rval)
    ret != 0 && throw(PROPEREXCEPTION(model.moi_backend.env, ret))
    # ...
end

I would like to know how I could complete the above function.

Thanks and regards.

@odow
Copy link
Member

odow commented Feb 25, 2024

See https://jump.dev/JuMP.jl/dev/tutorials/linear/basis/

There is no need to use the low-level C API.

If you have more questions, please post on the Discourse forum: https://discourse.julialang.org/c/domain/opt/13

@odow odow closed this as completed Feb 25, 2024
@matheusdiogenesandrade
Copy link
Author

See https://jump.dev/JuMP.jl/dev/tutorials/linear/basis/

There is no need to use the low-level C API.

If you have more questions, please post on the Discourse forum: https://discourse.julialang.org/c/domain/opt/13

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants