Skip to content

Commit

Permalink
jump example
Browse files Browse the repository at this point in the history
  • Loading branch information
montyvesselinov committed Jun 23, 2017
1 parent 060e337 commit 4bdb41c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion examples/learn_julia/jump.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,22 @@ function testme()
JuMP.solve(m)
end

testme()
@generated function testme2{nvar}(::Type{Val{nvar}}, t::Vector)
myfcall = macroexpand(:(@Base.Cartesian.ncall $nvar myf i->x[i]))
q = quote
nvar = length(t)
function myf(a...)
sum((collect(a).-t).^2)
end
m = JuMP.Model(solver=Ipopt.IpoptSolver())
JuMP.register(m, :myf, nvar, myf, autodiff=true)
@JuMP.variable(m, x[1:nvar], start=rand())
@JuMP.NLobjective(m, Min, $myfcall)
JuMP.solve(m)
return JuMP.getvalue(x)
end
return q
end

testme2(Val{12}, rand(12))
# testme()

0 comments on commit 4bdb41c

Please sign in to comment.