-
Notifications
You must be signed in to change notification settings - Fork 81
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
Document how to use C API #412
Comments
Use Using the C API is an advanced an largely undocumented feature. You need to use JuMP in direct mode: using JuMP, Gurobi
const GRB_ENV = Gurobi.Env()
model = direct_model(Gurobi.Optimizer(GRB_ENV))
@variable(model, 0 <= y <= 2.5, Int)
@objective(model, Max, y)
optimize!(model)
grb = backend(model)
p = Ref{Cdouble}()
Gurobi.GRBgetdblattr(grb, "ObjBound", p) |
I'll leave this issue open as a reminder we need to better document this. |
Sounds good! Thanks for your help. |
Hi, @odow I wonder is there a convenient way to call the general constraints from Gurobi, e.g., julia> import MathOptInterface as MOI
julia> import Gurobi
julia> const GRB_ENV = Gurobi.Env()
Set parameter Username
Academic license - for non-commercial use only - expires 2024-08-09
Gurobi.Env(Ptr{Nothing} @0x000001fe29b2f6d0, false, 0)
julia> o = Gurobi.Optimizer(GRB_ENV);
julia> x,sin_x = MOI.add_variable(o),MOI.add_variable(o) # input 5
(MOI.VariableIndex(1), MOI.VariableIndex(2))
julia> error_code = Gurobi.GRBaddgenconstrSin(o, "sin_constr", 1, 2, "") # input 6
10006 # probably means GRB_ERROR_INDEX_OUT_OF_RANGE Can we just model as usual (up to input 5) conveniently with the help of MOI, and we insert such a C-API portion as in input 6? To be more specific, the intention is to build a constraint Thanks! |
For the columns, you need to use a 0-indexed import MathOptInterface as MOI
import Gurobi
model = Gurobi.Optimizer()
x, sin_x = MOI.add_variables(model, 2)
Gurobi.GRBaddgenconstrSin(
model,
"sin_constr",
Cint(Gurobi.column(model, x) - 1),
Cint(Gurobi.column(model, sin_x) - 1),
"",
) |
I've added a minimal amount of documentation here: #526 |
Hello,
I am attempting to get the lower bound from an integer program using the Gurobi C API. Here is my example
When I run this code I get the following error:
I am not sure if my code is incorrect or if there is a bug here. Any help you can provide would be much appreciated.
The text was updated successfully, but these errors were encountered: