Need to improve optimization time  Warning: large bounds and large coefficient range
AnsweredHi,
I am running an optimization for an underground hydrogen storage with econimic calculations for one year with step size of 1h. Due to long optimizations times I would like to improve the model. Also I receive the warnings:
Optimize a model with 4665 rows, 6216 columns and 10641 nonzeros
Model fingerprint: 0xd87d8a5a
Model has 502 quadratic constraints
Model has 2 general constraints
Variable types: 5915 continuous, 301 integer (300 binary)
Coefficient statistics:
Matrix range [2e05, 6e+06]
QMatrix range [3e06, 1e+05]
QLMatrix range [2e04, 1e+06]
Objective range [1e+00, 1e+00]
Bounds range [1e+00, 1e+10]
RHS range [3e03, 8e+07]
Warning: Model contains large bounds
Warning: Quadratic constraints contain large coefficient range
Consider reformulating model or setting NumericFocus parameter
to avoid numerical issues.
Presolve removed 4327 rows and 5381 columns
Presolve time: 0.01s
Presolved: 1130 rows, 835 columns, 3149 nonzeros
Presolved model has 198 bilinear constraint(s)
Variable types: 835 continuous, 0 integer (0 binary)
Root relaxation: objective 1.000000e+06, 506 iterations, 0.01 seconds (0.01 work units)
Nodes  Current Node  Objective Bounds  Work
Expl Unexpl  Obj Depth IntInf  Incumbent BestBd Gap  It/Node Time
0 0 1000000.00 0 20  1000000.00   0s
0 0 1000000.00 0 19  1000000.00   0s
0 0 1000000.00 0 19  1000000.00   0s
0 2 1000000.00 0 19  1000000.00   0s
* 3925 4060 104 1000000.0000 1000000.00 0.00% 8.8 0s
Cutting planes:
RLT: 17
Explored 5712 nodes (44790 simplex iterations) in 0.66 seconds (0.33 work units)
Thread count was 32 (of 64 available processors)
Solution count 1: 1e+06
Optimal solution found (tolerance 1.00e04)
Warning: max constraint violation (3.8147e06) exceeds tolerance
Warning: max bound violation (1.6629e05) exceeds tolerance
Best objective 1.000000000000e+06, best bound 1.000000000000e+06, gap 0.0000%
I have a few ideas, but don't know exactly what to do:
1. Use prefixes for units to reduce the bounds?
2. Use lb ub with smaller difference to reduce variable bounds?
3. Also I don't know why there are 300 binary variables, because I already removed all binary vanribles I added to reduce calculation time. (only appear in this optimization with 100h not with 10h)
4. Is there a way to check wheather the model is linear or not?
Thank you in advance
Ruben

Hi Ruben,
Thanks for posting to the forum! Here are some thoughts about your log output and model; hope this helps!
 The warnings relate to the “Coefficient statistics” at the top of your log output. Indeed scaling would help improve (reduce) these ranges. See this page and further for guidelines and advice.
 Yes, this might help; I can see that the "Bounds range" is also quite large.
 These might be caused by your 2 general constraints, as these are translated behind the scenes to an equivalent MIP formulation. Can you explain what these general constraints look like?
 At the top, you can see that your model contains quadratic constraints and general constraints. From this, we know that your model is not linear.
In general, my understanding is that you want to solve 365x24 models and each currently takes 0.66s, so roughly 1.6 hours. Of course this runtime and solution quality (see the warnings about constraint violations at the end of the log) would change as you improve the numerical aspects. Then the next question could be, are these models all independent? If they are, you could consider solving multiple models in parallel and/or using our multiscenario feature. If they are not, you might consider merging the models into a single model (again) and seeing if that reduces overall runtime.
Good luck!
Ronald1 
One additional remark:
3. Also I don't know why there are 300 binary variables, because I already removed all binary vanribles I added to reduce calculation time
Did you remove the variables completely from the model? Or do you just fix them or only remove them from the constraints? If they are still defined in the model (although without any use) they are counted initially. Presolve then removes these variables. And indeed the presolved model has only continuous variables
Presolved model has 198 bilinear constraint(s)
Variable types: 835 continuous, 0 integer (0 binary)1 
Thank you for your help!
To Ronald:
My general constrain is to maximize the revenue achieved by variable electricity prices. Additionally, there are a lot of other constraints that limit the hydrogen storage dynamics to realistic circumstances. I don't understand why there are two general constrains, when there is only one objective defined.
m.setObjective(v.demand['revenue_total'], GRB.MAXIMIZE)
The models cannot be solved independently. I alredy saved a lot of time by removing the binary variables. With the implementation of your answer to 1. and 2., I think it will be enough.To Marika:
I removed the binary variables from a list, that is used to in a forloop to define all the variables (addVars...).0 
You could write the model as an LP file (see Model.write() for Python) directly before calling optimize.
In this way, you can inspect the model that is solved by Gurobi.
The LP file contains a section "General Constraints" (if there are any). That might help to understand where the 2 general constraints come from.0
Please sign in to leave a comment.
Comments
4 comments