Comments (6)
This is easy and cheap to emulate by storing the previous input vector and checking if it's equal to the new one. We'd accept a PR for this, but anyway I'd recommend coding to the MathProgBase interface which would let you easily switch between solvers (Ipopt, KNITRO, NLopt).
from ipopt.jl.
Ok, thank you, I'll look into MathProgBase. For my own understanding, how would you store the previous value? I can't seem to access variables outside the scope of eval functions. (An example is below.)
using Ipopt
prev_x = zeros(2)
prev_v = 0.0
function eval_f(x::Vector{Float64})
if (x == prev_x)
return prev_v
else
prev_x = x
prev_v = x[1]^2 + x[2]^2
end
prev_v
end
function eval_grad_f(x::Vector{Float64}, grad_f::Vector{Float64})
grad_f[1] = 2 * x[1]
grad_f[2] = 2 * x[2]
end
function intermediate(alg_mod::Int, iter_count::Int,
obj_value::Float64, inf_pr::Float64, inf_du::Float64, mu::Float64,
d_norm::Float64, regularization_size::Float64, alpha_du::Float64, alpha_pr::Float64,
ls_trials::Int)
println("Iteration $iter_count, objective value is $obj_value.")
return true
end
n = 2
x_L = [1.0, 1.0]
x_U = [2.0, 2.0]
function eval_no_jac_g(x, mode, rows, cols, values)
end
function eval_no_g(x, g)
end
prob = createProblem(n, x_L, x_U, 0, Array(Float64, 0), Array(Float64, 0), 0, 2,
eval_f, eval_no_g, eval_grad_f, eval_no_jac_g)
addOption(prob, "hessian_approximation", "limited-memory")
prob.x = [1.5, 2.5]
stat = solveProblem(prob)
# Gives the error:
# ERROR: prev_x not defined
# in eval_f at none:2
# in eval_f_wrapper at /home/rgiordan/.julia/v0.3/Ipopt/src/Ipopt.jl:86
from ipopt.jl.
Try prev_x[:] = x[:]
, that way it replaces the "global" prev_x
instead of rebinding the name.
from ipopt.jl.
If you look in the source you'll see that I did wrap the C interface, including new_x
, already. However, I punted on exposing it to user-facing code because I didn't know how I wanted it to look in Julia and I didn't have a need for it.
from ipopt.jl.
Thanks, using the brackets to refer to the global prev_x
works fine. Unless I'm mistaken, using some sort of similar global variable trick will also be necessary with MathProgBase
.
Yes, I noticed that you had new_x
in the C interface but hadn't exposed it to Julia.
from ipopt.jl.
It's not very well documented at this point, but you wouldn't use globals with MathProgBase, you would store the vector inside your NLPEvaluator object, so there's no type inference/performance issues to worry about. See the discussion here: JuliaNLSolvers/Optim.jl#107
from ipopt.jl.
Related Issues (20)
- Linking full hsl library to Ipopt.jl on ubuntu HOT 19
- julia 0.6.0 install Ipopt cannot connect to mumps dependency HOT 2
- Add support for GetIpoptCurrentViolations
- Incorrect number of Hessian structure (nonzero entries) HOT 10
- Does Ipopt.jl support giving hessian matrix in JuMP directly, without using the C_wrapper? HOT 2
- pointer being freed was not allocated HOT 33
- Invalid number in NLP function or derivative detected. HOT 8
- Issue with non-negative variable tolerance. HOT 2
- does not allow Ipopt_jll current version HOT 2
- Add some pre-built "debugging" callbacks HOT 1
- Crash on Windows when optimizing with SPRAL_jll HOT 11
- Using Ipopt in parallel threads HOT 4
- "double free or corruption" when providing duplicate hessian entries via MathOptInterface HOT 4
- Parsing an NLP HOT 1
- Ipopt does not print in Jupyter notebooks HOT 4
- Get number of iterations after optimization HOT 3
- Add way to change AD backend
- Cannot be installed properly on Alpine Linux which is a MUSL based distro HOT 7
- [email protected] is slower than [email protected] HOT 18
- ERROR: LoadError: ReadOnlyMemoryError() HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ipopt.jl.