Initializing help system before first use

UG - Examples from 'BCL Reference Manual'


Type: Programming
Rating: 3
Description: The following examples are discussed in detail in the 'BCL User Guide and Reference Manual':
  • modeling and solving a small MIP scheduling problem (xbexpl1 version BASIC)
  • using variable arrays and constraint templates (xbexpl1 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)
  • 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)
File(s): xbexpl1.cxx, xbexpl1i.cxx, xbexpl3.cxx, xbexpl2.cxx, xbcutex.cxx, xbqpr12.cxx, xbairport.cxx, xbcontr1.cxx, xbcontr2.cxx, xbcontr2s.cxx
Data file(s): durations.dat


xbexpl1.cxx
/********************************************************
  Xpress-BCL C++ Example Problems
  ===============================

  file xbexpl1.cxx
  ````````````````
  BCL user guide example.
  Definition of variables and constraints, 
  variable arrays and SOS, followed by file output,
  solving and printing of solutions.

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

#include 
#include "xprb_cpp.h"

using namespace std;
using namespace ::dashoptimization;

/**************************************************************************/
/* Define the following option to try out a problem formulation using     */
/* Special Ordered Sets:                                                  */
#undef SOS

/**************************************************************************/

#define NJ    4             /* Number of jobs */   
#define NT   10             /* Time limit */   

/**** DATA ****/
double DUR[] = {3,4,2,2};   /* Durations of jobs   */ 

XPRBvar start[NJ];          /* Start times of jobs  */ 
XPRBvar delta[NJ][NT];      /* Binaries for start times */  
XPRBvar z;                  /* Maximum completion time (makespan) */ 
XPRBsos set[NJ];            /* Sets regrouping start times for jobs */
 
void jobsModel(void);       /* Basic model formulation */
void jobsModelb(void);      /* Model using SOS */
void jobsSolve(void);       /* Solving and solution printing */

XPRBprob p("Jobs");         /* Initialize BCL and a new problem */ 
             
/*************************************************************************/

void jobsModel()
{
 XPRBexpr le;
 int j,t;

/****VARIABLES****/
                                /* Create start time variables */
 for(j=0;j

xbexpl1i.cxx
/********************************************************
  Xpress-BCL C++ Example Problems
  ===============================

  file xbexpl1i.cxx
  `````````````````
  BCL user guide example.
  Version using index sets.

  (c) 2008 Fair Isaac Corporation
      author: S.Heipcke, 2003, rev. Mar. 2011
********************************************************/

#include 
#include 
#include 
#include "xprb_cpp.h"

using namespace std;
using namespace ::dashoptimization;

#define MAXNJ 4             /* Max. number of jobs */   
#define NT   10             /* Time limit */   

#define DATAFILE XPRBDATAPATH "/jobs/durations.dat"

/**** DATA ****/
int NJ = 0;	            /* Number of jobs read in */
double DUR[MAXNJ];          /* Durations of jobs   */ 

XPRBindexSet Jobs;	    /* Job names */
XPRBvar *start;             /* Start times of jobs  */ 
XPRBvar **delta;            /* Binaries for start times */  
XPRBvar z;                  /* Maximum completion time (makespan) */ 
 
void readData(void);        /* Read data from file  */
void jobsModel(void);       /* Basic model formulation */
void jobsSolve(void);       /* Solving and solution printing */

XPRBprob p("Jobs");         /* Initialize BCL and a new problem */ 
             
/*************************************************************************/

void readData()
{ 
 char name[100];
 FILE *datafile;
                             /* Create a new index set */
 Jobs = p.newIndexSet("jobs", MAXNJ);

 datafile=fopen(DATAFILE,"r");  /* Open the data file for read access */
 while(NJ

xbexpl3.cxx
/********************************************************
  Xpress-BCL C++ Example Problems
  ===============================

  file xbexpl3.cxx
  ````````````````
  User error handling and output redirection.

  (c) 2008 Fair Isaac Corporation
      author: Y.Colombani, 2006, rev. Mar. 2011
********************************************************/

#include 
#include 
#include 
#include "xprb_cpp.h"

using namespace std;
using namespace ::dashoptimization;

/* This small, infeasible example shows how the error handling and all 
   printed messages can be intercepted by the user's program. This is done 
   by defining the corresponding BCL callback functions and changing 
   the error handling flag. */

/***********************************************************************/

class bcl_exception
{
 public:
   string msg;
   int code;
   bcl_exception(int c,const char *m)
   {
    code=c;
    msg=string(m);
    cout << "EXCP:" << msg << "\n";
   }
};

/***********************************************************************/

/**** User error handling function ****/
void XPRB_CC usererror(xbprob* prob, void *vp, int num, int type, 
                       const char *t)
{
 throw bcl_exception(num, t);
}


/**** User printing function ****/
void XPRB_CC userprint(xbprob* prob, void *vp, const char *msg)   
{
 static int rtsbefore=1;

    /* Print 'BCL output' whenever a new output line starts,
       otherwise continue to print the current line. */ 
 if(rtsbefore)
  cout << "BCL output: " << msg;
 else
  cout << msg;
 rtsbefore=(msg[strlen(msg)-1]=='\n');
}

/***********************************************************************/

void modexpl3(XPRBprob &p)
{
 XPRBvar x[3];
 XPRBlinExp le;
 int i;

 for(i=0;i<2;i++) x[i]=p.newVar(XPRBnewname("x_%d",i), XPRB_UI, 0, 100);

                /* Create the constraints:
                   C1: 2x0 + 3x1 >= 41
                   C2:  x0 + 2x1  = 13 */
 p.newCtr("C1", 2*x[0] + 3*x[1] >= 41);
 p.newCtr("C2", x[0] + 2*x[1] == 13);

// Uncomment the following line to cause an error in the model that
// triggers the user error handling:

// x[2]=p.newVar("x_2", XPRB_UI, 10,1);
 
                // Objective: minimize x0+x1 
 le=0; 
 for(i=0;i<2;i++) le += x[i]; 
 p.setObj(le);                   // Select objective function
 p.setSense(XPRB_MINIM);         // Set objective sense to minimization

 p.print();                      // Print current problem definition

 p.lpOptimize("");               // Solve the LP
 XPRBprintf(p.getCRef(), "problem status: %d  LP status: %d  MIP status: %d\n",
    p.getProbStat(), p.getLPStat(), p.getMIPStat());

// This problem is infeasible, that means the following command will fail.
// It prints a warning if the message level is at least 2 
   
 XPRBprintf(p.getCRef(), "Objective: %g\n", p.getObjVal());

 for(i=0;i<2;i++)                // Print solution values 
  XPRBprintf(p.getCRef(), "%s:%g, ", x[i].getName(), x[i].getSol());
 XPRBprintf(p.getCRef(), "\n");
}

/***********************************************************************/

int main()
{
 XPRBprob *p;

 XPRBseterrctrl(0);     // Switch to error handling by the user's program
 XPRB::setMsgLevel(2);       // Set the printing flag. Try other values:
                             // 0 - no printed output, 1 - only errors,
                             // 2 - errors and warnings, 3 - all messages
                        // Define the callback functions: 
 XPRBdefcbmsg(NULL, userprint, NULL);  
 XPRBdefcberr(NULL, usererror, NULL);

 try
 {
  p=new XPRBprob("Expl3");   // Initialize a new problem in BCL
 }
 catch(bcl_exception &e)
 {
  cout << e.code << ":" << e.msg;
  return 1;
 }

 try
 {
  modexpl3(*p);              // Formulate and solve the problem
 }
 catch(bcl_exception &e)
 {
  cout << e.code << ":" << e.msg << "\n";
//  return 2;
 }
 catch(const char *m)
 {
  cout << m << "\n";
  return 3;
 }
 catch(...)
 {
  cout << "other exception\n";
  return 4;
 }
 return 0;

}

xbexpl2.cxx
/********************************************************
  Xpress-BCL C++ Example Problems
  ===============================

  file xbexpl2.cxx
  ````````````````
  Transportation model demonstrating use of index sets.

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


#include 
#include 
#include "xprb_cpp.h"

using namespace std;
using namespace ::dashoptimization;

#define MaxSuppliers 100         /* Max. number of suppliers */
#define MaxCustomers 1000        /* Max. number of customers */
#define MaxArcs 10000            /* Max. number of non-zero cost values */
#define DEMANDFILE XPRBDATAPATH "/trans/ex2dem1.dat"  
                                 /* Demand data file (comma-separated format) */
#define AVAILFILE XPRBDATAPATH "/trans/ex2avail.dat" 
                                 /* Supply data file (comma-separated format) */
#define COSTFILE XPRBDATAPATH "/trans/ex2cost.dat"   
                                 /* Cost data file (comma-separated format) */

XPRBindexSet Suppliers;          /* Set of suppliers */
XPRBindexSet Customers;          /* Set of customers */
double AVAIL[MaxSuppliers];      /* Availability of products */
double DEMAND[MaxCustomers];     /* Demand by customers */
struct {
        int suppl;
        int custm;
        double value;
} COST[MaxArcs];                 /* Cost per supplier-customer pair */

int NSuppl=0,NCustom=0, NArc=0;  /* Actual numbers of suppliers, customers, 
                                    and arcs */

XPRBprob p("Trans");             /* Initialize a new problem in BCL */

/***********************************************************************/

void modTrans()
{
 XPRBexpr lobj, *av,*de;
 int s,c,a;
 XPRBvar *x;
 
/****VARIABLES****/
 x = new XPRBvar[NArc];
 if(x==NULL) cout << "Allocating memory for variables failed." << endl;
 for(a=0; a= DEMAND[c]);

/****SOLVING + OUTPUT****/
 p.exportProb(XPRB_MPS,"trans");   /* Matrix generation & output to MPS file */

 p.lpOptimize("");                 /* Solve the LP-problem */
 cout << "Objective: " << p.getObjVal() << endl;   /* Get objective value */

 for(a=0; a0)
 {
  cout << Suppliers[COST[a].suppl] << " (" << AVAIL[COST[a].suppl] << ") -> ";
  cout << Customers[COST[a].custm] << " (" << DEMAND[COST[a].custm] << "): ";
  cout << x[a].getSol() << endl;  
 }
 delete [] de;   
 delete [] av;
 delete [] x;
}

/***********************************************************************/

    /**** Read data from files ****/
void readData()
{
 double value;
 FILE *datafile;
 char name[100], name2[100];
 
        /* Create supplier and customer index sets */
 Suppliers=p.newIndexSet("suppl",MaxSuppliers);
 Customers=p.newIndexSet("custom",MaxCustomers);
 
        /* Read the demand data file */
 datafile=fopen(DEMANDFILE,"r");
 while (XPRBreadlinecb(XPRB_FGETS, datafile, 200, "T,g", name, &value) == 2)
  DEMAND[Customers+=name]=value;
 fclose(datafile);
 NCustom = Customers.getSize();

        /* Read the supply data file */
 datafile=fopen(AVAILFILE,"r");
 while (XPRBreadlinecb(XPRB_FGETS, datafile, 200, "T,g", name, &value) == 2)
  AVAIL[Suppliers+=name]=value;
 fclose(datafile);
 NSuppl = Suppliers.getSize();

        /* Read the cost data file */
 NArc = 0;
 datafile=fopen(COSTFILE,"r");
 while (XPRBreadlinecb(XPRB_FGETS, datafile, 200, "T,T,g", name, 
        name2, &value) == 3)
 {
  COST[NArc].suppl = Suppliers[name];
  COST[NArc].custm = Customers[name2];
  if(COST[NArc].custm<0) printf("Cust(%s)\n",name2);
  if(COST[NArc].suppl<0) printf("Supp(%s)\n",name);
  COST[NArc++].value = value;
 }
 fclose(datafile);
 printf("C: %d  S: %d  A: %d\n",NCustom,NSuppl,NArc);
}

/***********************************************************************/

int main(int argc, char **argv)
{
 readData();            /* Data input from file */
 modTrans();            /* Formulate and solve the problem */
 
 return 0;
} 

xbcutex.cxx
/********************************************************
  Xpress-BCL C++ Example Problems
  ===============================

  file xbcutex.cxx
  ````````````````
  Simplified version of xbexpl1.cxx showing how 
  to define cuts with BCL.

  (c) 2008 Fair Isaac Corporation
      author: S.Heipcke, 2005, rev. Mar. 2011
********************************************************/

#include 
#include "xprb_cpp.h"
#include "xprs.h"

using namespace std;
using namespace ::dashoptimization;

#define NJ    4             /* Number of jobs */   
#define NT   10             /* Time limit */   

/**** DATA ****/
double DUR[] = {3,4,2,2};   /* Durations of jobs   */ 

XPRBvar start[NJ];          /* Start times of jobs  */ 
XPRBvar delta[NJ][NT];      /* Binaries for start times */  
XPRBvar z;                  /* Maximum completion time (makespan) */ 
 
void jobsModel(void);       /* Basic model formulation */
void jobsSolve(void);       /* Solving and solution printing */

XPRBprob p("Jobs");         /* Initialize BCL and a new problem */ 
             
/***********************************************************************/

int XPRS_CC usrcme(XPRSprob oprob, void* vd)
{
 XPRBcut ca[2];
 int num;
 int i=0;
 XPRBprob *bprob;

/* In terms of an example, we add a few additional constraints (without
   any relation to the original problem) at the second node of the MIP
   search tree. These constraints/cuts are applied at this node and all 
   its child nodes. */
 
 bprob = (XPRBprob*)vd;
 bprob->beginCB(oprob);
 XPRSgetintattrib(oprob, XPRS_NODES, &num);
 if(num == 2) 
 {
  ca[0] = bprob->newCut(start[1]+2 <= start[0], 2); 
  ca[1] = bprob->newCut(4*start[2] - 5.3*start[3] <= -17, 2);
  cout << "Adding constraints:" << endl;
  for(i=0;i<2;i++) ca[i].print();
  if(bprob->addCuts(ca,2)) cout << "Problem with adding cuts." << endl;
 }
 bprob->endCB();
 return 0;                      /* Call this function once per node */
}

/*************************************************************************/

void jobsModel()
{
 XPRBexpr le;
 int j,t;

/****VARIABLES****/
                                /* Create start time variables */
 for(j=0;j

xbqpr12.cxx
/********************************************************
  Xpress-BCL C++ Example Problems
  ===============================

  file xbqpr12.cxx
  ````````````````
  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
            0<=x1<=20
            0<=x2,x3
            x4 free

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

#include 
#include "xprb_cpp.h"

using namespace std;
using namespace ::dashoptimization;

#define NXPRBvar 4

/***********************************************************************/

int main(int argc, char **argv)
{
 XPRBctr c;
 XPRBexpr le, qobj;
 XPRBvar x[NXPRBvar];
 int i;
 XPRBprob p("QPr12");     	/* Initialize a new problem in BCL */

/**** VARIABLES ****/
 x[0] = p.newVar("x1", XPRB_PL, 0, 20);
 x[1] = p.newVar("x2");
 x[2] = p.newVar("x3");
 x[3] = p.newVar("x4", XPRB_PL, -XPRB_INFINITY, XPRB_INFINITY);

/****OBJECTIVE****/
		                  /* Define the objective function */
 qobj = x[0] + sqr(x[0])  +2*x[0]*x[1]  + 2*sqr(x[1])  + sqr(x[3]);
 p.setObj(qobj);
 
/**** CONSTRAINTS ****/
 p.newCtr("C1", x[0] + 2*x[1] - 4*x[3] >= 0);
 p.newCtr("C2", 3*x[0] - 2*x[2] -x[3] <= 100);
 c = p.newCtr("C3", x[0] + 3*x[1] + 3*x[2] - 2*x[3] );
 c.setRange(10,30);
   
/****SOLVING + OUTPUT****/
 p.print();			  /* Print out the problem definition */
 p.exportProb(XPRB_MPS,"QPr12");  /* Output the matrix in MPS format */
 p.exportProb(XPRB_LP,"QPr12");   /* Output the matrix in LP format */
  
 p.setSense(XPRB_MINIM);      	  /* Choose the sense of the optimization */   
 p.lpOptimize("");                /* Solve the QP-problem */

 cout << "Objective function value: " << p.getObjVal() << endl;
 for(i=0;i

xbairport.cxx
/********************************************************
  BCL Example Problems
  ====================

  file xbairport.cxx
  ``````````````````
  QCQP problem by
      Rodrigo de Barros Nabholz & Maria Aparecida Diniz Ehrhardt
      November 1994, DMA - IMECC- UNICAMP.
  Based on AMPL model airport.mod by Hande Y. Benson
  (Source: http://www.orfe.princeton.edu/~rvdb/ampl/nlmodels/ )
   
  (c) 2008 Fair Isaac Corporation
      author: S.Heipcke, June 2008, rev. Mar. 2011
********************************************************/

#include 
#include "xprb_cpp.h"
#include "xprs.h"

using namespace std;
using namespace ::dashoptimization;

#define N 42

double CX[] = {-6.3, -7.8, -9, -7.2, -5.7, -1.9, -3.5, -0.5, 1.4, 4,
               2.1, 5.5, 5.7, 5.7, 3.8, 5.3, 4.7, 3.3, 0, -1, -0.4, 4.2, 
               3.2, 1.7, 3.3, 2, 0.7, 0.1, -0.1, -3.5, -4, -2.7, -0.5, -2.9,
               -1.2, -0.4, -0.1, -1, -1.7, -2.1, -1.8, 0};
double CY[] = {8, 5.1, 2, 2.6, 5.5, 7.1, 5.9, 6.6, 6.1, 5.6, 4.9, 4.7, 
               4.3, 3.6, 4.1, 3, 2.4, 3, 4.7, 3.4, 2.3, 1.5, 0.5, -1.7, -2,
               -3.1, -3.5, -2.4, -1.3, 0, -1.7, -2.1, -0.4, -2.9, -3.4, -4.3,
               -5.2, -6.5, -7.5, -6.4, -5.1, 0};
double R[] = {0.09, 0.3, 0.09, 0.45, 0.5, 0.04, 0.1, 0.02, 0.02, 0.07, 0.4, 
              0.045, 0.05, 0.056, 0.36, 0.08, 0.07, 0.36, 0.67, 0.38, 0.37, 
              0.05, 0.4, 0.66, 0.05, 0.07, 0.08, 0.3, 0.31, 0.49, 0.09, 
              0.46, 0.12, 0.07, 0.07, 0.09, 0.05, 0.13, 0.16, 0.46, 0.25, 0.1};

int main(int argc, char **argv)
{
 int i,j;
 XPRBvar x[N],y[N];
 XPRBexpr qe;
 XPRBctr cobj, c;
 XPRBprob prob("airport");              // Initialize a new problem in BCL

/**** VARIABLES ****/
 for(i=0;i

xbcontr1.cxx
/********************************************************
  Xpress-BCL C++ Example Problems
  ===============================

  file xbcontr1.cxx
  `````````````````
  Contract allocation example.
  Combining BCL problem input with problem solving 
  in Xpress-Optimizer.

  (c) 2008 Fair Isaac Corporation
      author: S.Heipcke, Jan. 2000, rev. Oct. 2010
********************************************************/

#include 
#include 
#include "xprb_cpp.h"
#include "xprs.h"

using namespace std;
using namespace ::dashoptimization;

#define District 6               /* Number of districts */
#define Contract 10              /* Number of contracts */

/**** DATA ****/
int OUTPUT[] = {50, 40, 10, 20, 70, 50};    /* Max. output per district */
int COST[]   = {50, 20, 25, 30, 45, 40};    /* Cost per district */
int VOLUME[]   = {20, 10, 30, 15, 20, 30, 10, 50, 10, 20};  
                                 /* Volume of contracts */
 
/***********************************************************************/

int main(int argc, char **argv)
{
 int d,c;
 XPRBexpr l1,l2,lobj;
 XPRBvar x[District][Contract];  /* Variables indicating whether a project 
                                    is chosen */
 XPRBvar y[District][Contract];  /* Quantities allocated to contractors */
 int i, ncol, len, stat, offset;
 double *sol, val;
 char *names;
 XPRSprob op;
 XPRBprob p("Contr1");                /* Initialize a new problem in BCL */
 
/**** VARIABLES ****/
 for(d=0;d= VOLUME[c]);  /* "Size": cover the required volume */
  p.newCtr("Min", l2 >= 2 ); 	/* "Min": at least 2 districts per contract */
 }
 
 for(d=0;d

xbcontr2.cxx
/********************************************************
  Xpress-BCL C++ Example Problems
  ===============================

  file xbcontr2.cxx
  `````````````````
  Contract allocation example.
  Combining BCL problem input with problem solving 
  and callbacks in Xpress-Optimizer.

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

#include 
#include "xprb_cpp.h"
#include "xprs.h"

using namespace std;
using namespace ::dashoptimization;

#define District 6               /* Number of districts */
#define Contract 10              /* Number of contracts */

/**** DATA ****/
int OUTPUT[] = {50, 40, 10, 20, 70, 50};    /* Max. output per district */
int COST[]   = {50, 20, 25, 30, 45, 40};    /* Cost per district */
int VOLUME[]   = {20, 10, 30, 15, 20, 30, 10, 50, 10, 20};  
                                 /* Volume of contracts */
 
/***********************************************************************/

void XPRS_CC printsolution(XPRSprob oprob, void *vp)
{
 int num, d, c;
 XPRBprob *bprob;
 XPRBvar y;
 
 bprob = (XPRBprob *)vp;
 bprob->beginCB(oprob);
 XPRSgetintattrib(oprob, XPRS_MIPSOLS, &num); /* Get number of the solution */
 bprob->sync(XPRB_XPRS_SOL);                  /* Update BCL solution values */
 cout << "Solution " << num << ": Objective value: " << bprob->getObjVal() << endl; 

 for(d=0;dgetVarByName(XPRBnewname("q_d%dc%d",d+1,c+1));
   if( (y.getColNum()>-1) && (y.getSol() != 0))
    cout << y.getName() << ": " << y.getSol() << endl; 
  }
  
 bprob->endCB();
}

/***********************************************************************/

int main(int argc, char **argv)
{
 int d,c;
 XPRBexpr l1,l2,lobj;
 XPRBvar x[District][Contract];  /* Variables indicating whether a project 
                                    is chosen */
 XPRBvar y[District][Contract];  /* Quantities allocated to contractors */
 XPRBprob p("Contr2");           /* Initialize a new problem in BCL */
 
/**** VARIABLES ****/
 for(d=0;d= VOLUME[c]);   /* "Size": cover the required volume */
  p.newCtr("Min", l2 >= 2 ); 	/* "Min": at least 2 districts per contract */
 }
 
 for(d=0;d

xbcontr2s.cxx
/********************************************************
  Xpress-BCL C++ Example Problems
  ===============================

  file xbcontr2s.cxx
  ``````````````````
  Contract allocation example.
  Combining BCL problem input with problem solving 
  and callbacks in Xpress-Optimizer.
  -- Single MIP thread --

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

#include 
#include "xprb_cpp.h"
#include "xprs.h"

using namespace std;
using namespace ::dashoptimization;

#define District 6               /* Number of districts */
#define Contract 10              /* Number of contracts */

/**** DATA ****/
int OUTPUT[] = {50, 40, 10, 20, 70, 50};    /* Max. output per district */
int COST[]   = {50, 20, 25, 30, 45, 40};    /* Cost per district */
int VOLUME[]   = {20, 10, 30, 15, 20, 30, 10, 50, 10, 20};  
                                 /* Volume of contracts */
 
/***********************************************************************/

void XPRS_CC printsolution(XPRSprob oprob, void *vp)
{
 int num, d, c;
 XPRBprob *bprob;
 XPRBvar y;
 
 bprob = (XPRBprob *)vp;
 XPRSgetintattrib(oprob, XPRS_MIPSOLS, &num); /* Get number of the solution */
 bprob->sync(XPRB_XPRS_SOL);                  /* Update BCL solution values */
 cout << "Solution " << num << ": Objective value: " << bprob->getObjVal() << endl; 

 for(d=0;dgetVarByName(XPRBnewname("q_d%dc%d",d+1,c+1));
   if( (y.getColNum()>-1) && (y.getSol() != 0))
    cout << y.getName() << ": " << y.getSol() << endl; 
  }
}

/***********************************************************************/

int main(int argc, char **argv)
{
 int d,c;
 XPRBexpr l1,l2,lobj;
 XPRBvar x[District][Contract];  /* Variables indicating whether a project 
                                    is chosen */
 XPRBvar y[District][Contract];  /* Quantities allocated to contractors */
 XPRBprob p("Contr2");           /* Initialize a new problem in BCL */
 
/**** VARIABLES ****/
 for(d=0;d= VOLUME[c]);   /* "Size": cover the required volume */
  p.newCtr("Min", l2 >= 2 ); 	/* "Min": at least 2 districts per contract */
 }
 
 for(d=0;d