Slow model building
ユーザーの入力を待っています。Hello,
I am building a branch-and-price application, and my master-problem is taking a very long time to build (> 10 minutes) (and I am getting RAM memory issues after a while when building it), however actually solving the problem is super fast (often < 1 s)
It has the following data rows, columns and entries:
Optimize a model with 598 rows, 5000 columns and 691142 nonzeros
Model fingerprint: 0x040fac46
Coefficient statistics:
Matrix range [1e+00, 1e+09]
Objective range [2e+05, 1e+08]
Bounds range [1e+00, 1e+00]
RHS range [1e+00, 2e+09]
Warning: Model contains large matrix coefficients
Warning: Model contains large rhs
Consider reformulating model or setting NumericFocus parameter
to avoid numerical issues.
The formulation is as follows:
I realize I am dealing with a large, real-world issue, so indices are generations -> 100, timeperiods -> 100, units -> 20
However it still does not make fully sense to me that the model should actually be this slow... Any ideas would be greatly appreciated!
-
Hi Vegard,
That does sound unusually slow. Can you show us how you are creating the variables?
- Riley
0 -
I am building the variables like this:
l = dict.fromkeys((g,k) for g in all_generations for k in production_schedules[g])
for g in all_generations:
for k in production_schedules[g]:
l[(g,k)] = problem.addVar(name = 'lambda({},{})'.format(g,k))
The model building scales very badly with the nr of columns k, already at k > 50 it starts getting quite slow.0 -
Without seeing the entire code, and the data structures you are using it is hard to say what the cause is. Are you using pandas anywhere?
In your code snippet for building variables you can replace the first line with
l = dict()
and the last line with
l[g,k] = problem.addVar(name = 'lambda({},{})'.format(g,k))
The first thing I would do is invoke the golden rule of computers and turn it off and on again. I'm wondering if you are running low on memory and a reset could help.
The second thing I would do is record the time taken for each chunk of code, so you can narrow down where the issue is:
import time
# stuff here
start_time = time.time()
# build variables
end_time = time.time()
execution_time = end_time - start_time
print(f"Variable creation time: {execution_time} seconds")
start_time = time.time()
# first set of constraints
end_time = time.time()
execution_time = end_time - start_time
print(f"First constraints creation time: {execution_time} seconds")
# and so on...- Riley
0
サインインしてコメントを残してください。
コメント
3件のコメント