@@ -200,18 +200,18 @@ Parameter:
200200"""
201201function build_terminal_cost! (model:: SPModel , problem:: JuMP.Model , Vt:: PolyhedralFunction )
202202 # if shape is PolyhedralFunction, build terminal cost with it:
203- alpha = getVar (problem, :alpha )
204- x = getVar (problem, :x )
205- u = getVar (problem, :u )
206- w = getVar (problem, :w )
203+ alpha = getvariable (problem, :alpha )
204+ x = getvariable (problem, :x )
205+ u = getvariable (problem, :u )
206+ w = getvariable (problem, :w )
207207 t = model. stageNumber - 1
208208 if isa (Vt, PolyhedralFunction)
209209 for i in 1 : Vt. numCuts
210210 lambda = vec (Vt. lambdas[i, :])
211- @addConstraint (problem, Vt. betas[i] + dot (lambda, model. dynamics (t, x, u, w)) <= alpha)
211+ @constraint (problem, Vt. betas[i] + dot (lambda, model. dynamics (t, x, u, w)) <= alpha)
212212 end
213213 else
214- @addConstraint (problem, alpha >= 0 )
214+ @constraint (problem, alpha >= 0 )
215215 end
216216end
217217
@@ -247,26 +247,26 @@ function build_models(model::SPModel, param::SDDPparameters)
247247 nu = model. dimControls
248248 nw = model. dimNoises
249249
250- @defVar (m, model. xlim[i][1 ] <= x[i= 1 : nx] <= model. xlim[i][2 ])
251- @defVar (m, model. ulim[i][1 ] <= u[i= 1 : nu] <= model. ulim[i][2 ])
252- @defVar (m, model. xlim[i][1 ] <= xf[i= 1 : nx]<= model. xlim[i][2 ])
253- @defVar (m, alpha)
250+ @variable (m, model. xlim[i][1 ] <= x[i= 1 : nx] <= model. xlim[i][2 ])
251+ @variable (m, model. ulim[i][1 ] <= u[i= 1 : nu] <= model. ulim[i][2 ])
252+ @variable (m, model. xlim[i][1 ] <= xf[i= 1 : nx]<= model. xlim[i][2 ])
253+ @variable (m, alpha)
254254
255- @defVar (m, w[1 : nw] == 0 )
256- m. ext[:cons ] = @addConstraint (m, state_constraint, x .== 0 )
255+ @variable (m, w[1 : nw] == 0 )
256+ m. ext[:cons ] = @constraint (m, state_constraint, x .== 0 )
257257
258- @addConstraint (m, xf .== model. dynamics (t, x, u, w))
258+ @constraint (m, xf .== model. dynamics (t, x, u, w))
259259
260260 if typeof (model) == LinearDynamicLinearCostSPmodel
261- @setObjective (m, Min, model. costFunctions (t, x, u, w) + alpha)
261+ @objective (m, Min, model. costFunctions (t, x, u, w) + alpha)
262262
263263 elseif typeof (model) == PiecewiseLinearCostSPmodel
264- @defVar (m, cost)
264+ @variable (m, cost)
265265
266266 for i in 1 : length (model. costFunctions)
267- @addConstraint (m, cost >= model. costFunctions[i](t, x, u, w))
267+ @constraint (m, cost >= model. costFunctions[i](t, x, u, w))
268268 end
269- @setObjective (m, Min, cost + alpha)
269+ @objective (m, Min, cost + alpha)
270270 end
271271
272272 models[t] = m
@@ -310,10 +310,13 @@ function initialize_value_functions( model::SPModel,
310310 # Build scenarios according to distribution laws:
311311 aleas = simulate_scenarios (model. noises, param. forwardPassNumber)
312312
313- V[end ] = model. finalCost
314-
315313 # Add final costs to solverProblems:
316- build_terminal_cost! (model, solverProblems[end ], V[end ])
314+ if isa (model. finalCost, PolyhedralFunction)
315+ V[end ] = model. finalCost
316+ build_terminal_cost! (model, solverProblems[end ], V[end ])
317+ elseif isa (model. finalCost, Function)
318+ model. finalCost (model, solverProblems[end ])
319+ end
317320
318321 stockTrajectories = forward_simulations (model,
319322 param,
@@ -353,9 +356,16 @@ function hotstart_SDDP(model::SPModel, param::SDDPparameters, V::Vector{Polyhedr
353356
354357 solverProblems = build_models (model, param)
355358
356- for t in 1 : model. stageNumber- 1
359+ for t in 1 : model. stageNumber- 2
357360 add_cuts_to_model! (model, t, solverProblems[t], V[t+ 1 ])
358361 end
362+
363+ # Take care of final cost:
364+ if isa (model. finalCost, PolyhedralFunction)
365+ add_cuts_to_model! (model, model. stageNumber- 1 , solverProblems[end ], V[end ])
366+ else
367+ model. finalCost (model, solverProblems[end ])
368+ end
359369 return solverProblems
360370end
361371
@@ -388,16 +398,16 @@ function get_bellman_value(model::SPModel, param::SDDPparameters,
388398 t:: Int64 , Vt:: PolyhedralFunction , xt:: Vector{Float64} )
389399
390400 m = Model (solver= param. solver)
391- @defVar (m, alpha)
401+ @variable (m, alpha)
392402
393403 for i in 1 : Vt. numCuts
394404 lambda = vec (Vt. lambdas[i, :])
395- @addConstraint (m, Vt. betas[i] + dot (lambda, xt) <= alpha)
405+ @constraint (m, Vt. betas[i] + dot (lambda, xt) <= alpha)
396406 end
397407
398- @setObjective (m, Min, alpha)
408+ @objective (m, Min, alpha)
399409 solve (m)
400- return getValue (alpha)
410+ return getvalue (alpha)
401411end
402412
403413
@@ -474,14 +484,14 @@ Parameters:
474484
475485"""
476486function add_cuts_to_model! (model:: SPModel , t:: Int64 , problem:: JuMP.Model , V:: PolyhedralFunction )
477- alpha = getVar (problem, :alpha )
478- x = getVar (problem, :x )
479- u = getVar (problem, :u )
480- w = getVar (problem, :w )
487+ alpha = getvariable (problem, :alpha )
488+ x = getvariable (problem, :x )
489+ u = getvariable (problem, :u )
490+ w = getvariable (problem, :w )
481491
482492 for i in 1 : V. numCuts
483493 lambda = vec (V. lambdas[i, :])
484- @addConstraint (problem, V. betas[i] + dot (lambda, model. dynamics (t, x, u, w)) <= alpha)
494+ @constraint (problem, V. betas[i] + dot (lambda, model. dynamics (t, x, u, w)) <= alpha)
485495 end
486496end
487497
@@ -547,19 +557,19 @@ Return:
547557function is_cut_relevant (model:: SPModel , k:: Int , Vt:: PolyhedralFunction , solver)
548558
549559 m = Model (solver= solver)
550- @defVar (m, alpha)
551- @defVar (m, model. xlim[i][1 ] <= x[i= 1 : model. dimStates] <= model. xlim[i][2 ])
560+ @variable (m, alpha)
561+ @variable (m, model. xlim[i][1 ] <= x[i= 1 : model. dimStates] <= model. xlim[i][2 ])
552562
553563 for i in 1 : Vt. numCuts
554564 if i!= k
555565 lambda = vec (Vt. lambdas[i, :])
556- @addConstraint (m, Vt. betas[i] + dot (lambda, x) <= alpha)
566+ @constraint (m, Vt. betas[i] + dot (lambda, x) <= alpha)
557567 end
558568 end
559569
560570 λ_k = vec (Vt. lambdas[k, :])
561- @setObjective (m, Min, alpha - dot (λ_k, x) - Vt. betas[k])
571+ @objective (m, Min, alpha - dot (λ_k, x) - Vt. betas[k])
562572 solve (m)
563- return getObjectiveValue (m) < 0.
573+ return getobjectivevalue (m) < 0.
564574end
565575
0 commit comments