I am trying to extract the variable coefficients in a constraint. According to Gurobi documentation, https://www.gurobi.com/documentation/9.1/refman/py_model_getcoeff.html, the function Model.getCoeff() should do the trick. However, this does not exist in Gurobi Julia package. The closest one I get is Gurobi.getcoeff(model::Gurobi.Model , cidx::Integer , vidx::Integer) at Gurobi\7YNJV\src\grb_constrs.jl:367. However, I can not make it work.
For example, in the following minimal code:
using Gurobi
using JuMP
# define a simple UC problem
n_u = 5
n_t = 3
U = collect(1:n_u) # num units
T = collect(1:n_t) # num time steps
p_g_min = round.(0.0*rand(n_u), digits=2)
p_g_max = 1 .+ round.(rand(n_u), digits=2)
cost_g = 10 .+ round.(10.0*rand(n_u), digits=1)
cost_g0 = round.(1.0*rand(n_u), digits=1)
d0 = rand((sum(p_g_min):.01:.6*sum(p_g_max)),n_t)
# basic_uc_model = Model(Gurobi.Optimizer)
basic_uc_model = direct_model(Gurobi.Optimizer())
@variable(basic_uc_model, p_g_min[i] <= p_g[i in U, t in T] <= p_g_max[i])
@variable(basic_uc_model, 0 <= I_g[i in U, t in T] <= 1)
@constraint(basic_uc_model, lower_band[i in U, t in T], p_g[i,t] >= p_g_min[i]*I_g[i,t])
@constraint(basic_uc_model, upper_band[i in U, t in T], p_g[i,t] <= p_g_max[i]*I_g[i,t])
@constraint(basic_uc_model, demand[t in T], sum(p_g[i,t] for i in U) == d0[t])
@objective(basic_uc_model, Min, sum(p_g[i,t]*cost_g[i] + I_g[i,t]*cost_g0[i] for i in U, t in T))
set_optimizer_attribute(basic_uc_model, "PoolSearchMode", 1)
optimize!(basic_uc_model)
Gurobi.getcoeff(basic_uc_model, lower_band[1,1], p_g[1,1])
Error: MethodError: no method matching getcoeff(::Model, ::ConstraintRef{Model,MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.GreaterThan{Float64}},ScalarShape}, ::VariableRef)
in top-level scope at test_gurobi.jl:42
I think I am not using the correct formatting and I am not sure about cidx and vidx. I would appreciate any help.