-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a settable optimize_hook with access to the current scenario. #219
Conversation
Codecov Report
@@ Coverage Diff @@
## master #219 +/- ##
==========================================
- Coverage 93.3% 93.27% -0.03%
==========================================
Files 11 12 +1
Lines 1075 1101 +26
==========================================
+ Hits 1003 1027 +24
- Misses 72 74 +2
Continue to review full report at Codecov.
|
Can I use this to add new restriction before/after each iteration? I'd like to add DC powerflow active losses as "cuts" iterative. Could you give an example of how to use the pre-/post-optimize hook? |
The current example is here: Lines 150 to 176 in 9b5ebc9
For each node in the tree, you can add a hook. To loop through nodes, you can go for (index, node) in model.nodes
# add hook
end
function my_pre_optimize_hook(model, node, state, noise, scenario_path, require_duals)
sp = node.subproblem
active_loss_constraint = @constraint(sp, sp[:x] <= 1)
return active_loss_constraint
end
function my_post_optimize_hook(ret)
# `ret` is the `active_loss_constraint` reference returned from `my_pre_optimize_hook`
println("Active loss constraint = $(ret)")
return
end
for (index, node) in model.nodes
SDDP.pre_optimize_hook(my_pre_optimize_hook, node)
SDDP.post_optimize_hook(my_post_optimize_hook, node)
end Note that Lines 293 to 295 in 9b5ebc9
|
No description provided.