-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
[style] naming wrapped c functions #1409
Comments
The intermediate |
Sorry, I have just noticed that I opened this issue in JuMP.jl instead of Cplex.jl |
I prefer There are lots of functions in Gurobi that have levels and levels of redicrection, for example If we made a style guide that the low-level function is to be called |
I agree with @odow about not having too many level of indirections. But this is an argument against naming functions PS: I assume that if we name a function |
MOI should not use the less specific function. It should use the Currently we are in the situation where there are lots of helper functions floating around that are not documented or well tested. It is also not obvious just be looking at the function name or the arguments which C function it ultimately ends up calling. We should be pushing people to use MOI / JuMP in direct mode rather than the low-level solver interfaces.
Yes. I would like to refactor the whole Gurobi.jl package to remove the unnecessary exports, simplify all the calls, and change all the C functions to |
I think I didn't explain well what I meant by the less specific wrapping function. Consider this simple example: #Solution 1
function get_var_lb(model::Model, col::Cint)
lb = Vector{Cdouble}(1)
@cpx_ccall(getlb, Cint, ( Ptr{Void}, Ptr{Void}, Ptr{Cdouble}, Cint, Cint),
model.env.ptr, model.lp, lb, col-Cint(1), col-Cint(1))
return lb[1]
end
function LQOI.get_variable_lowerbound(model::Optimizer, column::Int)
get_var_lb(model.inner, Cint(column))
end
The other solution forces the wrapping function to offer the full functionality as the C function and restrict it later either by using a helper function (solution 2A) or by increasing the complexity in all the calling functions (solution 2B). #Solution 2A
function c_api_getlb(model::Model, col_start::Cint, col_end::Cint)
lb = Vector{Cdouble}(1)
@cpx_ccall(getlb, Cint, ( Ptr{Void}, Ptr{Void}, Ptr{Cdouble}, Cint, Cint),
model.env.ptr, model.lp, lb, col_start - Cint(1), col_end-Cint(1))
return lb[1]
end
function get_var_lb(model::Model, col::Cint)
return get_var_lb(model.inner, Cint(column), Cint(column))
end
function LQOI.get_variable_lowerbound(model::Optimizer, column::Int)
return get_var_lb(model.inner, Cint(column))
end #Solution 2B
function c_api_getlb(model::Model, col_start::Cint, col_end::Cint)
lb = Vector{Cdouble}(1)
@cpx_ccall(getlb, Cint, ( Ptr{Void}, Ptr{Void}, Ptr{Cdouble}, Cint, Cint),
model.env.ptr, model.lp, lb, col_start - Cint(1), col_end-Cint(1))
return lb[1]
end
function LQOI.get_variable_lowerbound(model::Optimizer, column::Int)
get_var_lb(model.inner, Cint(column), Cint(column))
end There is a 3rd solution that I'd exclude which is to keep solution 1 but only rename So which solution exactly you prefer? I prefer solution 1 because it leaves the flexibility for the developer of the wrapping function to use or not the same functionality as the C API. |
I would prefer the following for a few reasons:
"""
c_api_getlb(model::Model, dest, column_start::Int, column_end::Int)
Get the lower bounds of a list of contiguous variables in the (one-indexed)
columns `column_start` to `column_end`, and store the result in `dest`.
If `column_start != column_end`, `dest` must be a `Vector{Float64}` with length
`column_end - column_start + 1`. If `column_start == column_end`, then it is
more efficient to pass `dest` as `Ref{Float64}()`, since this avoids
constructing a one-element array.
"""
function c_api_getlb(model::Model, dest, column_start::Int, column_end::Int)
@assert length(dest) == column_end - column_start + 1
stat = @cpx_ccall(getlb, Cint,
(Ptr{Void}, Ptr{Void}, Ptr{Cdouble}, Cint, Cint),
model.env.ptr, model.lp, dest, column_start-1, column_end-1)
if stat != 0
throw(CplexError(model.env, stat))
end
end
function LQOI.get_variable_lower_bound(model::Optimizer, column::Int)
lower_bound = Ref{Float64}()
c_api_getlb(model.inner, lower_bound, column, column)
return lower_bound[]
end |
The only thing I am saying is that : Those two are really advantages of solution2
But those 2 are not.
You could choose to have the exact same code you have written, with the name However, I agree that the first two advantages are probably strong enough to go for solution2, Although I d keep the flexibility of using solution2A (with helper functions) when the complexity in the calling functions is substantial. |
Exactly :) This is what I want. Let's move the complexity away from the C API wrapper, and into the (hopefully) well tested LQOI interface functions. To avoid going back and forth with the same points, perhaps we should let others weigh in to see what they think. |
If there are no objections on this by tomorrow, I'll go with what we agreed on :) |
I'm not sure we have agreed on this...? |
I thought yes. we go with |
* MOI/LQOI support for ILP * style fixing * updates following jump-dev/JuMP.jl#1409 * making c_api_getrhs in place * fixes thanks to @odow comments * a few fixes * removed a useless `using` * enabled name test
Cplex has
cpxchgsense
The corresponding julia function should be
chg_sense
orchgsense
?The text was updated successfully, but these errors were encountered: