Skip to content

Commit

Permalink
Fix model pointer passed to callbacks (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Nov 29, 2023
1 parent 379220b commit c09d761
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
19 changes: 8 additions & 11 deletions src/C_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,7 @@ function _newpt_wrapper(
@_checked KN_get_number_cons(model, nc)
x = unsafe_wrap(Array, ptr_x, nx[])
lambda = unsafe_wrap(Array, ptr_lambda, nx[] + nc[])
# TODO: should `model` arugment be `ptr_model`?
return model.newpt_callback(model, x, lambda, model.newpt_user_data)
return model.newpt_callback(ptr_model, x, lambda, model.newpt_user_data)
end
end

Expand All @@ -591,7 +590,7 @@ solution point (that is, after every iteration).
`callback` is a function with signature:
```julia
callback(kc::Model, x::Vector{Cdouble}, lambda::Vector{Cdouble}, user_data::Any) -> Cint
callback(kc::Ptr, x::Vector{Cdouble}, lambda::Vector{Cdouble}, user_data::Any) -> Cint
```
## Notes
Expand Down Expand Up @@ -629,8 +628,7 @@ function _ms_process_wrapper(
@_checked KN_get_number_cons(model, nc)
x = unsafe_wrap(Array, ptr_x, nx[])
lambda = unsafe_wrap(Array, ptr_lambda, nx[] + nc[])
# TODO: should `model` arugment be `ptr_model`?
return model.ms_process_callback(model, x, lambda, model.ms_process_user_data)
return model.ms_process_callback(ptr_model, x, lambda, model.ms_process_user_data)
end
end

Expand All @@ -646,7 +644,7 @@ processing a multistart solve.
`callback` is a function with signature:
```julia
callback(kc::Model, x::Vector{Cdouble}, lambda::Vector{Cdouble}, user_data::Any) -> Cint
callback(kc::Ptr, x::Vector{Cdouble}, lambda::Vector{Cdouble}, user_data::Any) -> Cint
```
## Notes
Expand Down Expand Up @@ -681,8 +679,7 @@ function _mip_node_callback_wrapper(
@_checked KN_get_number_cons(model, nc)
x = unsafe_wrap(Array, ptr_x, nx[])
lambda = unsafe_wrap(Array, ptr_lambda, nx[] + nc[])
# TODO: should `model` arugment be `ptr_model`?
return model.mip_node_callback(model, x, lambda, model.mip_node_user_data)
return model.mip_node_callback(ptr_model, x, lambda, model.mip_node_user_data)
end
end

Expand All @@ -699,7 +696,7 @@ procedure).
`callback` is a function with signature:
```julia
callback(kc::Model, x::Vector{Cdouble}, lambda::Vector{Cdouble}, user_data::Any) -> Cint
callback(kc::Ptr, x::Vector{Cdouble}, lambda::Vector{Cdouble}, user_data::Any) -> Cint
```
## Notes
Expand Down Expand Up @@ -735,7 +732,7 @@ function _ms_initpt_wrapper(
x = unsafe_wrap(Array, ptr_x, nx[])
lambda = unsafe_wrap(Array, ptr_lambda, nx[] + nc[])
return model.ms_initpt_callback(
model,
ptr_model,
nSolveNumber,
x,
lambda,
Expand All @@ -753,7 +750,7 @@ in the multistart procedure.
```julia
callback(
model::Model,
kc::Ptr,
nSolveNumber::Cint,
x::Vector{Cdouble},
lambda::Vector{Cdouble},
Expand Down
2 changes: 1 addition & 1 deletion test/knitroapi_licman.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using Test
end

function newpt_callback(kc, x::Vector{Cdouble}, lambda::Vector{Cdouble}, user_data)
@test kc isa KNITRO.Model
@test kc isa Ptr{Cvoid}
return 0
end

Expand Down

2 comments on commit c09d761

@odow
Copy link
Member Author

@odow odow commented on c09d761 Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/96172

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.0 -m "<description of version>" c09d76198daf998d5782dd184fabfbcd46719f3e
git push origin v0.14.0

Please sign in to comment.