Hi,

I have a general question regarding the computational efficiency of two alternative methods of formulating a constraint in mosel.

Say I have an array of mpvars X(t). Each element of the array has its own coefficient C(t). I have a constraint:

constraint:= sum(t in TSET) C(t)*X(t) <= Z where Z is a constant.

The coefficients C(t) are specified as a conditional sum of one or more other data arrays - e.g.

C(t) := sum( a in A, b in B | t in MAP(a) ) E1(a) + E2(a,b)

An alternative to this structure is to formulate everything directly within the constraint:

constraint:= sum( a in A, b in B, t in MAP(a) ) (E1(a) + E2(a,b) ) * X(t) <= Z

My question is: does anyone know in general which approach is the most efficient for mosel - i.e. which will take the least execution time to prepare the model for sending to the solver? The first approach is perhaps best for readability, but if I have a large data set that would require the calculation of a large number of very large "derived" coefficient arrays, would I be able to reduce execution time significantly by formulating directly within the constraints and not creating the derived or intermediate arrays? Of course, all this is depends on how large is large, but any indications on this front would be welcome!

It is difficult to judge the efficiency of the different formulations without further detail on the data structures (dynamic or static arrays? ranges or sets? density of arrays?).

However, given that the decision variables 'X' only depend on the index 't', I would recommend to use a columnwise (decomposed) definition - that is, calculating the coefficients C(t) separately as in your first formulation option. Furthermore, since the 'E1' terms only depend on one of the indices, it might even be preferable to write the expression as follows:

C(t) := sum( a in A | t in MAP(a) ) E1(a)*B.size +

sum( a in A, b in B | t in MAP(a) ) E2(a,b)

In any case, I would recommend that you run the Mosel profiler with the different formulation options for your problem.

To run the profiler, type the following command at the commandline:

mosel profile mymodel.mos

This will produce a profile log file "mymodel.mos.prof" in the same location as the model file.