Forum Discussion
FICO
3 years agoCommunity Manager
combining mmxprs and/or nlsolv with mmquad or mmnl
I have two questions about combining mmxprs and/or nlsolv with mmquad or mmnl in Mosel:
If I use the Xpress solver (mmxprs), can I trust that it will always detect that a constraint or objective is linear or quadratic, even if it is defined as qexp (with mmquad) or nlctr (with mmnl)?
In other words, can I safely use nlctr/qexp in a model that sometimes (dependent on data) uses quadratic terms, but in other cases it is a pure LP (or MIP)?
And is this detection done by the solver, or by Mosel?
It does not seem possible to combine nlsolv with mmquad - it triggers the following compilation error: "The symbol `@*' from `mmquad' cannot be defined (redefinition)." Is this a bug that can be fixed, or does it have some deeper reason?
I know that it is possible to combine nlsolv with mmnl instead and use nlctr for the quadratic terms, but then I am not sure if Mosel detects that it is a QP and parse it to the solvers as such. (This is connected to the first question.)
Moreover, using nlctr for an objective function makes it impossible (as far as I can see) to save the problem as an .lp or .mps file, since exportprob only accepts objective function as linctr or qexp (with mmquad) and nlsolv's exportnl() only writes .nl files. Or did I missed something?
Is it, for example, possible to convert nlctr and/or qexp to linctr? (where such conversion would fail if the expression was not linear)?
5 Replies
- FICOCommunity Manager
Hi Michal,
Firstly, mmnl and mmquad are not compatible with each other: these modules provide two different ways to model quadratic constraints, and you should choose one of them. We recommend using mmnl if possible, since it provides a more general nonlinear programming interface and integrates better with the other modules like nlsolv. This incompatibility is the cause of the error you mentioned about redefining the @* symbol.
mmxprs and mmquad will both detect whether an nlctr/qexp is linear or quadratic and load it into the Optimizer accordingly, i.e. the problem will not be considered quadratic unless there is an actual quadratic constraint or objective. The problem must be convex or the Optimizer will abort the solve with an error.
You can export a QP as an .lp or .mps file by using the loadprob function (which accepts an nlctr or qexp as the objective) followed by the writeprob function. Both of these functions are provided by mmxprs.
I would not recommend using nlsolv, unless you particularly want to use an external solver other than Xpress. The mmxprs/mmnl/mmquad/mmxnlp modules are much better integrated with the Xpress solver. However, if you do use nlsolv to write a .nl file and then solve this with Xpress, the Optimizer will recognise if the problem is linear or quadratic and solve it accordingly. But in this case, if your problem is nonconvex the Optimizer may try to solve it using a general nonlinear solver, if your license allows for this.
Chris
- FICOCommunity Manager
Thanks for the answer.
While I like using the more general approach, I was not sure whether Mosel automatically analysis nlctr-objects and chooses appropriate solver and solution methods - can you confirm that?
(In other words, if all my nctr-objects are only linear and quadratic, will Mosel detect it and use QP solver/method - and the same for purely linear objects?)
Moreover, it could be useful to be able to write an LP/MPS file in cases one uses mmnl, but all nctr objects are linear or quadratic - which I guess mean provided overloaded exportprob as a part of mmnl?
- FICOCommunity Manager
Yes I can confirm that the appropriate solver algorithm will always be selected based on the nature of the problem. Whether nlctr objects are used in the modelling has no effect on this. If the problem is purely linear it will be solved using primal/dual simplex or interior point, depending on the Optimizer settings. If the problem has quadratic objective only it will be solved by quadratic simplex or interior point, and if the problem contains quadratic constraints it will be solved by interior point.
We do not have plans to provide an overloaded exportprob function, since the same functionality is provided by the loadprob/writeprob functions in mmxprs. These functions can be used in the case you are describing, where you use mmnl and all nlctr objects are linear or quadratic.
- FICOCommunity Manager
A few add-on notes:
- mmquad vs mmnl: as was already said, usually we recommend using mmnl as it has more functionality and it is now as efficient as mmquad for handling quadratic constraints (this was not the case in earlier versions of mmnl)
- matrix export: the core functionality of Mosel only supports pure linear problems - this is what gets written out by 'exportprob'. The full solver problem is output by loading it into the optimiser using 'loadprob', followed by 'writeprob'. When working with nlsolv the module itself does not provide matrix export functionality, but the solver that you use through it may be able to write out matrices, for example with 'amplxpress', you can achieve this through the solver options setting:
setparam("nl_options", "writeprob=testout.lp") ! LP format matrix file
or
setparam("nl_options", "writeprob=testout.mps") ! MPS format matrix file
- FICOCommunity Manager
Thanks a lot for the answers, it really helped :-)

