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

How to improve the speed to build a complex model? #3688

Closed
KennethAnn opened this issue Feb 28, 2024 · 2 comments
Closed

How to improve the speed to build a complex model? #3688

KennethAnn opened this issue Feb 28, 2024 · 2 comments

Comments

@KennethAnn
Copy link

I am building a large MILP model in JuMP.jl, which was previously built by the Pyomo package in Python. However, I found that JuMP performs so slowly when building some expressions with complex indexes and conditions. An expression is shown below.

@expression(mod, Disp[z in ZONES, t in POINTS], sum(D1[(p, t)] + D2[(p, t)] for p in GENS[z] if (((p, t) in G_PS) & (is1[p] == false))) - sum(D1[(p, t)] * enerload[p] for p in GENS[z] if (((p, t) in G_PS) & (is1[p] == false))))

I'd like to know whether there are any performance suggestions on building the expressions and whether the model can be saved in a file so that I can re-run the model with revised inputs without spending too much time building the expressions.

@KennethAnn
Copy link
Author

I got the idea that the condition should not be (p, t) in G_PS), which loops in a larger size of elements. The optimal way is by looping p in a list.

@odow
Copy link
Member

odow commented Feb 28, 2024

This is yet another case of #2348 (comment)

Please post on https://discourse.julialang.org/c/domain/opt/13 if you need some suggestions.

I'd probably start with:

z_to_p_list = Dict([p for p in GENS[z] if !is1[p]] for z in ZONES)
@expression(
    mod,
    Disp[z in ZONES, t in POINTS],
    sum(D1[(p, t)] + D2[(p, t)] - D1[(p, t)] * enerload[p] for p in z_to_p_list[z] if (p, t) in G_PS)
)

But it depends on what G_PS is.

Even something like

z_to_p_list = Dict([p for p in GENS[z] if !is1[p]] for z in ZONES)
t_to_p_set = Dict()  # Could be Dict{typeof(t),Set{typeof(p)}} if types are known
for (p, t) in G_PS
    if !haskey(t_to_p_set, t)
        t_to_p_set[t] = Set()
    end
    push!(t_to_p_set[t], p)
end
@expression(
    mod,
    Disp[z in ZONES, t in POINTS],
    sum(D1[(p, t)] + D2[(p, t)] - D1[(p, t)] * enerload[p] for p in z_to_p_list[z] if p in t_to_p_set[t])
)

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

No branches or pull requests

2 participants