Initializing help system before first use

Cutstk - Column generation for a cutting stock problem


Type: Cutting stock
Rating: 4
Description: This example features iteratively adding new variables, basis in/output and working with subproblems. The column generation algorithm is implemented as a loop over the root node of the MIP problem.
File(s): xbcutstk.java


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

  file xbcutstk.java
  ``````````````````
  Cutting stock problem, solved by column (= cutting
  pattern) generation heuristic looping over the
  root node.

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

import java.lang.*;
import com.dashoptimization.*;

public class xbcutstk
{
 static final int NWIDTHS = 5;
 static final int MAXWIDTH = 94;

 static final double EPS = 1e-6;
 static final int MAXCOL = 10;

/****DATA****/
 static final double[] WIDTH = {17, 21, 22.5,  24, 29.5}; /* Possible widths */
 static final int[] DEMAND = {150, 96,   48, 108,  227};  /* Demand per width */
 static int[][] PATTERNS;    /* (Basic) cutting patterns */

 static XPRBvar[] pat;              /* Rolls per pattern */
 static XPRBctr[] dem;              /* Demand constraints */
 static XPRBctr cobj;               /* Objective function */

 static XPRB bcl;
 static XPRBprob p;

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

 static void modCutStock() throws XPRSexception
 {
  int i,j;
  XPRBexpr le;

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

  PATTERNS = new int[NWIDTHS][NWIDTHS];
  for(j=0;j EPS)
     {
      dem[i].add(pat[npatt].mul(x[i]));
      if((int)Math.ceil((double)DEMAND[i]/x[i]) > dw)
       dw = (int)Math.ceil((double)DEMAND[i]/x[i]);
     }
    pat[npatt].setUB(dw);           /* Change the upper bound on the new var.*/   
    npatt++;

    p.loadMat();                    /* Reload the problem */
    p.loadBasis(basis);             /* Load the saved basis */
    basis=null;                     /* No need to keep the basis any longer */
   }
  }

  p.mipOptimize("");                /* Solve the MIP */
  
  System.out.println("(" + (XPRB.getTime()-starttime)/1000.0 + 
    " sec) Optimal solution: " + p.getObjVal() + " rolls, " + npatt + 
    " patterns");
  System.out.print("   Rolls per pattern: ");
  for(i=0;i