Giter VIP home page Giter VIP logo

Comments (3)

tkelman avatar tkelman commented on June 30, 2024

Are you using the low-level interface? You can make a closure. If the function you want to write looks like eval_f(x, data) then just send x -> eval_f(x, data) as the function when you call createProblem. On Julia 0.5 that should be the same performance. On Julia 0.4 it might have a little bit of a performance penalty but for a large problem most of the time should be spent in the Ipopt linear algebra rather than function evaluations.

from ipopt.jl.

chegini avatar chegini commented on June 30, 2024

Thanks for the reply.
I am using Julia interface (5.0) . As you said I made a closure as follows:

function testfunc(x,data)
function eval_f(x,data)
println(data)
return x[1] * x[4] * (x[1] + x[2] + x[3]) + x[3]
end
return eval_f
end
.
.
.
global data = 10
prob = createProblem(n, x_L, x_U, m, g_L, g_U, 8, 10,
testfunc, eval_g, eval_grad_f, eval_jac_g, eval_h)
.
.
.

data is defined as a global variable. Now I have this error: Could you please tell what is wrong here?

ERROR: LoadError: MethodError: no method matching testFunc(::Array{Float64,1})
Closest candidates are:
testFunc(::Any, !Matched::Any) at /Users/fatimachegini/.julia/v0.5/Ipopt/example/hs071.jl:11
in eval_f_wrapper(::Int32, ::Ptr{Float64}, ::Int32, ::Ptr{Float64}, ::Ptr{Void}) at /Users/fatimachegini/.julia/v0.5/Ipopt/src/Ipopt.jl:89
in solveProblem(::Ipopt.IpoptProblem) at /Users/fatimachegini/.julia/v0.5/Ipopt/src/Ipopt.jl:304
in include_from_node1(::String) at ./loading.jl:426
in include_from_node1(::String) at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
in process_options(::Base.JLOptions) at ./client.jl:262
in _start() at ./client.jl:318
in _start() at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
while loading /Users/fatimachegini/.julia/v0.5/Ipopt/example/hs071.jl, in expression starting on line 113

from ipopt.jl.

chegini avatar chegini commented on June 30, 2024

Hi,
I defined the data as a global variable, now it works. 👍

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.