/******************************************************** Xpress-BCL C++ Example Problems =============================== file folioiis.cpp ````````````````` Modeling a MIP problem to perform portfolio optimization. Same model as in foliomip3.cpp. -- Infeasible model parameter values -- -- Retrieving IIS -- (c) 2009 Fair Isaac Corporation author: S.Heipcke, June 2009, rev. Mar. 2011 ********************************************************/ #include #include #include #include #include #include "xprb_cpp.h" #include "xprs.h" using namespace std; using namespace ::dashoptimization; #define MAXNUM 5 // Max. number of different assets #define MAXRISK 1/3 // Max. investment into high-risk values #define MINREG 0,1 // Min. investment per geogr. region #define MAXREG 0,2 // Max. investment per geogr. region #define MAXSEC 0,1 // Max. investment per ind. sector #define MAXVAL 0,2 // Max. investment per share #define MINVAL 0,1 // Min. investment per share #define DATAFILE "folio10.cdat" // File with problem data #define MAXENTRIES 10000 int NSHARES; // Number of shares int NRISK; // Number of high-risk shares int NREGIONS; // Number of geographical regions int NTYPES; // Number of share types double *RET; // Estimated return in investment int *RISK; // High-risk values among shares char **LOC; // Geogr. region of shares char **SECT; // Industry sector of shares char **SHARES_n; char **REGIONS_n; char **TYPES_n; #include "readfoliodata.c_" int main(int argc, char **argv) { int s,r,t; XPRBprob p("FolioMIP3inf"); // Initialize a new problem in BCL XPRBctr Risk,Return,Num,*MinReg, *MaxReg, *LimSec; XPRBexpr le, le2, Cap, LinkL, LinkU; XPRBvar *frac; // Fraction of capital used per share XPRBvar *buy; // 1 if asset is in portfolio, 0 otherwise readdata(DATAFILE); // Data input from file // Create the decision variables (including upper bounds for `frac') frac = new XPRBvar[NSHARES]; buy = new XPRBvar[NSHARES]; for(s=0;s0) { le += frac[s]; le2 += frac[s]; } MinReg[r] = p.newCtr(XPRBnewname("MinReg(%s)",REGIONS_n[r]), le >= MINREG); MaxReg[r] = p.newCtr(XPRBnewname("MaxReg(%s)",REGIONS_n[r]), le2 <= MAXREG); } // Diversification across industry sectors LimSec = new XPRBctr[NTYPES]; for(t=0;t0) le += frac[s]; LimSec[t] = p.newCtr(XPRBnewname("LimSec(%s)",TYPES_n[t]), le <= MAXSEC); } // Spend all the capital for(s=0;s= MINVAL*buy[s]); } // Solve the problem (LP) p.setSense(XPRB_MAXIM); p.lpOptimize(""); if (p.getLPStat()==XPRB_LP_INFEAS) { cout << "LP infeasible. Retrieving IIS." << endl; int numiis = p.getNumIIS(); // Get the number of independent IIS cout << "Number of IIS: " << numiis << endl; XPRSprob op = p.getXPRSprob(); // Retrieve the Optimizer problem /**** Obtain variable and constraint names for use in printout ****/ int ncol, nrow, len, numc, numv, i; char *vnames, *cnames; int *viis,*ciis; char **vindex,**cindex; // Retrieve variable names XPRSgetintattrib(op, XPRS_ORIGINALCOLS, &ncol); XPRSgetnamelist(op, 2, NULL, 0, &len, 0, ncol-1); // Get number of bytes required for retrieving names vnames = new char[len]; vindex = new char*[ncol]; XPRSgetnamelist(op, 2, vnames, len, NULL, 0, ncol-1); vindex[0]=vnames; for(i=1; i0) { cout << " Variables: "; // Print all variables in the IIS for(i=0;i0) { cout << " Constraints: "; // Print all constraints in the IIS for(i=0;i