FICO Xpress Optimization Examples Repository
 FICO Optimization Community FICO Xpress Optimization Home

Workshop - Displaying solution information

Description
A small planning problem. The example composes constraints, LP solves the problem and then prints the variables.

Model version 'xbworkrng' shows how to retrieve ranging information for variables and constraints and how to change the number-printing format.

Source Files

xbworkrng.java

```/********************************************************
Xpress-BCL Java Example Problems
================================

file xbworkrng.java
```````````````````
Workshop planning example.
Test ranges and number printing format.

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

import com.dashoptimization.*;

public class xbworkrng
{
static final int NProd = 2;     /* Number of products */
static final int NShop = 3;     /* Number of workshops */
static final int WMAX = 40;     /* Maximum weekly working time */

/****DATA****/
static final int[][] DUR = {{5, 9, 7},
{10, 2, 5}};  /* Duration of product p on shop s */
static final int[] RES   = {10, 8};      /* Man hours per unit */
static final int[] PRICE = {108, 84};    /* Selling price per unit */

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

public static void main(String[] args)
{
int p,s;
XPRB bcl;
XPRBexpr l;
XPRBvar[] x;                   /* Amount of product p */
XPRBprob pb;
XPRBctr[] c;

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

/****VARIABLES****/
x = new XPRBvar[NProd];
for(p=0;p<NProd;p++)  x[p] = pb.newVar("x");

/****OBJECTIVE****/
l = new XPRBexpr();
for(p=0;p<NProd;p++)
pb.setObj(l);                  /* Set obj. function: maximize benefit */

/****CONSTRAINTS****/
c = new XPRBctr[NShop];
for(s=0;s<NShop;s++)           /* Limit on weekly working hours */
{
l = new XPRBexpr();
c[s] = pb.newCtr("ResMax", l.lEql(WMAX) );
}

/****SOLVING + OUTPUT****/
pb.setRealFmt("%4.2e");
for(p=0;p<NProd;p++)
{ x[p].print(); System.out.print(" "); }

pb.setSense(XPRB.MAXIM);
pb.lpOptimize("");             /* Solve the LP-problem */
System.out.println("Objective: " + pb.getObjVal());  /* Get objective value */

pb.setRealFmt("%g, ");
for(p=0;p<NProd;p++)           /* Print the solution values */
x[p].print();
System.out.println();

pb.setRealFmt("%8.4f");
pb.print();
/* Row ranges */
System.out.println("Ctr: Lower activity, Upper activity, Unit cost DN, Unit cost UP");
for(s=0;s<NShop;s++)
System.out.println(c[s].getName() + ": " +
c[s].getRNG(XPRB.LOACT) + ", " +  c[s].getRNG(XPRB.UPACT) + ", " +
c[s].getRNG(XPRB.UDN) + ", " +  c[s].getRNG(XPRB.UUP));

/* Column ranges */
System.out.println("Var: Lower activity, Upper activity, Unit cost DN, Unit cost UP, Lower profit, Upper profit");
for(p=0;p<NProd;p++)
System.out.println(x[p].getName() + ": " +
x[p].getRNG(XPRB.LOACT) + ", " + x[p].getRNG(XPRB.UPACT) + ", " +
x[p].getRNG(XPRB.UDN) + ", " +  x[p].getRNG(XPRB.UUP) + ", " +
x[p].getRNG(XPRB.LCOST) + ", " +  x[p].getRNG(XPRB.UCOST));

}

}

```