/********************************************************
Xpress-BCL Java Example Problems
================================
file xbels.java
```````````````
Economic lot sizing, ELS, problem, solved by adding
(l,S)-inequalities) in several rounds looping over
the root node.
ELS considers production planning over a horizon
of T periods. In period t, t=1,...,T, there is a
given demand DEMAND[t] that must be satisfied by
production prod[t] in period t and by inventory
carried over from previous periods. There is a
set-up up cost SETUPCOST[t] associated with
production in period t. The unit production cost
in period t is PRODCOST[t]. There is no inventory
or stock-holding cost.
(c) 2008 Fair Isaac Corporation
author: S.Heipcke, 2001, rev. Mar. 2011
********************************************************/
import com.dashoptimization.*;
public class xbels
{
static final double EPS = 1e-6;
static final int T = 6; /* Number of time periods */
/****DATA****/
static final int[] DEMAND = { 1, 3, 5, 3, 4, 2}; /* Demand per period */
static final int[] SETUPCOST = {17,16,11, 6, 9, 6}; /* Setup cost / period */
static final int[] PRODCOST = { 5, 3, 2, 1, 3, 1}; /* Prod. cost / period */
static int[][] D; /* Total demand in periods t1 - t2 */
static XPRBvar[] prod; /* Production in period t */
static XPRBvar[] setup; /* Setup in period t */
static XPRB bcl;
static XPRBprob p;
/***********************************************************************/
static void modEls() throws XPRSexception
{
int s,t,k;
XPRBexpr cobj,le;
bcl = new XPRB(); /* Initialize BCL */
p = bcl.newProb("Els"); /* Create a new problem in BCL */
XPRS.init(); /* Initialize Xpress-Optimizer */
D = new int[T][T];
for(s=0;s= D[0][l]
*/
if(ds < D[0][l] - EPS)
{
le = new XPRBexpr();
for(t=0;t<=l;t++)
{
if (solprod[t] < D[t][l]*solsetup[t] + EPS)
le .add(prod[t]);
else
le .add(setup[t].mul(D[t][l]));
}
p.newCtr("cut" +(ncut+1), le.gEql(D[0][l]) );
ncut++;
npcut++;
}
}
System.out.println("Pass " +npass + " (" +(XPRB.getTime()-starttime)/1000.0
+ " sec), objective value " + objval + ", cuts added: " + npcut
+ " (total " + ncut +")");
if(npcut==0)
System.out.println("Optimal integer solution found:");
else
{
p.loadMat(); /* Reload the problem */
p.loadBasis(basis); /* Load the saved basis */
basis = null; /* No need to keep the basis any longer */
}
} while(npcut>0);
/* Print out the solution: */
for(t=0;t |
/********************************************************
Xpress-BCL Java Example Problems
================================
file xbelsc.java
````````````````
Economic lot sizing, ELS, problem, solved by adding
(l,S)-inequalities) in a branch-and-cut heuristic
(using the cut manager).
ELS considers production planning over a horizon
of T periods. In period t, t=1,...,T, there is a
given demand DEMAND[t] that must be satisfied by
production prod[t] in period t and by inventory
carried over from previous periods. There is a
set-up up cost SETUPCOST[t] associated with
production in period t. The unit production cost
in period t is PRODCOST[t]. There is no inventory
or stock-holding cost.
(c) 2008 Fair Isaac Corporation
author: S.Heipcke, 2005, rev. Mar. 2011
********************************************************/
import java.util.*;
import com.dashoptimization.*;
public class xbelsc
{
static final double EPS = 1e-6;
static final int T = 6; /* Number of time periods */
/****DATA****/
static final int[] DEMAND = { 1, 3, 5, 3, 4, 2}; /* Demand per period */
static final int[] SETUPCOST = {17,16,11, 6, 9, 6}; /* Setup cost / period */
static final int[] PRODCOST = { 5, 3, 2, 1, 3, 1}; /* Prod. cost / period */
static int[][] D; /* Total demand in periods t1 - t2 */
static XPRBvar[] prod; /* Production in period t */
static XPRBvar[] setup; /* Setup in period t */
static XPRB bcl;
static XPRBprob p;
static class myobj {
XPRBprob prob;
double tol;
};
/**************************************************************************/
/* Cut generation algorithm: */
/* get the solution values */
/* identify and set up violated constraints */
/* add cuts to the problem */
/**************************************************************************/
static class CutMgrCallback implements XPRScutMgrListener
{
public int XPRScutMgrEvent(XPRSprob oprob, Object data)
{
int t,l;
boolean res;
int ncut; /* Counter for cuts */
double[] solprod, solsetup; /* Solution values for var.s prod & setup */
double ds;
XPRBexpr le;
ArrayList cutlist;
XPRBcut[] cuts;
myobj mo;
mo = (myobj)data;
ncut = 0;
cutlist = new ArrayList();
try {
/* Get the solution values */
mo.prob.beginCB(oprob);
mo.prob.sync(XPRB.XPRS_SOL);
solprod = new double[T];
solsetup = new double[T];
for(t=0;t= D[0][l]
*/
if(ds < D[0][l] - mo.tol)
{
le = new XPRBexpr();
for(t=0;t<=l;t++)
{
if (solprod[t] < D[t][l]*solsetup[t] + mo.tol)
le .add(prod[t]);
else
le .add(setup[t].mul(D[t][l]));
}
cutlist.add( mo.prob.newCut(le.gEql(D[0][l])) );
ncut++;
}
}
/* Add cuts to the problem */
if(ncut>0)
{
cuts = new XPRBcut[ncut];
for(t=0;t |