MIP model 2: imposing a minimum investment in each share
Topics covered in this section:
To formulate the second MIP model, we start again with the LP model from Chapters 2 and 15. The new constraint we wish to formulate is `if a share is bought, at least a minimum amount 10% of the budget is spent on the share.' Instead of simply constraining every variable fracs to take a value between 0 and 0.3, it now must either lie in the interval between 0.1 and 0.3 or take the value 0. This type of variable is known as semi-continuous variable. In the new model, we replace the bounds on the variables fracs by the following constraint:
Matrix representation
This problem has the same matrix as the LP problem in the previous chapter, and so we do not repeat it here. The only changes are in the specification of the MIP-related column data.
Implementation with Xpress Optimizer
The following program foliomip2.c loads the MIP model 2 into the Optimizer. We have the same matrix data as for the LP problem in the previous chapter, but the variables are now semi-continuous, defined by the type marker 'S'. By default, Xpress Optimizer assumes a continuous limit of 1, we therefore specify the value 0.1 in the array sclim. Please note in this context that limits for semi-continuous and semi-continuous integer variables given in the array sclim are overwritten by the value in the array lb if the latter is different from 0.
Other available composite variable types are semi-continuous integer variables that take either the value 0 or an integer value between a given limit and their upper bound (marked by 'R') and partial integers that take integer values from their lower bound to a given limit value and are continuous beyond this value (marked by 'P').
#include <stdio.h> #include <stdlib.h> #include "xprs.h" int main(int argc, char **argv) { XPRSprob prob; int s, status; double objval, *sol; /* Problem parameters */ int ncol = 10; int nrow = 3; int nmip = 10; /* Row data */ char rowtype[] = { 'L','G','E'}; double rhs[] = {1.0/3,0.5, 1}; /* Column data */ double obj[] = { 5, 17, 26, 12, 8, 9, 7, 6, 31, 21}; double lb[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; double ub[] = {0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3}; /* Matrix coefficient data */ int colbeg[] = {0, 2, 5, 8, 11,12,13,14,15, 17, 19}; int rowidx[] = {1,2,0,1,2,0,1,2,0,1,2, 2, 2, 2, 2, 0,2, 0,2}; double matval[] = {1,1,1,1,1,1,1,1,1,1,1, 1, 1, 1, 1, 1,1, 1,1}; /* MIP problem data */ char miptype[] = {'S','S','S','S','S','S','S','S','S','S'}; int mipcol[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; double sclim[] = {0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1}; /* Initialize Xpress */ if (XPRSinit(NULL)) { printf("Failed to initialize Xpress.\n"); return -1; } XPRScreateprob(&prob); /* Create a new problem */ /* Load the problem matrix */ XPRSloadmip(prob, "FolioSC", ncol, nrow, rowtype, rhs, NULL, obj, colbeg, NULL, rowidx, matval, lb, ub, nmip, 0, miptype, mipcol, sclim, NULL, NULL, NULL, NULL); XPRSchgobjsense(prob, XPRS_OBJ_MAXIMIZE); /* Set sense to maximization */ XPRSmipoptimize(prob, ""); /* Solve the problem */ XPRSgetintattrib(prob, XPRS_MIPSTATUS, &status); /* Get MIP sol. status */ if((status == XPRS_MIP_OPTIMAL) || (status == XPRS_MIP_SOLUTION)) { XPRSgetdblattrib(prob, XPRS_MIPOBJVAL, &objval); /* Get objective value */ printf("Total return: %g\n", objval); sol = (double *)malloc(ncol*sizeof(double)); XPRSgetsolution(prob, NULL, sol, 0, ncol-1); /* Get primal solution */ for(s=0;s<ncol;s++) printf("%d: %g%%\n", s, sol[s]*100); } XPRSdestroyprob(prob); /* Delete the problem */ XPRSfree(); /* Terminate Xpress */ return 0; }
When executing this program we obtain the following output:
Total return: 14.0333 0: 30% 1: 0% 2: 20% 3: 0% 4: 10% 5: 26.6667% 6: 0% 7: 0% 8: 13.3333% 9: 0%
Now five securities are chosen for the portfolio, each forming at least 10% and at most 30% of the total investment. Due to the additional constraint, the optimal MIP solution value is again lower than the initial LP solution value.
© 2001-2025 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.