Skip to content
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

WIP: SDDiP #237

Merged
merged 23 commits into from
Aug 26, 2019
Merged

WIP: SDDiP #237

merged 23 commits into from
Aug 26, 2019

Conversation

lkapelevich
Copy link
Contributor

@lkapelevich lkapelevich commented Jun 19, 2019

  • handle integer state variables (bug somewhere atm)
  • handle continuous state variables
  • remove all the ext[:issddip]=true and find a nice way to distinguish for a node/subproblem that we want Lagrangian duals (half done)
  • improve the code for calculating duals, better initial values, get rid of extra vectors being created
  • remove manifest
  • move over remaining examples
  • pass the SDDP model's solver through to Kelley's method
  • remove the speed stuff from the binary expansion code, unnecessary
  • raise an issue: state variables are assumed to be nonnegative here just mentioned in docstrings
  • allow user to set epsilon in continuous state variables
    closes SDDiP #195 and Complete rewrite lkapelevich/SDDiP.jl#21

@lkapelevich lkapelevich changed the title SDDiP WIP: SDDiP Jun 19, 2019
examples/air_conditioning.jl Outdated Show resolved Hide resolved
src/user_interface.jl Outdated Show resolved Hide resolved
@odow
Copy link
Owner

odow commented Jun 19, 2019

handle integer state variables (bug somewhere atm)
handle continuous state variables

@variable(sp, x, SDDP.SDDiP.BinaryState(), initial_value = 1.0)
@variable(sp, 0 <= x <= 10, SDDP.SDDiP.ContinuousState(), initial_value = 1.0)
@variable(sp, 0 <= x <= 10, SDDP.SDDiP.IntegerState(), initial_value = 1.0)

remove all the ext[:issddip]=true and find a nice way to distinguish for a node/subproblem that we want Lagrangian duals

See previous comment. Make the new JuMP variable types and set :issddip in add_variable.

Bonus points for including a way to check for SDDP.State variables that have been added and throw an error if :issddip is set.

improve the code for calculating duals, better initial values, get rid of extra vectors being created

👍

remove manifest

Why is it needed at the moment?

move over remaining examples

More the merrier.

@lkapelevich
Copy link
Contributor Author

Why is it needed at the moment?

It's not, I pushed it without realizing

@lkapelevich
Copy link
Contributor Author

So by the SDDP.SDDiP.ContinuousState(), I take it you imagining this being a plugin/submodule? I think everything here can easily be moved, except the most invasive part here:

if !node.ext[:issddip]

which relies on SDDP knowing about SDDiP, and I couldn't think of how to get this working without changing code algorithm.jl, or else parameterizing Node. So would you parameterize Node by the type of states it has (SDDP vs SDDiP)?

There is also minor gotcha here

if !haskey(model.nodes[1].ext, :issddip)
.
but basically we just need to tell a Node whether it will be involved in SDDiP.

@odow
Copy link
Owner

odow commented Jul 1, 2019

It doesn't have to be a submodule. You could also go SDDP.SDDiPState(). But having almost everything self-contained in a single file would be nice.

I don't really want to parameterize Node. Instead, one argument for including SDDiP in the package is so that we can have tighter interactions like you describe instead of splitting everything into lots of different packages. That said, you might be able to make an over-loadable version of get_dual_variables somehow.

@lkapelevich
Copy link
Contributor Author

After a think, I don't think there is a reason to introduce SDDiPState or similar unless you really like it as the interface. A user will either use SDDiP, in which case all variables need to be binary-fied, or they will not. So it's easier to just have a single switch for any state variables added, a keyword argument SDDiP = true in PolicyGraph will do everything necessary I think.

@odow
Copy link
Owner

odow commented Jul 1, 2019

Is it possible to add the keyword to train? Then the default remains as-is, and we can solve the LP relaxation. You could even pass in a type, add it to Options and then use it to dispatch on any methods you need to overload.

abstract type AbstractSMIPSolver end
struct ContinuousRelaxation <: AbstractSMIPSolver end
struct SDDiP <: AbstractSMIPSolver end
struct MyCoolNewSolver <: AbstractSMIPSolver end

SDDP.train(model, integrality_method = SDDP.SDDiP())

(Edit: although, then we get in trouble if you try to solve multiple times. Maybe an argument to PolicyGraph is best.)

@lkapelevich
Copy link
Contributor Author

lkapelevich commented Jul 1, 2019

Oops I pushed before reading the comment

Edit: I'll think about the keyword to train

@lkapelevich
Copy link
Contributor Author

What exactly is the problem you see if we try to solve multiple times? If the keyword is added to train then the approach would be to not modify add_variable but instead in train, loop over all nodes and add new binary variables, then proceed with sddp. We would need to flag nodes once the extra variables have been added so that if we train multiple times the variables don't get added again. Were you thinking of something else?

@odow
Copy link
Owner

odow commented Jul 6, 2019

Basically I would worry that someone would go

SDDP.train(model, integrality_method = SDDP.SDDiP(), iteration_limit = 10)
SDDP.train(model, integrality_method = SDDP.ContinuousRelaxation(), iteration_limit = 10)

Would anything problematic happen the second time?

@lkapelevich
Copy link
Contributor Author

lkapelevich commented Jul 6, 2019

Yes this is actually worse than what I was thinking, because the first train would add a bunch of new state variables that we don't want for the second train.

An argument to PolicyGraph is probably best.

examples/generation_expansion.jl Outdated Show resolved Hide resolved
examples/vehicle_location.jl Outdated Show resolved Hide resolved
src/MIP_utils.jl Outdated Show resolved Hide resolved
src/MIP_utils.jl Outdated Show resolved Hide resolved
src/user_interface.jl Outdated Show resolved Hide resolved
src/MIP_utils.jl Outdated Show resolved Hide resolved
examples/stochastic_all_blacks.jl Show resolved Hide resolved
examples/sddip.jl Outdated Show resolved Hide resolved
Copy link
Owner

@odow odow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good @lkapelevich. Modulo the test failures. But I guess you're on those.

src/algorithm.jl Show resolved Hide resolved
src/algorithm.jl Outdated Show resolved Hide resolved
src/binary_expansion.jl Outdated Show resolved Hide resolved
src/plugins/headers.jl Show resolved Hide resolved
src/plugins/headers.jl Outdated Show resolved Hide resolved
test/binary_expansion.jl Outdated Show resolved Hide resolved
src/user_interface.jl Outdated Show resolved Hide resolved
test/runtests.jl Outdated Show resolved Hide resolved
test/runtests.jl Outdated Show resolved Hide resolved
examples/sddip.jl Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 24, 2019

Codecov Report

Merging #237 into master will increase coverage by 0.25%.
The diff coverage is 96.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #237      +/-   ##
==========================================
+ Coverage   93.82%   94.07%   +0.25%     
==========================================
  Files          14       17       +3     
  Lines        1231     1351     +120     
==========================================
+ Hits         1155     1271     +116     
- Misses         76       80       +4
Impacted Files Coverage Δ
src/SDDP.jl 100% <ø> (ø) ⬆️
src/algorithm.jl 97.85% <100%> (+0.01%) ⬆️
src/user_interface.jl 97.52% <100%> (+0.25%) ⬆️
src/binary_expansion.jl 100% <100%> (ø)
src/plugins/headers.jl 83.33% <50%> (-16.67%) ⬇️
src/JuMP.jl 90.9% <90.9%> (ø)
src/plugins/integrality_handlers.jl 97.26% <97.26%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 12ef874...fd99920. Read the comment docs.

@odow
Copy link
Owner

odow commented Aug 24, 2019

Looks like you forgot to commit src/JuMP.jl.

@odow
Copy link
Owner

odow commented Aug 24, 2019

Great! The doc-test failures aren't your fault. The other PR's are also failing. I'm trying to fix it.

@odow
Copy link
Owner

odow commented Aug 24, 2019

If you rebase onto the latest master, the documentation should be fixed.

@lkapelevich
Copy link
Contributor Author

@odow anything else?

Copy link
Owner

@odow odow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great @lkapelevich!

The only other thing is some docs. If you have time, great. If you don't, I'll merge this as-is and add a TODO for some docs.

@lkapelevich
Copy link
Contributor Author

I don't want to spend time writing docs right now, but happy to answer questions for docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SDDiP
2 participants