I want to have a variable where depending on the use cases may have different number of indices.
That is in some cases, the variable may be of the form V: array(set of string, set of string) of mpvar, while in some other cases, it may be V: array(set of string, set of string, set of string) of mpvar.
Is there a way to declare and use variables with a dynamic number of indices?
I've read the documentation of Xpress but haven't managed to find a solution.
How to address this question will to a large extend depend on the way how this array of variables is used. How is the array accessed / enumerated (always in its entirety, or are you building constraint expressions over certain indices)? How do you decide whether there are 2 or 3 indices (at compile time or data-driven at run time)?
Within a single model it is not possible to declare (globally) an array with 2 different sets of indices, however, multiple declarations (along with their use) could be provided in various different ways, eg through separately compiled portions of code.
There are various other options (among others, local declarations within subroutines, using preprocessor markup to select portions of code for compilation, or working with dynamically loaded Mosel packages), but deciding what would be a good choice really depends on your specific use case.