/********************************************************
  Xpress-BCL Java Example Problems
  ================================

  file xbworks.java
  `````````````````
  Workshop planning example.

  (c) 2008 Fair Isaac Corporation
      author: S.Heipcke, Jan. 2000, rev. Mar. 2011
********************************************************/

import com.dashoptimization.*;

public class xbworks
{
 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;
  
  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++)
   l.add(x[p].mul(PRICE[p]-5*RES[p]));
  pb.setObj(l);                  /* Set obj. function: maximize benefit */ 
 
/****CONSTRAINTS****/
  for(s=0;s<NShop;s++)           /* Limit on weekly working hours */
  {
   l = new XPRBexpr();
   for(p=0;p<NProd;p++)  l.add(x[p].mul(DUR[p][s]));
   pb.newCtr("ResMax", l.lEql(WMAX) );
  }
  
/****SOLVING + OUTPUT****/  
  pb.setSense(XPRB.MAXIM);
  pb.lpOptimize("");             /* Solve the LP-problem */
  System.out.println("Objective: " + pb.getObjVal());  /* Get objective value */
  for(p=0;p<NProd;p++)           /* Print the solution values */
   System.out.print(x[p].getName() + ":" + x[p].getSol() + " ");
  System.out.println();
 }
 
} 
