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

Cycle policy condition on t #799

Closed
Thuener opened this issue Nov 4, 2024 · 3 comments
Closed

Cycle policy condition on t #799

Thuener opened this issue Nov 4, 2024 · 3 comments

Comments

@Thuener
Copy link
Collaborator

Thuener commented Nov 4, 2024

I am working on an inventory problem, and I have some constraints that are just for the initial stages, but I'm using a cycle policy.
For example, imagine a problem with 12 nodes (or months) that I have a constraint that is different for the first 4 stages.

if t <= 4
    @constraint(sp, A)
else 
    @constraint(sp, B)
end

If I use the cycle policy this constraint will also appear after the initial 4 months, on months 13,14,15 and 16. If there is an way to detect the cycle then I could do something like this:

if t <= 4 && !node.cycle
    @constraint(sp, A)
else 
    @constraint(sp, B)
end

There is any flag for the subproblem to know that you are in cycle?

@odow
Copy link
Owner

odow commented Nov 4, 2024

There is any for the subproblem to know that you are in cycle?

No. The correct approach is to use a graph with 16 nodes:

julia> using SDDP

julia> graph = SDDP.LinearGraph(12);

julia> for t in 1:4
           SDDP.add_node(graph, 12 + t)
           p = t == 1 ? 0.95 : 1.0
           SDDP.add_edge(graph, 11 + t => 12 + t, p)
       end

julia> SDDP.add_edge(graph, 16 => 5, 1.0)

julia> graph
Root
 0
Nodes
 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
Arcs
 0 => 1 w.p. 1.0
 1 => 2 w.p. 1.0
 2 => 3 w.p. 1.0
 3 => 4 w.p. 1.0
 4 => 5 w.p. 1.0
 5 => 6 w.p. 1.0
 6 => 7 w.p. 1.0
 7 => 8 w.p. 1.0
 8 => 9 w.p. 1.0
 9 => 10 w.p. 1.0
 10 => 11 w.p. 1.0
 11 => 12 w.p. 1.0
 12 => 13 w.p. 0.95
 13 => 14 w.p. 1.0
 14 => 15 w.p. 1.0
 15 => 16 w.p. 1.0
 16 => 5 w.p. 1.0

@Thuener
Copy link
Collaborator Author

Thuener commented Nov 5, 2024

Thanks.
I taught about this approach, the downside is that it will create more nodes leading to more convergence time. For 4 nodes is would be ok, but for 12 maybe it would be too much.

@Thuener Thuener closed this as completed Nov 5, 2024
@odow
Copy link
Owner

odow commented Nov 5, 2024

It probably won't make that much of a difference. In an acyclic graph, the solution scales approximately linearly in the number of nodes. In a cyclic graph, I don't think anyone has a result, but I assume that it's the expected number of nodes in the forward pass. So 12 * (1 - p) is 240 nodes. Adding an extra 4 won't change much.

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

No branches or pull requests

2 participants