Initializing help system before first use

Using BCL-compatible functions

The Optimizer library functions that are most likely to be used in a BCL program are those for setting and accessing control and problem parameters, as shown in the following examples. The control parameters can be set and accessed at any time after the software has been initialized (see Section Initialization and termination). The problem attributes only return the problem-specific values once the problem has been loaded into the Optimizer. Note that all the parameters take their default values at the beginning of a BCL program but they are not reset if several problems are solved in a single program and changes are made to the parameter values along the way.

Setting control parameters:

XPRBprob bcl_prob;
XPRSprob opt_prob;

bcl_prob = XPRBnewprob("Example1");  /* Initialize BCL (and the Optimizer
                                  library) and create a new problem */
   ...                         /* Define the problem */
XPRBloadmat(bcl_prob);
opt_prob = XPRBgetXPRSprob(bcl_prob);
XPRSsetintcontrol(opt_prob, XPRS_MAXTIME, 60);
                               /* Set a time limit of 60 seconds */
XPRSsetdblcontrol(opt_prob, XPRS_MIPADDCUTOFF, 0.999);
                               /* Set an ADDCUTTOFF value */
XPRBsetsense(bcl_prob, XPRB_MAXIM);  /* Select maximization */
XPRBlpoptimize(bcl_prob,"");   /* Load matrix and solve as LP problem */

Accessing problem parameters:

int rows;
XPRBprob bcl_prob;
XPRSprob opt_prob;

bcl_prob = XPRBnewprob("Example1");  /* Initialize BCL (and the Optimizer
                                  library) and create a new problem */
    ...                        /* Define the problem */
XPRBloadmat(bcl_prob);         /* Load matrix into the Optimizer */
opt_prob = XPRBgetXPRSprob(bcl_prob);
XPRSgetintattrib(opt_prob, XPRS_ORIGINALROWS, &rows);
                               /* Get number of rows */
XPRBsetsense(bcl_prob, XPRB_MAXIM);  /* Select maximization */
XPRBlpoptimize(bcl_prob,"");   /* Load matrix and solve as LP problem */

Another likely set of functions are the Optimizer library callbacks for solution printout and possibly for directing the branch and bound search (see the remarks about indices in Section Indices of matrix elements):

void XPRS_CC printsol(XPRSprob opt_prob,void *my_object)
{
  XPRBprob bcl_prob
  XPRBvar x;
  int num;

  bcl_prob = (XPRBprob)my_object;
  XPRBbegincb(bcl_prob, opt_prob);
                               /* Use local Optimizer problem in BCL */
  XPRSgetintattrib(opt_prob, XPRS_MIPSOLS, &num);
                               /* Get number of the solution */
  XPRBsync(bcl_prob, XPRB_XPRS_SOL);
                               /* Update BCL solution values */
  XPRBprintf(bcl_prob, "Solution %d: Objective value: %g\n",
              num, XPRBgetobjval(bcl_prob));
  x = XPRBgetbyname(bcl_prob, "x_1", XPRB_VAR);
  if(XPRBgetcolnum(x)>-1)      /* Test whether variable is in the
                                  matrix */
    XPRBprintf(bcl_prob, "%s: %g\n", XPRBgetvarname(x), XPRBgetsol(x));

  XPRBendcb(bcl_prob);         /* Reset BCL to main problem */
}

int main(int argc, char **argv)
{
  XPRBprob bcl_prob;
  XPRSprob opt_prob;
  XPRBvar x;

  bcl_prob = XPRBnewprob("Example1");  /* Initialize BCL (and the Optimizer
                                  library) and create a new problem */
  x = XPRBnewvar(bcl_prob,XPRB_BV,"x_1",0,1);   /* Define a variable */
     ...                       /* Define the rest of the problem */
  opt_prob = (XPRSprob)XPRBgetXPRSprob(bcl_prob);
  XPRSsetcbintsol(opt_prob, printsol, bcl_prob);
                               /* Define an integer solution callback */
  XPRBsetsense(bcl_prob, XPRB_MAXIM);  /* Select maximization */
  XPRBmipoptimize(bcl_prob,"");   /* Solve as MIP problem */
}

The synchronization between BCL and the Optimizer during the MIP search requires some special care. The code extract above shows how to use the functions XPRBbegincb and XPRBendcb to coordinate the BCL solution information with the Optimizer subproblem in a default multi-threaded MIP search. Alternatively, you may choose to disable parallelism by setting the XPRS_MIPTHREADS control to 1.

 opt_prob = XPRBgetXPRSprob(bcl_prob);
 XPRSsetintcontrol(opt_prob, XPRS_MIPTHREADS, 1);
                               /* Use single-threaded MIP */

MIP solution information can also be accessed through the Optimizer library functions whereby it is possible to use the column or row indices saved for BCL modeling objects as shown below. In this case there is no need for synchronizing the BCL solution information.

void XPRS_CC printsol(XPRSprob opt_prob,void *my_object)
{
 int num,ncol;
 XPRBprob bprob;
 XPRBvar x;
 double *sol, objval;

 bprob = (XPRBprob)vp;
 XPRSgetintattrib(oprob, XPRS_ORIGINALCOLS, &ncol);
                                           /* Get the number of columns */
 sol = (double *)malloc(ncol * sizeof(double));
  	                                   /* Create the solution array */
 XPRSgetintattrib(oprob, XPRS_MIPSOLS, &num); /* Get number of the solution */
 XPRSgetlpsol(oprob, sol, NULL, NULL, NULL);  /* Get the solution values */
 XPRSgetdblattrib(oprob, XPRS_LPOBJVAL, &objval);
 printf("Solution %d: Objective value: %g\n", num, objval);
 x = XPRBgetbyname(bprob, "x_1", XPRB_VAR);
 if(XPRBgetcolnum(x)>-1)
   printf("%s: %g\n", XPRBgetvarname(x), sol[XPRBgetcolnum(x)]);
 free(sol);
}

© 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.