Giter VIP home page Giter VIP logo

Comments (6)

mlubin avatar mlubin commented on August 16, 2024

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.

rgiordan avatar rgiordan commented on August 16, 2024

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.

IainNZ avatar IainNZ commented on August 16, 2024

Try prev_x[:] = x[:], that way it replaces the "global" prev_x instead of rebinding the name.

from ipopt.jl.

IainNZ avatar IainNZ commented on August 16, 2024

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.

rgiordan avatar rgiordan commented on August 16, 2024

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.

mlubin avatar mlubin commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.