Martin Bonde
Martin Bonde

Reputation: 556

What is the most efficient set order in GAMS?

The documentation suggests that sets should appear in the same order to increase performance. If most of our variables share a set, is it better to have the common set first or last?

I.e. which is more efficient?

  y[i,t] =E= a[t] * x[j,t];

or

  y[t,i] =E= a[t] * x[t,j];

Upvotes: 1

Views: 120

Answers (2)

Martin Bonde
Martin Bonde

Reputation: 556

In case anyone stumbles upon this, the context is a large dynamic economic model.

We tried switching our time index from always being the last set to always being the first. The model is a square system of around 1m equations, 7m Jacobian elements, of which 2m are non-linear.

The solution time using CONOPT4 was significantly worse after the change. I.e. we have better performance with the time index last rather than first, despite the time index being among the largest sets in the model. The result is probably not transferable to other models, but confirms that there is no trivial answer.

Upvotes: 1

Lutz
Lutz

Reputation: 2292

The main point of this "same order" is, that the sets should be used in the order they are controlled. So

Equation1(t,i,j).. y[t,i] =E= a[t] * x[t,j];

should be better than

Equation2(i,j,t).. y[t,i] =E= a[t] * x[t,j];

Other than that, it is not so easy to give many general rules. If you have also full control over the controlling indices, often it is beneficial, if the largest set is last, so if t >> i, than x[i,t] should be better than x[t,i]. In general, the GAMS command line parameter profile (https://www.gams.com/latest/docs/UG_GamsCall.html#GAMSAOprofile) is very useful to check the influence of different formulations of your mode.

Upvotes: 2

Related Questions