Linear, integer, and quadratic problems can be formulated in MATLAB and then optimized either locally or over the network using the OS Library. The OSMatlab class functions much like OSnl2osil and OSmps2osil and takes MATLAB arrays and creates an OSiL instance. This class is part of the OS library. In order to use the OS library with MATLAB the user should do the following. In order to use the OSMatlab class it is necessary to compile matlabSolver.cpp into a MATLAB Executable file. The matlabSolver.cpp file is in the OSModelInterfaces directory even though it is not part of the OS library. The following steps should be followed.
CXXFLAGS='-fno-common -no-cpp-precomp -fexceptions -I/Users/kmartin/Documents/files/code/cpp/OScpp/COIN-OSX/ -I/Users/kmartin/Documents/files/code/cpp/OScpp/COIN-OSX/include'
Next edit the CXXLIBS flag so that the OS and supporting libraries are included. For example, it should look like:
CXXLIBS="$MLIBS -lstdc++ -L/Users/kmartin/Documents/files/code/ipopt/macosx/Ipopt-3.2.2/lib -L/Users/kmartin/Documents/files/code/cpp/OScpp/COIN-OSX/lib -lOS -lIpopt -lOsiCbc -lOsiClp -lCbc -lCgl -lOsi -lClp -lCoinUtils -lm"
For a UNIX system the mexopts.sh file will usually be found in a directory with the release name in /.matlab. For example,
/.matlab/R14SP3.
On a Windows system, the mexopts.bat file will usually be in a directory with the release name in C:
Documents and Settings
Username
Application Data
Mathworks
MATLAB
mex -v matlabSolver.cpp
On a MAC OS X the resulting executable will be named matlabSolver.mexmac. On the Windows system the file is named matlabSolver.mexw32.
To use the matlabSolver it is necessary to put the coefficients from a linear, integer, or quadratic problem into MATLAB arrays.
The MATLAB representation of this problem in MATLAB arrays is
% the number of constraints numCon = 4; % the number of variables numVar = 2; % variable types VarType='CC'; % constraint types A = [.7 1; .5 5/6; 1 2/3 ; .1 .25]; BU = [630 600 708 135]; BL = []; OBJ = [10 9]; VL = [-inf -inf]; VU = []; ObjType = 1; % leave Q empty if there are no quadratic terms Q = []; prob_name = 'ParInc Example' password = 'chicagoesmuyFRIO'; % % %the solver solverName = 'lindo'; %the remote service service address %if left empty we solve locally serviceAddress='http://gsbkip.chicagogsb.edu/os/OSSolverService.jws'; % now solve callMatlabSolver( numVar, numCon, A, BL, BU, OBJ, VL, VU, ObjType, ... VarType, Q, prob_name, password, solverName, serviceAddress)This example m-file is in the data directory and is file parincLinear.m. Note that in addition to the problem formulation we can specify which solver to use through the solverName variable. If solution with a remote solver is desired this can be specified with the serviceAddress variable. If the serviceAddress is left empty, i.e.
serviceAddress='';then a local solver is used. In this case it is crucial that the appropriate solver is linked in with the matlabSolver executable using the CXXLIBS option.
The data directory also contains the m-file template.m which contains extensive comments about how to formulate the problems in MATLAB. A second example which is a quadratic problem is given in the Appendix. The appropriate m-file is markowitz.m.