Initializing help system before first use

Coco - A full production planning example


Type: Production planning
Rating: 2
Description: The Coco productional planning problem: multi-item, multi-period, multi-site production planning. A sequence of model versions show how the model was developed, to (a) use more sophisticated modeling features and (b) to extend the model, taking it from a simple linear model to one with fixed prices and logical decisions.
  1. xbcoco1: initial formulation, data, variables and constraints fixed
  2. xbcoco2: use parameters, data tables and subscripted variables.
    read data tables in from text data files (short-term planning).
  3. xbcoco3: like xbcoco2.c, but several time periods (mid-term planning).
  4. xbcoco : complete problem, data defined in the model definition (long-term planning).
File(s): xbcoco1.c, xbcoco2.c, xbcoco3.c, xbcoco.c
Data file(s): rev.dat, cmake.dat, cbuy.dat, req.dat, maxsell.dat, mxmake.dat, revt.dat, cbuyt.dat, maxsellt.dat, pstock0.dat, rstock0.dat


xbcoco1.c
/********************************************************
  BCL Example Problems
  ====================

  file xbcoco1.c
  ``````````````
  Coco Problem Phase 1. 
  Initial formulation: data, variables,
  and constraints fixed.

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

#include 
#include "xprb.h"

int main(int argc, char **argv)
{
 XPRBvar make11,make21,make12,make22;
 XPRBctr ctr;
 XPRBprob prob;

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

/****VARIABLES****/
 make11=XPRBnewvar(prob,XPRB_PL,"make11",0,XPRB_INFINITY);  
                                  /* Amount of prod. 1 to make at factory 1 */
 make21=XPRBnewvar(prob,XPRB_PL,"make21",0,XPRB_INFINITY);
                                  /* Amount of prod. 2 to make at factory 1 */
 make12=XPRBnewvar(prob,XPRB_PL,"make12",0,XPRB_INFINITY);
                                  /* Amount of prod. 1 to make at factory 2 */
 make22=XPRBnewvar(prob,XPRB_PL,"make22",0,XPRB_INFINITY);
                                  /* Amount of prod. 2 to make at factory 2 */
/****OBJECTIVE****/
 ctr = XPRBnewctr(prob,"OBJ",XPRB_N); 
 XPRBaddterm(ctr, make11,  50);   /* Objective: maximize total profit */
 XPRBaddterm(ctr, make21, 125); 
 XPRBaddterm(ctr, make12,  47); 
 XPRBaddterm(ctr, make22, 132); 
 XPRBsetobj(prob,ctr);            /* Select objective function */ 

/****CONSTRAINTS****/
 ctr=XPRBnewctr(prob,"MxMake1",XPRB_L);  /* Capacity limit at factory 1 */
 XPRBaddterm(ctr, make11, 1);
 XPRBaddterm(ctr, make21, 1); 
 XPRBaddterm(ctr, NULL, 400);

 ctr=XPRBnewctr(prob,"MxMake2",XPRB_L);  /* Capacity limit at factory 2 */
 XPRBaddterm(ctr, make12, 1);
 XPRBaddterm(ctr, make22, 1); 
 XPRBaddterm(ctr, NULL, 500);

 ctr=XPRBnewctr(prob,"MxSell1",XPRB_L);  /* Limit on amount of prod. 1 to be sold */
 XPRBaddterm(ctr, make11, 1);
 XPRBaddterm(ctr, make12, 1); 
 XPRBaddterm(ctr, NULL, 650);

 ctr=XPRBnewctr(prob,"MxSell2",XPRB_L);  /* Limit on amount of prod. 2 to be sold */
 XPRBaddterm(ctr, make21, 1);
 XPRBaddterm(ctr, make22, 1); 
 XPRBaddterm(ctr, NULL, 600);

/****SOLVING + OUTPUT****/
 XPRBsetsense(prob, XPRB_MAXIM);      /* Choose the sense of optimization */
 XPRBlpoptimize(prob, "");            /* Solve the LP-problem */
 printf("Objective: %g\n", XPRBgetobjval(prob));   /* Get objective value */

    /* Print out the solution values for all variables */
 printf("%s: %g\n",XPRBgetvarname(make11),XPRBgetsol(make11));
 printf("%s: %g\n",XPRBgetvarname(make21),XPRBgetsol(make21));
 printf("%s: %g\n",XPRBgetvarname(make12),XPRBgetsol(make12));
 printf("%s: %g\n",XPRBgetvarname(make22),XPRBgetsol(make22));
 
 return 0;
} 

xbcoco2.c
/********************************************************
  BCL Example Problems
  ====================

  file xbcoco2.c
  ``````````````
  Coco Problem Phase 2. 
  Use parameters, data tables and subscripted variables 
  to separate the model structure from the data. 
  Read data tables in from text data files.

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

#include 
#include "xprb.h"

#define NP 2            /* Number of products (p) */
#define NF 2            /*           factories (f) */
#define NR 2            /*           raw materials (r) */

#define REVFILE     XPRBDATAPATH "/coco/rev.dat"
#define CMAKEFILE   XPRBDATAPATH "/coco/cmake.dat"
#define CBUYFILE    XPRBDATAPATH "/coco/cbuy.dat"
#define REQFILE     XPRBDATAPATH "/coco/req.dat"
#define MXSELLFILE  XPRBDATAPATH "/coco/maxsell.dat"
#define MXMAKEFILE  XPRBDATAPATH "/coco/mxmake.dat"

/****TABLES****/
double REV[NP];         /* Unit selling price of product p */
double CMAK[NP][NF];    /* Unit cost to make product p at factory f */
double CBUY[NR];        /* Unit cost to buy raw material r */
double REQ[NP][NR];     /* Requirement by unit of prod. p for raw material r */
double MXSELL[NP];      /* Max. amount of p that can be sold */
double MXMAKE[NF];      /* Max. amount factory f can make over all products */
double PROFIT[NP][NF];  /* Profit contribution of product p at factory f */
 
/***********************************************************************/

void modcoco2(XPRBprob prob)
{
 XPRBvar make[NP][NF];
 XPRBctr ctr;
 int p,f;
 
/****VARIABLES****/
 for(p=0;p

xbcoco3.c
/********************************************************
  BCL Example Problems
  ====================

  file xbcoco3.c
  ``````````````
  Coco Problem Phase 3. 
  Introduce time periods and inventory.

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

#include 
#include "xprb.h"

#define NP 2           /* Number of products (p) */
#define NF 2           /* Factories (f) */
#define NR 2           /* Raw materials (r) */
#define NT 4           /* Time periods (t) */

#define REVFILE     XPRBDATAPATH "/coco/revt.dat"
#define CMAKEFILE   XPRBDATAPATH "/coco/cmake.dat"
#define CBUYFILE    XPRBDATAPATH "/coco/cbuyt.dat"
#define REQFILE     XPRBDATAPATH "/coco/req.dat"
#define MXSELLFILE  XPRBDATAPATH "/coco/maxsellt.dat"
#define MXMAKEFILE  XPRBDATAPATH "/coco/mxmake.dat"
#define PSTOCK0FILE XPRBDATAPATH "/coco/pstock0.dat"
#define RSTOCK0FILE XPRBDATAPATH "/coco/rstock0.dat"

/****TABLES****/
double REV[NP][NT];     /* Unit selling price of product p in period t */
double CMAK[NP][NF];    /* Unit cost to make product p at factory f */
double CBUY[NR][NT];    /* Unit cost to buy raw material r in period t */
double REQ[NP][NR];     /* Requirement by unit of prod. p for raw material r */
double MXSELL[NP][NT];  /* Max. amount of p that can be sold in period t */
double MXMAKE[NF];      /* Max. amount factory f can make over all products */
double PSTOCK0[NP][NF]; /* Initial product p stock level at factory f */
double RSTOCK0[NR][NF]; /* Initial raw material r stock level at factory f*/

/****DATA****/
double CPSTOCK = 2.0;   /* Unit cost to store any product p */
double CRSTOCK = 1.0;   /* Unit cost to store any raw material r */
double MXRSTOCK = 300;  /* Max. amount of r that can be stored each f and t */
 
/***********************************************************************/

void modcoco3(XPRBprob prob)
{
 XPRBvar make[NP][NF][NT], sell[NP][NF][NT], pstock[NP][NF][NT+1],
         buy[NR][NF][NT], rstock[NR][NF][NT+1];
 XPRBctr ctr;
 int p,f,r,t;
 
/****VARIABLES****/
 for(p=0;p

xbcoco.c
/********************************************************
  BCL Example Problems
  ====================

  file xbcoco.c
  `````````````
  Complete Coco Problem. 
  Specify phase by PHASE parameter. 
  Data input in the model, not via data files.

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

#include 
#include "xprb.h"

#define PHASE 5
/* Phase = 3: Multi-period parameterised model; mines always open
 * Phase = 4: Mines may open/closed freely; when closed save 20000 per month
 * Phase = 5: Once closed always closed; larger saving */
 
#define NP 2            /* Number of products (p) */
#define NF 2            /*           factories (f) */
#define NR 2            /*           raw materials (r) */
#define NT 4            /*           time periods (t) */

/****DATA****/
double REV[][NT] =      /* Unit selling price of product p in period t */
        {{400, 380, 405, 350},
         {410, 397, 412, 397}};
double CMAK[][NF] =     /* Unit cost to make product p at factory f */
        {{150, 153},
         { 75,  68}};
double CBUY[][NT] =     /* Unit cost to buy raw material r in period t */
        {{100,  98,  97, 100},
         {200, 195, 198, 200}};
double COPEN[] =        /* Fixed cost of factory f being open for one period */
        {50000, 63000};
double CPSTOCK = 2.0;   /* Unit cost to store any product p */
double CRSTOCK = 1.0;   /* Unit cost to store any raw material r */
double REQ[][NR] =      /* Requirement by unit of prod. p for raw material r */
        {{1.0, 0.5},
         {1.3, 0.4}};
double MXSELL[][NT] =   /* Max. amount of p that can be sold in period t */
        {{650, 600, 500, 400},
         {600, 500, 300, 250}};
double MXMAKE[] =       /* Max. amount factory f can make over all products */
        {400, 500};
double MXRSTOCK = 300;  /* Max. amount of r that can be stored each f and t */
double PSTOCK0[][NF] =  /* Initial product p stock level at factory f */
        {{50, 100},
         {50,  50}};
double RSTOCK0[][NF] =  /* Initial raw material r stock level at factory f*/
        {{100, 150},
         { 50, 100}};
 
/***********************************************************************/

int main(int argc, char **argv)
{
 XPRBvar make[NP][NF][NT], sell[NP][NF][NT], pstock[NP][NF][NT+1],
       buy[NR][NF][NT], rstock[NR][NF][NT+1], openm[NF][NT];
 XPRBctr ctr;
 int p,f,r,t;
 XPRBprob prob;

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

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