Replies: 3 comments 1 reply
-
I think the default initial guess is 0 for ipopt which likely causes invalid number for log(c). If you use log(c + 1.0e-5), then the code works. |
Beta Was this translation helpful? Give feedback.
-
@notesofdabbler is correct, the default guess for @variable(m, c, Infinite(t), start = 1) This modification resolves the problem. |
Beta Was this translation helpful? Give feedback.
-
@notesofdabbler @pulsipher Thank you!
using InfiniteOpt, Ipopt
ρ = 0.025 # discount rate
T = 10.0 # life horizon
r = 0.05 # interest rate
B0 = 100.0 # endowment
function f(γ)
u(c) = ( c^(1- γ) ) / (1- γ)
discount(t; ρ=ρ) = exp(-ρ*t) # discount function
BC(B, c; r=r) = r*B - c # budget constraint
opt = Ipopt.Optimizer # desired solver
ns = 1_000; # number of points in the time grid
m = InfiniteModel(opt)
@infinite_parameter(m, t in [0, T], num_supports = ns)
@variable(m, B, Infinite(t)) ## state variables
@variable(m, c, Infinite(t), start = 1) ## control variables. Initial guess c(t)=1. Ipopt default initial guess c(t)=1.
@objective(m, Max, integral(u(c), t, weight_func = discount))
@constraint(m, B(0) == B0)
@constraint(m, B(T) == 0)
@constraint(m, c1, deriv(B, t) == BC(B, c; r=r))
optimize!(m)
termination_status(m)
c_opt = value(c)
B_opt = value(B)
ts = supports(t)
opt_obj = objective_value(m) # V(B0, 0)
ix = 2:(length(ts)-1) # index for plotting
plot!(ts[ix], B_opt[ix], lab = "B: wealth balance")
plot!(ts[ix], c_opt[ix], lab = "c: consumption")
end
plot()
f(2.0 - .1) # correct
f(2.0 + .1) # correct
f(2.0 + 0) # wrong |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm trying to test out the nonlinear capabilities.
I repeated the example in the docs (except w/
log(c)
as the objective)The message:
Beta Was this translation helpful? Give feedback.
All reactions