Loading the matrix
BCL loads the matrix into the Optimizer library whenever (through BCL) an action is required from the Optimizer and the matrix in the Optimizer does not correspond to the one in BCL. This means, if a user wishes to switch to using Optimizer library commands, for instance for performing the optimization, he should explicitly load the current BCL problem into the Optimizer (function XPRBloadmat).
Since both BCL and the Optimizer require separate problem pointers to specify the problem being worked on, there is an issue about how to obtain the Optimizer problem pointer referring to a problem just loaded by BCL. Such issues are handled using the function XPRBgetXPRSprob, which returns the required Optimizer pointer. It should be noted that no call to XPRScreateprob is necessary in this instance, as the problem is created by BCL at the point that it is first passed to the Optimizer.
Standard use of BCL:
XPRBarrvar x; ... x = XPRBnewarrvar(prob, 10, XPRB_PL, "x", 0, 100); ... /* (Define the rest of the problem) */ XPRBsetsense(prob, XPRB_MAXIM); /* Set sense to maximization */ XPRBlpoptimize(prob,""); /* Load matrix and maximize LP problem */ for(i=0; i<10; i++) /* Print solution values for variables */ printf("%s: %d, ",XPRBgetvarname(prob,x[i]), XPRBgetsol(prob,x[i]));
Switch to using the Optimizer library after problem input with BCL:
XPRBprob bcl_prob; XPRSprob opt_prob; XPRBarrvar x; int i, cols, len, offset; double *sol; char *names; bcl_prob = XPRBnewprob("Example1"); /* Initialize BCL (and the Optimizer library) and create a new problem */ x = XPRBnewarrvar(bcl_prob, 10, XPRB_PL, "x", 0, 100); ... /* Define the rest of the problem */ XPRBloadmat(bcl_prob); /* Load matrix into the Optimizer */ opt_prob = XPRBgetXPRSprob(bcl_prob); /* Get the Optimizer problem */ XPRSchgobjsense(opt_prob,XPRS_OBJ_MAXIMIZE); /* Select maximization */ XPRSlpoptimize(opt_prob,""); /* Maximize the LP problem */ XPRSgetintattrib(opt_prob, XPRS_ORIGINALCOLS, &cols); /* Get the number of columns */ sol = malloc(cols * sizeof(double)); XPRSgetlpsol(opt_prob, sol, NULL, NULL, NULL); /* Get entire primal solution */ XPRSgetnamelist(opt_prob, 2, NULL, 0, &len, 0, cols-1); /* Get number of bytes required for retrieving names */ names = (char *)malloc(len*sizeof(char)); XPRSgetnamelist(opt_prob, 2, names, len, NULL, 0, ncol-1); /* Get the variable names */ offset=0; for(i=0; i<cols; i++) { /* Print all solution values */ printf("%s: %g, ", names+offset, sol[i]); offset += strlen(names+offset)+1; }
© 2001-2019 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.