FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Delivery - Data input from file; infeasibility analysis

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.[download all files]

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.

Data Files


  Xpress-BCL C++ Example Problems

  file xbdelvr.cxx
  Transportation problem.

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

#include <iostream>
#include <cstdio>
#include "xprb_cpp.h"

using namespace std;
using namespace ::dashoptimization;

#define NSupp 10                  /* Number of suppliers */
#define NCust 7                   /* Number of customers */
#define MaxArcs 100               /* Max. num. of non-zero cost values */

#define VANFILE XPRBDATAPATH "/delivery/ifvan.dat"    /* Van data file */
#define COSTFILE XPRBDATAPATH "/delivery/cost.dat"    /* Cost data file */

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

double COST[NSupp][NCust];        /* Cost per supplier-customer pair */

double IFVAN[NSupp][NCust];       /* Non-zero if route uses vans instead 
                                     of lorries */
double VANCAP=40.0;               /* Capacity on routes that use vans */


void modDelivery(XPRBprob &p)
 XPRBexpr lobj, lc;
 int s,c;
 XPRBvar x[NSupp][NCust];
  for(c=0; c<NCust; c++)
   x[s][c] = p.newVar(XPRBnewname("x_s%d",s));
 for(s=0;s<NSupp;s++)             /* Objective: Minimize total cost */
  for(c=0; c<NCust; c++)
   lobj += COST[s][c]*x[s][c];
 p.setObj(p.newCtr("OBJ", lobj)); /* Set objective function */ 

 for(c=0; c<NCust; c++)           /* Satisfy demand of each customer */
  for(s=0;s<NSupp;s++)  lc += x[s][c];
  p.newCtr("Demand", lc >= DEMAND[c]);
 for(s=0;s<NSupp;s++)             /* Keep within supply at each supplier*/
  for(c=0; c<NCust; c++)  lc+= x[s][c];
  p.newCtr("Supply", lc <= SUPPLY[s]);
  for(c=0; c<NCust; c++)
   if(IFVAN[s][c]!=0) x[s][c].setUB(VANCAP);

/****SOLVING + OUTPUT****/
 p.exportProb(XPRB_MPS,"delivery");   /* Write out an MPS file */

 p.setSense(XPRB_MINIM);           /* Set objective sense to minimization */
 p.lpOptimize("");                 /* Solve the LP-problem */
 cout << "Objective: " << p.getObjVal() << endl;  /* Get objective value */
 for(s=0;s<NSupp;s++)              /* Print out the solution values */
  for(c=0; c<NCust; c++)
   cout << x[s][c].getName() << ":" << x[s][c].getSol() << " ";
 cout << endl;    


    /**** Read data from files ****/
void readData()
 FILE *datafile;
 int s,c;  

/* Initialize data tables to 0: in the van data file some entries that are 
 * zero are simply left out, but the function XPRBreadarrline only initializes 
 * those elements to 0 that have been read, e.g. a data line ",,," results
 * in the first 4 elements of the array to be set to zero, even if the
 * maximum number of elements to be read (=last parameter of XPRBreadarrline)
 * has a much larger value */
  for(c=0; c<NCust; c++)
   COST[s][c] = 0;
   IFVAN[s][c] = 0;
        /* Read the demand data file */
  XPRBreadarrlinecb(XPRB_FGETS, datafile, 99, "g,", COST[s], NCust);

        /* Read the van data file */
  XPRBreadarrlinecb(XPRB_FGETS, datafile, 99,"g,", IFVAN[s], NCust);


int main(int argc, char **argv)
 XPRBprob p("Delivery"); /* Initialize a new problem in BCL */
 readData();             /* Data input from file */
 modDelivery(p);         /* Problem formulation and solution */

 return 0;

Back to examples browserPrevious exampleNext example