• No results found

The project planning model using Special Ordered Sets

In document Xpress-Mosel User guide (Page 40-43)

The example can be modified to use Special Ordered Sets of type 1 (SOS1). The startpmvariables for a given p form a set of variables which are ordered by m, the month. The ordering is induced by the coefficients of the startpmin the specification of the SOS. For example, startp1’s coefficient, 1, is less than startp2’s, 2, which in turn is less than startp3’s coefficient, and so on The fact that the startpmvariables for a given p form a set of variables is specified to Mosel as follows:

(! Define SOS-1 sets that ensure that at most one start(p,m) is non-zero for each project p. Use month index to order the variables !)

forall(p in PROJ) XSet(p):= sum(m in MONTHS) m*start(p,m) is_sos1

The is_sos1 specification tells Mosel that Xset(p) is a Special Ordered Set of type 1. The linear expression specifies both the set members and the coefficients that order the set members. It says that all the startpmvariables for m in the MONTHS index range are members of an SOS1 with reference row entries m.

The specification of the startpmas binary variables must now be removed. The binary nature of the startpmis implied by the SOS1 property, since if the startpmmust add up to 1 and only one of them can differ from zero, then just one is 1 and the others are 0.

If the two formulations are equivalent why were Special Ordered Sets invented, and why are they useful? The answer lies in the way the reference row gives the search procedure in Integer Programming (IP) good clues as to where the best solution lies. Quite frequently the Linear Programming (LP) problem that is solved as a first approximation to an Integer Program gives an answer where startp1is fractional, say with a value of 0.5, and startp,NMtakes on the same fractional value. The IP will say:

‘my job is to get variables to 0 or 1. Most of the variables are already there so I will try moving xp1 or xpT. Since the set members must add up to 1.0, one of them will go to 1, and one to 0. So I think that we start the project either in the first month or in the last month.’

A much better guess is to see that the startpmare ordered and the LP solution is telling us it looks as if the best month to start is somewhere midway between the first and the last month. When sets are present, the IP can branch on sets of variables. It might well separate the months into those before the middle of the period, and those later. It can then try forcing all the early startpm to 0, and restricting the choice of the one startpmthat can be 1 to the later startpm. It has this option because it now has the information to ‘know’ what is an early and what is a late startpm, whereas these variables were unordered in the binary formulation.

The power of the set formulation can only really be judged by its effectiveness in solving large, difficult problems. When it is incorporated into a good IP system such as Xpress it is often found to be an order of magnitude better than the equivalent binary formulation for large problems.

Chapter 5

Overview of subroutines and

reserved words

There is a range of built-in functions and procedures available in Mosel. They are described fully in the Mosel Language Reference Manual. Here is a summary.

• Accessing solution values: getsol, getact, getcoeff, getdual, getrcost, getslack, getobjval

• Arithmetic functions: abs, arctan, cos, sin, ceil, floor, round, exp, ln, log, sqrt, isodd, random, setrandseed

• List functions: maxlist, minlist, cuthead, cuttail, findfirst, findlast, getfirst, getlast, getreverse, reverse, gethead, gettail, splithead, splittail

• String functions: strfmt, substr

• Dynamic array handling: create, finalize, delcell

• File handling: fclose, fflush, fopen, fselect, fskipline, getfid, iseof, read, readln, getreadcnt, write, writeln

• Accessing control parameters: getparam, setparam • Getting information: getsize, gettype, getvars

• Constraint definition: sethidden, ishidden, makesos1, makesos2, setcoeff, settype • Time and date: currentdate, currenttime, timestamp

• Miscellaneous functions: exportprob, assert, bittest, exit, reset

5.1

Modules

The distribution of Mosel contains several modules that add extra functionality to the language. A full list of the functionality of a module can be obtained by using Mosel’s exam command, for instance

mosel -c "exam mmsystem"

In this manual, we always use Xpress-Optimizer as solver. Access to the corresponding optimization functions is provided by the module mmxprs.

In the mmxprs module are the following useful functions.

c

• Optimize: minimize, maximize

• MIP directives: setmipdir, clearmipdir

• Handling bases: savebasis, loadbasis, delbasis • Force problem loading: loadprob

• Accessing problem status: getprobstat

• Deal with bounds: setlb, setub, getlb, getub • Model cut functions: setmodcut, clearmodcut

For example, here is a nice habit to get into when solving a problem with Xpress-Optimizer.

declarations status:array({XPRS_OPT,XPRS_UNF,XPRS_INF,XPRS_UNB,XPRS_OTH}) of string end-declarations status::([XPRS_OPT,XPRS_UNF,XPRS_INF,XPRS_UNB,XPRS_OTH])[ "Optimum found","Unfinished","Infeasible","Unbounded","Failed"] ... minimize(Obj) writeln(status(getprobstat))

In the mmsystem module are various useful functions provided by the underlying operating system and a few programming utilities :

• Delete a file/directory: fdelete, removedir • Copy/move a file: fcopy, fmove

• Make a directory: makedir

• Current working directory: getcwd

• Get/set an environment variable’s value: getenv, setenv • File and system status: getfstat, getsysstat

• General system call: system

• Time and date: gettime, getdate, getweekday, getasnumber, ...

• Handling the type text: copytext, cuttext, deltext, readtextline, ... • Sort an array of numbers: qsort

Other modules mentioned in this manual are mmodbc and mmetc. See the module reference manuals for full details.

In document Xpress-Mosel User guide (Page 40-43)