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.java, xbcoco2.java, xbcoco3.java, xbcoco.java
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.java
/********************************************************
  Xpress-BCL Java Example Problems
  ================================

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

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


import com.dashoptimization.*;

public class xbcoco1
{
 public static void main(String[] args)
 {
  XPRB bcl;
  XPRBvar make11,make21,make12,make22;
  XPRBprob p;

  bcl = new XPRB();            /* Initialize BCL */
  p = bcl.newProb("Coco1");    /* Create a new problem in BCL */

/****VARIABLES****/
  make11 = p.newVar("make11"); /* Amount of prod. 1 to make at factory 1 */
  make21 = p.newVar("make21"); /* Amount of prod. 2 to make at factory 1 */
  make12 = p.newVar("make12"); /* Amount of prod. 1 to make at factory 2 */
  make22 = p.newVar("make22"); /* Amount of prod. 2 to make at factory 2 */

/****OBJECTIVE****/
              /* Define & set objective function: maximize total profit */ 
  p.setObj(make11.mul(50).add(make21.mul(125)).add(make12.mul(47))
    .add(make22.mul(132)) );

/****CONSTRAINTS****/
  p.newCtr("MxMake1", make11.add(make21).lEql(400) );
                               /* Capacity limit at factory 1 */

  p.newCtr("MxMake2", make12.add(make22).lEql(500) );
                               /* Capacity limit at factory 2 */

  p.newCtr("MxSell1", make11.add(make12).lEql(650) );
                               /* Limit on the amount of prod. 1 to be sold */

  p.newCtr("MxSell2", make21.add(make22).lEql(600) );
                               /* Limit on the amount of prod. 2 to be sold */

/****SOLVING + OUTPUT****/
  p.setSense(XPRB.MAXIM);      /* Choose the sense of the optimization */
  p.lpOptimize("");            /* Solve the LP-problem */
  System.out.println("Objective: " + p.getObjVal());  /* Get objective value */

               /* Print out the solution values for all variables */
  System.out.println(make11.getName() +": " + make11.getSol());
  System.out.println(make21.getName() +": " + make21.getSol());
  System.out.println(make12.getName() +": " + make12.getSol());
  System.out.println(make22.getName() +": " + make22.getSol()); 
 }
} 

xbcoco2.java
/********************************************************
  Xpress-BCL Java Example Problems
  ================================

  file xbcoco2.java
  `````````````````
  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
********************************************************/

import java.io.*;
import com.dashoptimization.*;

public class xbcoco2
{
 static final int NP = 2;        /* Number of products (p) */
 static final int NF = 2;        /*           factories (f) */
 static final int NR = 2;        /*           raw materials (r) */

 static final String REVFILE   = System.getProperty("XPRBDATA") + 
   "/coco/rev.dat";
 static final String CMAKEFILE = System.getProperty("XPRBDATA") + 
   "/coco/cmake.dat";
 static final String CBUYFILE  = System.getProperty("XPRBDATA") + 
   "/coco/cbuy.dat";
 static final String REQFILE   = System.getProperty("XPRBDATA") + 
   "/coco/req.dat";
 static final String MXSELLFILE= System.getProperty("XPRBDATA") + 
   "/coco/maxsell.dat";
 static final String MXMAKEFILE= System.getProperty("XPRBDATA") + 
   "/coco/mxmake.dat";

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

 static XPRB bcl;
 static XPRBprob pb;
 
/***********************************************************************/

 static void modCoco2()
 {
  XPRBvar[][] make;
  XPRBexpr lobj, lc;
  int p,f;

  bcl = new XPRB();            /* Initialize BCL */
  pb = bcl.newProb("Coco2");   /* Create a new problem in BCL */
 
/****VARIABLES****/
  make = new XPRBvar[NP][NF];
  for(p=0;p

xbcoco3.java
/********************************************************
  Xpress-BCL Java Example Problems
  ================================

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

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

import java.io.*;
import com.dashoptimization.*;

public class xbcoco3
{
 static final int NP = 2;    /* Number of products (p) */
 static final int NF = 2;    /*           factories (f) */
 static final int NR = 2;    /*           raw materials (r) */
 static final int NT = 4;    /*           time periods (t) */

 static final String REVFILE     = System.getProperty("XPRBDATA") + 
   "/coco/revt.dat";
 static final String CMAKEFILE   = System.getProperty("XPRBDATA") + 
   "/coco/cmake.dat";
 static final String CBUYFILE    = System.getProperty("XPRBDATA") + 
   "/coco/cbuyt.dat";
 static final String REQFILE     = System.getProperty("XPRBDATA") + 
   "/coco/req.dat";
 static final String MXSELLFILE  = System.getProperty("XPRBDATA") + 
   "/coco/maxsellt.dat";
 static final String MXMAKEFILE  = System.getProperty("XPRBDATA") + 
   "/coco/mxmake.dat";
 static final String PSTOCK0FILE = System.getProperty("XPRBDATA") + 
   "/coco/pstock0.dat";
 static final String RSTOCK0FILE = System.getProperty("XPRBDATA") + 
   "/coco/rstock0.dat";

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

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

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

 static void modCoco3()
 {
  XPRB bcl;
  XPRBvar[][][] make, sell, pstock, buy, rstock;
  XPRBexpr lobj, lc;
  int p,f,r,t;
 
  bcl = new XPRB();                   /* Initialize BCL */
  pb = bcl.newProb("Coco3");          /* Create a new problem in BCL */

/****VARIABLES****/
  make = new XPRBvar[NP][NF][NT];
  sell = new XPRBvar[NP][NF][NT]; 
  pstock = new XPRBvar[NP][NF][NT+1];
  buy = new XPRBvar[NR][NF][NT];
  rstock = new XPRBvar[NR][NF][NT+1];
  for(p=0;p

xbcoco.java
/********************************************************
  Xpress-BCL Java Example Problems
  ================================

  file xbcoco.java
  ````````````````
  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
********************************************************/

import com.dashoptimization.*;

public class xbcoco
{
 static final int 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 */
 
 static final int NP = 2;            /* Number of products (p) */
 static final int NF = 2;            /*           factories (f) */
 static final int NR = 2;            /*           raw materials (r) */
 static final int NT = 4;            /*           time periods (t) */

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

 public static void main(String[] args)
 {
  XPRB bcl;
  XPRBvar[][][] make, sell, pstock, buy, rstock; 
  XPRBvar[][] openm;
  XPRBexpr lobj, lc;
  int p,f,r,t; 
  XPRBprob pb;

  bcl = new XPRB();              /* Initialize BCL */
  pb = bcl.newProb("Coco");      /* Create a new problem in BCL */

/****VARIABLES****/
  make = new XPRBvar[NP][NF][NT];
  sell = new XPRBvar[NP][NF][NT]; 
  pstock = new XPRBvar[NP][NF][NT+1];
  buy = new XPRBvar[NR][NF][NT];
  rstock = new XPRBvar[NR][NF][NT+1];
  openm = new XPRBvar[NF][NT];
  for(p=0;p