| /********************************************************
  BCL Example Problems
  ====================
  file xbworks.c
  ``````````````
  Workshop planning example.
  (c) 2008 Fair Isaac Corporation
      author: S.Heipcke, Jan. 2000, rev. Mar. 2011
********************************************************/
#include <stdio.h>
#include "xprb.h"
#define NProd 2                  /* Number of products */
#define NShop 3                  /* Number of workshops */
#define WMAX 40                  /* Maximum weekly working time */ 
/****DATA****/
int DUR[][NShop] =  {{5, 9, 7},  /* Duration of product p on shop s */
                    {10, 2, 5}};
int RES[]   = {10, 8};           /* Man hours per unit */
int PRICE[] = {108, 84};         /* Selling price per unit */
/***********************************************************************/
int main(int argc, char **argv)
{
 int p,s;
 XPRBctr c; 
 XPRBvar x[NProd];                   /* Amount of product p */
 XPRBprob prob;
 prob=XPRBnewprob("Workshop");       /* Initialize a new problem in BCL */
/****VARIABLES****/
 for(p=0;p<NProd;p++)
  x[p] = XPRBnewvar(prob,XPRB_PL,"x",0,XPRB_INFINITY);
 
/****OBJECTIVE****/
 c = XPRBnewctr(prob,"OBJ",XPRB_N);  /* Objective: Maximize Benefit */
 for(p=0;p<NProd;p++)
  XPRBaddterm(c,x[p],PRICE[p]-5*RES[p]);
 XPRBsetobj(prob,c);                 /* Select objective function */ 
 
/****CONSTRAINTS****/
 for(s=0;s<NShop;s++)                /* Limit on weekly working hours */
 {
  c=XPRBnewctr(prob,"ResMax",XPRB_L);
  for(p=0;p<NProd;p++)
   XPRBaddterm(c,x[p],DUR[p][s]);
  XPRBaddterm(c,NULL,WMAX);
 }
 
/****SOLVING + OUTPUT****/
 XPRBsetsense(prob,XPRB_MAXIM);      /* Set obj. sense to maximization */    
 XPRBexportprob(prob,XPRB_MPS,"Works");  /* Output the matrix in MPS format */
 XPRBlpoptimize(prob,"");            /* Solve the LP-problem */
 printf("Objective: %g\n",XPRBgetobjval(prob));  /* Get objective value */
 for(p=0;p<NProd;p++)                /* Print the solution values */
  printf("%s:%g, ", XPRBgetvarname(x[p]), XPRBgetsol(x[p]));
 printf("\n");
 return 0;
} 
 | 
| /********************************************************
  BCL Example Problems
  ====================
  file xbworkrng.c
  ````````````````
  Workshop planning example.
  Test ranges and number printing format.
  (c) 2008 Fair Isaac Corporation
      author: S.Heipcke, 2003, rev. Mar. 2011
********************************************************/
#include <stdio.h>
#include "xprb.h"
#define NProd 2                  /* Number of products */
#define NShop 3                  /* Number of workshops */
#define WMAX 40                  /* Maximum weekly working time */ 
/****DATA****/
int DUR[][NShop] =  {{5, 9, 7},  /* Duration of product p on shop s */
                    {10, 2, 5}};
int RES[]   = {10, 8};           /* Man hours per unit */
int PRICE[] = {108, 84};         /* Selling price per unit */
/***********************************************************************/
int main(int argc, char **argv)
{
 int p,s;
 XPRBctr c[NShop],cobj; 
 XPRBvar x[NProd];                   /* Amount of product p */
 XPRBprob prob;
 prob=XPRBnewprob("Workshop");       /* Initialize a new problem in BCL */
/****VARIABLES****/
 for(p=0;p<NProd;p++)
  x[p] = XPRBnewvar(prob,XPRB_PL,"x",0,XPRB_INFINITY);
 
/****OBJECTIVE****/
 cobj = XPRBnewctr(prob,"OBJ",XPRB_N);  /* Objective: Maximize Benefit */
 for(p=0;p<NProd;p++)
  XPRBaddterm(cobj,x[p],PRICE[p]-5*RES[p]);
 XPRBsetobj(prob,cobj);              /* Select objective function */ 
 
/****CONSTRAINTS****/
 for(s=0;s<NShop;s++)                /* Limit on weekly working hours */
 {
  c[s]=XPRBnewctr(prob,"ResMax",XPRB_L);
  for(p=0;p<NProd;p++)
   XPRBaddterm(c[s],x[p],DUR[p][s]);
  XPRBaddterm(c[s],NULL,WMAX);
 }
 
/****SOLVING + OUTPUT****/
 XPRBsetrealfmt(prob, "%4.2e");
 for(p=0;p<NProd;p++)
 { XPRBprintvar(x[p]); printf(" "); }
 printf("\n");
 XPRBsetsense(prob,XPRB_MAXIM);      /* Set obj. sense to maximization */    
 XPRBlpoptimize(prob,"");            /* Solve the LP-problem */
 printf("Objective: %g\n",XPRBgetobjval(prob));  /* Get objective value */
 XPRBsetrealfmt(prob, "%g, ");
 for(p=0;p<NProd;p++)                /* Print the solution values */
  XPRBprintvar(x[p]);
 printf("\n");
 XPRBsetrealfmt(prob, "%8.4f");
 XPRBprintprob(prob);
                                 /* Row ranges */ 
 printf("Ctr: Lower activity, Upper activity, Unit cost DN, Unit cost UP\n");
 for(s=0;s<NShop;s++)
  printf("%s: %g, %g, %g, %g\n", XPRBgetctrname(c[s]),
          XPRBgetctrrng(c[s],XPRB_LOACT), XPRBgetctrrng(c[s],XPRB_UPACT),
          XPRBgetctrrng(c[s],XPRB_UDN), XPRBgetctrrng(c[s],XPRB_UUP));
                                 /* Column ranges */
 printf("Var: Lower activity, Upper activity, Unit cost DN, Unit cost UP, Lower profit, Upper profit\n");
 for(p=0;p<NProd;p++)
  printf("%s: %g, %g, %g, %g, %g, %g\n", XPRBgetvarname(x[p]),
          XPRBgetvarrng(x[p],XPRB_LOACT), XPRBgetvarrng(x[p],XPRB_UPACT),
          XPRBgetvarrng(x[p],XPRB_UDN), XPRBgetvarrng(x[p],XPRB_UUP),
          XPRBgetvarrng(x[p],XPRB_LCOST), XPRBgetvarrng(x[p],XPRB_UCOST));
 return 0;
} 
 |