Example
This chapter explains how to implement a basic Mosel module myxprs for using Xpress Optimizer as the solver for optimization models stated in Mosel. The use of the new module from Mosel looks as follows for its simplest form that provides starting of the solver, solution retrieval, and access to solver parameters.
model "Problem solving and solution retrieval" uses "myxprs" ! Load the solver module declarations x,y: mpvar ! Some decision variables pb: mpproblem ! (Sub)problem end-declarations procedure printsol if getprobstat = MYXP_OPT then writeln("Solution: ", getobjval, ";", x.sol, ";", y.sol) else writeln("No solution found") end-if end-procedure Ctr1:= 3*x + 2*y <= 400 Ctr2:= x + 3*y <= 310 MyObj:= 5*x + 20*y ! Setting solver parameters setparam("myxp_verbose", true) ! Display solver log setparam("myxp_maxtime", 10) ! Set a time limit ! Solve the problem (includes matrix generation) maximize(MyObj) ! Retrieve a solver parameter writeln("Solver status: ", getparam("myxp_lpstatus")) ! Access solution information printsol ! Turn poblem into a MIP x is_integer; y is_integer ! Solve the modified problem maximize(MyObj) printsol ! **** Define and solve a (sub)problem **** with pb do 3*x + 2*y <= 350 x + 3*y <= 250 maximize(5*x + 20*y) printsol end-do end-model
Sections Implementation of callback handling and Generating names for matrix entries show how to extend this initial version with a solution callback and a matrix export subroutine including names generation.