FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

UG - Examples from 'BCL Reference Manual'

The following examples are discussed in detail in the 'BCL User Guide and Reference Manual':
  • modeling and solving a small MIP scheduling problem (xbexpl1.c version BASIC)
  • using variable arrays and constraint templates (xbexpl1.c versions ARRAY and ARRAYC)
  • definition of SOS-1 (xbexpl1 version SOS)
  • data input from file, index sets (xbexpl1i)
  • user error handling, output redirection (xbexpl3)
  • solving multiple scenarios of a transportation problem in parallel (xbexpl2: standard, single thread version; xbscenar: defining multiple problems, each in a separate thread)
  • cut generation / adding cuts at MIP tree nodes (xbcutex)
  • quadratic programming (quadratic objective: xbqpr12, quadratic constraints: xbairport)
  • combine BCL problem input with problem solving in Xpress Optimizer (xbcontr1)
  • use an Xpress Optimizer solution callback with a BCL model (xbcontr2s: single MIP thread; xbcontr2: multiple MIP threads)
Further explanation of this example: 'BCL Reference Manual', Appendix B Using BCL with the Optimizer library

Source Files

Data Files


  BCL Example Problems

  file xbqpr12.c
  Small Quadratic Programming example.
       minimize x1 + x1^2 +2x1x2 +2x2^2 +x4^2
       s.t. C1:  x1 +2x2 -4x4 >= 0
            C2: 3x1 -2x3 - x4 <= 100
            C3: 10 <= x1 +3x2 +3x3 -2x4 <= 30
            x4 free

  (c) 2008 Fair Isaac Corporation
      author: S.Heipcke, Jan. 2000, rev. Mar. 2011

#include <stdio.h>
#include "xprb.h"

#define NVar 4


int main(int argc, char **argv)
 XPRBctr cobj, c;
 XPRBvar x[NVar];
 int i;
 XPRBprob prob;

 prob=XPRBnewprob("QPr12");       /* Initialize a new problem in BCL */

/**** VARIABLES ****/
 x[0] = XPRBnewvar(prob,XPRB_PL,"x1",0,20);
 x[1] = XPRBnewvar(prob,XPRB_PL,"x2",0,XPRB_INFINITY);
 x[2] = XPRBnewvar(prob,XPRB_PL,"x3",0,XPRB_INFINITY);

 cobj = XPRBnewctr(prob,"OBJ",XPRB_N);
 XPRBaddterm(cobj, x[0],1);
		                  /* Define quadratic part of the objective */

/**** CONSTRAINTS ****/
 c = XPRBnewctr(prob,"C1",XPRB_G);
 XPRBaddterm(c, x[0], 1);
 XPRBaddterm(c, x[1], 2);
 XPRBaddterm(c, x[3], -4);

 c = XPRBnewctr(prob,"C2",XPRB_L);
 XPRBaddterm(c, x[0], 3);
 XPRBaddterm(c, x[2], -2);
 XPRBaddterm(c, x[3], -1);
 XPRBaddterm(c, NULL, 100);

 c = XPRBnewctr(prob,"C3",XPRB_L);
 XPRBaddterm(c, x[0], 1);
 XPRBaddterm(c, x[1], 3);
 XPRBaddterm(c, x[2], 3);
 XPRBaddterm(c, x[3], -2);
 XPRBsetrange(c, 10, 30);

/****SOLVING + OUTPUT****/
 XPRBprintprob(prob);                   /* Print out the problem definition */
 XPRBexportprob(prob,XPRB_MPS,"QPr12"); /* Output the matrix in MPS format */
 XPRBexportprob(prob,XPRB_LP,"QPr12");  /* Output the matrix in LP format */

 XPRBsetsense(prob,XPRB_MINIM);         /* Choose the sense of optimization */
 XPRBlpoptimize(prob,"");               /* Solve the QP-problem */

 printf("Objective function value: %g\n", XPRBgetobjval(prob));
  printf("%s: %g, ", XPRBgetvarname(x[i]), XPRBgetsol(x[i]));

 return 0;

Back to examples browserPrevious exampleNext example