General constraints
Certain nonlinear constraint relations (refered to as general constraints) are recognized by MIP solvers and they are treated as MIP modeling constructs. These include
- piecewise linear expressions (see examples in Sections Price breaks and Non-linear functions above)
- absolute value, minimum value, maximum value of discrete or continuous decision variables
- logical constraints: 'and' and 'or' over binary variables (see Section Boolean variables )
The Mosel implementation of the numerical constraints abs, fmin and fmax makes it possible to use linear expressions as argument to these functions. Note that models using these general constraints need to load the mmxnlp module in addition to mmxprs although the problems will be solved by the Xpress MIP solver.
uses "mmxnlp" public declarations R=1..3 x: array(R) of mpvar y,z: mpvar end-declarations forall(i in R) x(i) <= 20 abs(x(1)-2*x(2)) <= 10 ! Absolute value constraint MinCtr:= fmin(union(i in R) [x(i)]) >= 5 ! Minimum value constraint y = fmax(x(3), 20, x(1)-z) ! Maximum value constraint maximize(sum(i in R) x(i)) ! Solve as MIP problem if getprobstat=XPRS_OPT then ! Solution reporting writeln("Solution: ", getobjval) forall(i in R) write("x", i, "=", x(i).sol, ", ") writeln("y=", y.sol, ", z=", z.sol) writeln("abs=", getsol(abs(x(1)-2*x(2))), ", Min of x(i)=", MinCtr.sol+5) else writeln("No solution") end-if