Large Scale Linear Sistem

45 views
Skip to first unread message

Mateus Balan

unread,
Dec 29, 2022, 5:39:21 AM12/29/22
to OPTANO Modeling
Dear All,

I'm working on an energy dispatch optimization problem with a linear power flow constraint.

The constraint is basically a matrix multiplication:

Matrix equation:      F   =    beta        *    P
Dimensions:        (9000)   (9000 X 12000)   (12000)


I wrote the code bellow for the matrix constraint, F and P are decision variable and beta is matrix parameter.

foreach (var lin in ndxLine) // 9000 lines
{
model.AddConstraint(F[lin] == Expression.Sum(ndxCol.Select(col => _mtxBetaDense[lin, col] * P[col])) );// 12000 columns
}

The model worked, but... it took 17 minutes to find the optimal solution.
I'm working to simplify the mathematical problem to minimize the execution time, but I'm wondering if its also possible to use a sparse matrix for the beta parameter.
Is it possible to declare beta as array of sparce arrays and use the sum loop in the expression?
I'm using GLPK solver.

Thank you.

OPTANO Team

unread,
Dec 29, 2022, 6:33:59 AM12/29/22
to OPTANO Modeling

Hi,

both, OPTANO Modeling and GLPK use a sparse matrix internally. OPTANO Modeling will create variables only if needed and only transfer those to glpk. GLPK will additionally run a matrix compression when starting to remove redundant constraints. You should see a console output of glpk about the size of the remaining problem.

In only very rare cases redundancy of constraints or unneeded variables have impact on the solution time. Usually, the solution times result from the hardness of the problem. And that is usually from the integer and binary variables. (There are other reasons as well, but let’s focus on the likely ones for now)

To speed up the model you might:

·       Check, if only required variables are of type binary or integer. Make all other continuous variables

·       Some decisions might be made before creating the model, in the preprocessing phase. This is usually for if-then relations the case. You could pre-calculate those decisions and not leave them to the solver.

·       Reformulations might help to find a tighter convex hull around the remaining integers / binaries. You might play around with different formulations as the solvers benefit individually from reformulations

·       As solvers run at different speeds on the models, you could test-drive other solvers such as Gurobi, Cplex or HiGHS. Changing the solver in OPTANO Modeling is as easy as changing one line of code.

 

Does this help?

 

Best

jp

Jannick Lange

unread,
Jan 3, 2023, 3:57:05 AM1/3/23
to OPTANO Modeling
Hello!

I just noticed one more thing: Your code looks as though you iterate the entire matrix cell by cell.
Usually, in MIPs/LPs, only a few cells actually are non-0 values. You can try to pre-process/group your data in such a way, that you only iterate over relevant index-combinations.
If all of the cells in your matrix are non-0, I'd expect many of them to be (very) close to 0. Treating 'small' values (i.e. |x| < 1e-6) as 0, might bring some speed up. Internally (in Modeling, as well as in the Solvers), this is the default tolerance/accuracy for computations, below which values will be discarded either way.

Hoep this helps
Jannick
Reply all
Reply to author
Forward
0 new messages