Closed GabrielPonte closed 2 years ago
I don't know what the show
problem is (we're likely missing a method), but KNITRO doesn't support adding constraints after optimize!:
https://github.com/jump-dev/KNITRO.jl/blob/d91f31830578e9928ab87320e53b3b8c62a2f2ca/src/MOI_wrapper/constraints.jl#L145-L150
One solution is to use a caching optimizer:
model = MOI.Utilities.CachingOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
KNITRO.Optimizer(),
)
Thanks, I replaced optimizer = KNITRO.Optimizer()
to
optimizer = MOI.Utilities.CachingOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
KNITRO.Optimizer(),
)
but I got this error
UndefVarError: automatic_copy_to not defined
Stacktrace:
[1] getproperty
@ .\Base.jl:35 [inlined]
[2] copy_to(model::KNITRO.Optimizer, src::MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}})
@ KNITRO C:\Users\gabponte\.julia\packages\KNITRO\6cfYO\src\MOI_wrapper.jl:206
[3] optimize!
@ C:\Users\gabponte\.julia\packages\MathOptInterface\kCmJV\src\MathOptInterface.jl:86 [inlined]
[4] optimize!(m::MathOptInterface.Utilities.CachingOptimizer{KNITRO.Optimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}})
@ MathOptInterface.Utilities C:\Users\gabponte\.julia\packages\MathOptInterface\kCmJV\src\Utilities\cachingoptimizer.jl:316
[5] top-level scope
@ In[15]:23
[6] eval
@ .\boot.jl:373 [inlined]
[7] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1196
Actually, the main reason that I opened this issue is because I'm getting the same error using Juniper with KNITRO.jl. Should I open another issue in here?
No need to open another issue. There are a bunch of issues with the KNITRO wrapper that need fixing. We're mainly constrained because we don't have CI, although I hope to sort that today or tomorrow.
Thank you!
I was trying to use KNITRO with MOI, and I tested this example here using KNITRO.jl. I tried a Cutting Plane method, so after optimizing the model, I added the constraint below
MOI.add_constraint(optimizer,x[1],MathOptInterface.LessThan{Float64}(0.0));
And this caused the error:SYSTEM: show(lasterr) caused an error
I tried to use GLPK and the code worked with it. Here is the code that I usedAnd here is the log