Initializing help system before first use

Delivery - Data input from file; infeasibility analysis


Type: Network flow
Rating: 2
Description: A simple supply and demand network example showing data input from file and the use of "views": incremental definition of arrays of variables. Also uses constraint templates with the arrays of variables.
A second version of this model (file xbdlvriis) has modified data making the problem infeasible. This example shows how to analyze infeasibility with the help of IIS (irreducible infeasible sets), it retrieves the IIS and prints out their contents.
It is possible to retrieve more detailed information on the IIS, such as isolation rows or bounds, using Xpress Optimizer functions (file xbdlvriis2iso) or to use the infeasibility repair functionality of the Optimizer (file xbdlvriis2rep) with models defined in BCL.
File(s): xbdelvr.java, xbdlvriis.java, xbdlvriis2iso.java, xbdlvriis2rep.java
Data file(s): ifvan.dat, cost.dat


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

  file xbdelvr.java
  `````````````````
  Transportation problem.

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

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

public class xbdelvr
{
 static final int NSupp = 10;     /* Number of suppliers */
 static final int NCust = 7;      /* Number of customers */
 static final int MaxArcs = 100;  /* Max. num. of non-zero cost values */

 static final String VANFILE = System.getProperty("XPRBDATA") + 
   "/delivery/ifvan.dat";
 static final String COSTFILE = System.getProperty("XPRBDATA") + 
   "/delivery/cost.dat";

/****DATA****/
/* Supplier:                    London  Luton  B'ham Bristl  Derby Stckpt */
 static final double SUPPLY[] = {140.0, 600.0,  50.0,  10.0, 400.0, 200.0,  
/* Supplier: York  Derby Soton Scnthp */
             20.0, 90.0,  30.0,  12.0};
/* Customer:                    London Livpol Doncst   York   Hull Manchr */
 static final double DEMAND[] = {123.3,  56.4,  17.1, 192.8, 310.0,  47.0, 
/* Customer:  Shffld */    
              86.0};

 static double[][] COST;          /* Cost per supplier-customer pair */
 static double[][] IFVAN;         /* Non-zero if route uses vans instead 
                                     of lorries */
 static final double VANCAP=40.0; /* Capacity on routes that use vans */

 static XPRB bcl;
 static XPRBprob p;

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

 static void modDelivery() throws IOException
 {
  XPRBexpr lobj, lc;
  int s,c;
  XPRBvar[][] x;
 
  bcl = new XPRB();               /* Initialize BCL */
  p = bcl.newProb("Delivery");    /* Create a new problem in BCL */

/****VARIABLES****/
  x = new XPRBvar[NSupp][NCust];
  for(s=0;s

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

  file xbdlvriis.java
  ```````````````````
  Transportation problem (infeasible data).
  Retrieving and printing IIS.

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

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

public class xbdlvriis
{
 static final int NSupp = 10;     /* Number of suppliers */
 static final int NCust = 7;      /* Number of customers */
 static final int MaxArcs = 100;  /* Max. num. of non-zero cost values */

 static final String VANFILE = System.getProperty("XPRBDATA") + 
   "/delivery/ifvan.dat";
 static final String COSTFILE = System.getProperty("XPRBDATA") + 
   "/delivery/cost.dat";

/****DATA****/
/* Supplier:                    London  Luton  B'ham Bristl  Derby Stckpt */
 static final double SUPPLY[] = {140.0, 200.0,  50.0,  10.0, 400.0, 200.0,  
/* Supplier:                     York  Derby Soton Scnthp */
                                 20.0, 90.0,  30.0,  12.0};
/* Customer:                     London Livpol Doncst   York   Hull  Manchr */
 static final double DEMAND[] = {1230.3, 560.4, 117.1, 592.8, 310.0, 1247.0, 
/* Customer:                     Shffld */    
                                 86.0};

 static double[][] COST;          /* Cost per supplier-customer pair */
 static double[][] IFVAN;         /* Non-zero if route uses vans instead 
                                     of lorries */
 static final double VANCAP=40.0; /* Capacity on routes that use vans */

 static XPRB bcl;
 static XPRBprob p;

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

 static void modDelivery()
 {
  XPRBexpr lobj, lc;
  int s,c,i;
  XPRBvar[][] x;
  ArrayList iisctr,iisvar;
  int numv, numc, numiis, ct;
 
  bcl = new XPRB();               /* Initialize BCL */
  p = bcl.newProb("Delivery");    /* Create a new problem in BCL */

/****VARIABLES****/
  x = new XPRBvar[NSupp][NCust];
  for(s=0;s0)
    {                              /* Print all variables in the IIS */
     System.out.print("        Variables: ");
     for(i=0;i0)
    {                              /* Print all constraints in the IIS */
     System.out.print("        Constraints: ");
     for(i=0;i0)
  {
   if(ct>0)
    System.out.println("IIS " + ct + ":  " + numv + " variables, " + numc + " constraints");
   ct++;  
   p.getIIS(iisvar, iisctr, ct);
   numv = iisvar.size(); numc = iisctr.size();
  }
   
/* Retrieve variables only */
   System.out.println("Variables");
   for(s=1;s<=numiis;s++)
   { 
    p.getIIS(iisvar, null, s);
    numv = iisvar.size(); 
    System.out.print("  IIS " + s + ":  " + numv + " variables  ( " );
    for(i=0;i

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

  file xbdlvriis2iso.java
  ```````````````````````
  Transportation problem (infeasible data).
  Retrieving and printing IIS.
  - Using Optimizer functions to retrieve detailed
    IIS information including isolation rows/bounds -

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

import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
import com.dashoptimization.*;

public class xbdlvriis2iso
{
 static final int NSupp = 10;     /* Number of suppliers */
 static final int NCust = 7;      /* Number of customers */
 static final int MaxArcs = 100;  /* Max. num. of non-zero cost values */

 static final String VANFILE = System.getProperty("XPRBDATA") + 
   "/delivery/ifvan.dat";
 static final String COSTFILE = System.getProperty("XPRBDATA") + 
   "/delivery/cost.dat";

/****DATA****/
/* Supplier:                    London  Luton  B'ham Bristl  Derby Stckpt */
 static final double SUPPLY[] = {140.0, 200.0,  50.0,  10.0, 400.0, 200.0,  
/* Supplier:                     York  Derby Soton Scnthp */
                                 20.0, 90.0,  30.0,  12.0};
/* Customer:                     London Livpol Doncst   York   Hull  Manchr */
 static final double DEMAND[] = {1230.3, 560.4, 117.1, 592.8, 310.0, 1247.0, 
/* Customer:                     Shffld */    
                                 86.0};

 static double[][] COST;          /* Cost per supplier-customer pair */
 static double[][] IFVAN;         /* Non-zero if route uses vans instead 
                                     of lorries */
 static final double VANCAP=40.0; /* Capacity on routes that use vans */

 static XPRB bcl;
 static XPRBprob p;
 static XPRSprob op;

 private static DecimalFormat form = new DecimalFormat ("####.0");

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

 static void modDelivery()
 {
  XPRBexpr lobj, lc;
  int s,c,i;
  XPRBvar[][] x;
  XPRBctr[] CSupply, CDemand;
  int numv, numc, numiis, ncol, nrow;
  IntHolder inumv, inumc, inumiis;
  int[] viis, ciis;
  double[] duals, rdcs, bnd, rhs;
  byte[] ctrtype, bndtype, isolationrows, isolationbnds;
  java.lang.String[] cnames, vnames;
  java.lang.String isotype[] = {"N/A", "No ", "Yes"};
 
  bcl = new XPRB();               /* Initialize BCL */
  p = bcl.newProb("Delivery");    /* Create a new problem in BCL */
  XPRS.init();                    /* Initialize Xpress-Optimizer */

/****VARIABLES****/
  x = new XPRBvar[NSupp][NCust];
  for(s=0;s0)
    {                              /* Print all variables in the IIS */
     bnd = new double[1];
     for(i=0;i0)
    {                              /* Print all constraints in the IIS */
     rhs = new double[1];
     for(i=0;i

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

  file xbdlvriis2rep.java
  ```````````````````````
  Transportation problem (infeasible data).
  Repairing infeasibility.
  - Using Optimizer functions -

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

import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
import com.dashoptimization.*;

public class xbdlvriis2rep
{
 static final int NSupp = 10;     /* Number of suppliers */
 static final int NCust = 7;      /* Number of customers */
 static final int MaxArcs = 100;  /* Max. num. of non-zero cost values */

 static final String VANFILE = System.getProperty("XPRBDATA") + 
   "/delivery/ifvan.dat";
 static final String COSTFILE = System.getProperty("XPRBDATA") + 
   "/delivery/cost.dat";

/****DATA****/
/* Supplier:                    London  Luton  B'ham Bristl  Derby Stckpt */
 static final double SUPPLY[] = {140.0, 200.0,  50.0,  10.0, 400.0, 200.0,  
/* Supplier:                     York  Derby Soton Scnthp */
                                 20.0, 90.0,  30.0,  12.0};
/* Customer:                     London Livpol Doncst   York   Hull  Manchr */
 static final double DEMAND[] = {1230.3, 560.4, 117.1, 592.8, 310.0, 1247.0, 
/* Customer:                     Shffld */    
                                 86.0};

 static double[][] COST;          /* Cost per supplier-customer pair */
 static double[][] IFVAN;         /* Non-zero if route uses vans instead 
                                     of lorries */
 static final double VANCAP=40.0; /* Capacity on routes that use vans */

 static XPRB bcl;
 static XPRBprob p;
 static XPRSprob op;

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

 static void modDelivery()
 {
  XPRBexpr lobj, lc;
  int s,c,i;
  XPRBvar[][] x;
  XPRBctr[] CSupply, CDemand;
  int nrow, ncol;
  IntHolder iscode;
  double[] lrp, grp, lbp, ubp;
 
  bcl = new XPRB();               /* Initialize BCL */
  p = bcl.newProb("Delivery");    /* Create a new problem in BCL */
  XPRS.init();                    /* Initialize Xpress-Optimizer */

/****VARIABLES****/
  x = new XPRBvar[NSupp][NCust];
  for(s=0;s= rows)
   ax + aux_var  = b 
   ax + aux_var >= b
lbp:
   x_i + aux_var >= l
ubp:
   x_i - aux_var <= u 
*/

/**** Simplified infeasibility repair:
      specifying preferences per constraint/bound type ****/

   System.out.println("\n**** Repair infeasibility:");
   iscode = new IntHolder();
   op.repairInfeas(iscode, 'c', 'o', ' ', 10, 9, 0, 20, 0.001);
   printSolution(p, iscode.value, x); 

/**** Weighted infeasibility repair:
      specifying preferences for every constraint/bound separately ****/

   ncol=op.getIntAttrib(XPRS.ORIGINALCOLS);    
   nrow=op.getIntAttrib(XPRS.ORIGINALROWS);    
   lrp = new double[nrow]; 
   grp = new double[nrow]; 
   lbp = new double[ncol]; 
   ubp = new double[ncol]; 

/* Relax bounds due to van capacity */
/* Repairweightedinfeas for upper bounds of concerned flow variables */

   for(s=0; s0.01)
      System.out.print(x[s][c].getName()+ ":" + x[s][c].getSol() + " ");
   System.out.println();    
   System.out.println("Violations:");
   for(c=0; cSUPPLY[s])
     System.out.println("  Supplier " + s + ": " +  (dem-SUPPLY[s]) );
   }
   for(s=0; s=0 && sol[x[s][c].getColNum()]>0.01)
      System.out.print(x[s][c].getName()+ ":" + sol[x[s][c].getColNum()] + " ");
   System.out.println();    
   System.out.println("Violations:");
   for(c=0; c=0) sup+=sol[x[s][c].getColNum()];
    if(sup=0) dem+=sol[x[s][c].getColNum()];
    if(dem>SUPPLY[s])
     System.out.println("  Supplier " + s + ": " +  (dem-SUPPLY[s]) );
   }
   for(s=0; s=0 &&
        VANCAP