Originally posted by: hllsen
Hi,
I noticed that creating the model in C++ API takes too much time (a lot longer than it takes in OPL). Then I noticed that the following code part takes approx. 300sec.:
double Time_start = env.getTime();
IloExpr objfunc(env);
for ( k = 0; k < m; ++k ) {
for ( j = 0; j < n; ++j ) {
objfunc += ( p[j][k] * w[j] / 2.0 ) * ( Y[k][j] + Y[k][j] * Y[k][j] );
for (int i = 0; i < n; ++i ) {
if ( p_over_w[k][i] < p_over_w[k][j] || ( p_over_w[k][i] == p_over_w[k][j] && i < j ) ) {
objfunc += (p[i][k] * w[j]) * Y[k][j] * Y[k][i];
}
}
}
}
std::cout << env.getTime() - Time_start << std::endl;
mod.add( IloMinimize( env, objfunc ) );
However, if I make the following [relatively] small change, it takes 12sec. to create the objective function.
double Time_start = env.getTime();
IloExpr objfunc(env);
for ( k = 0; k < m; ++k ) {
IloExpr objfunc_part(env);
for ( j = 0; j < n; ++j ) {
objfunc_part += ( p[j][k] * w[j] / 2.0 ) * ( Y[k][j] + Y[k][j] * Y[k][j] );
for (int i = 0; i < n; ++i ) {
if ( p_over_w[k][i] < p_over_w[k][j] || ( p_over_w[k][i] == p_over_w[k][j] && i < j ) ) {
objfunc_part += (p[i][k] * w[j]) * Y[k][j] * Y[k][i];
}
}
}
objfunc += objfunc_part;
}
std::cout << env.getTime() - Time_start << std::endl;
mod.add( IloMinimize( env, objfunc ) );
In both cases m = 6 and n = 100. I did try to use the same 'technique' to chop down objfunc_part into objfunc_part_part however it didn't save me any more time.
What confuses me is that creating the same objective function with the same data-set takes 0.1250 sec. in OPL Studio. Also extracting the model takes 3sec. in C++ API which is a lot longer than it takes OPL Studio to extract the same model (0.1406) .
LOAD_MODEL ... 0.0156
EXTRACT ... 0.1406
OBJECTIVE 0.1250
minimize
sum(k in machines)
sum(j in jobs)
( 0.5 * p[k][j] * w[j] * (y[k][j]+y[k][j]^2) + sum(i in jobs: (p_over_w[k][i] < p_over_w[k][j]) || (p_over_w[k][i] == p_over_w[k][j] && i < j)) p[k][i] * w[j] * y[k][i] * y[k][j]);
So my question is am I doing something wrong? Are these times [300sec/12sec/3sec/0.1406sec.] reasonable? Shouldn't C++ API be faster?
Thank you,
halil.
#CPLEXOptimizers#DecisionOptimization