/********************************************************
  Xpress-BCL Java Example Problems
  ================================

  file xbcoco1.java
  `````````````````
  Coco Problem Phase 1. 
  Initial formulation: data, variables and constraints fixed.

  (c) 2008 Fair Isaac Corporation
      author: S.Heipcke, Jan. 2000, rev. Mar. 2011
********************************************************/


import com.dashoptimization.*;

public class xbcoco1
{
 public static void main(String[] args)
 {
  XPRB bcl;
  XPRBvar make11,make21,make12,make22;
  XPRBprob p;

  bcl = new XPRB();            /* Initialize BCL */
  p = bcl.newProb("Coco1");    /* Create a new problem in BCL */

/****VARIABLES****/
  make11 = p.newVar("make11"); /* Amount of prod. 1 to make at factory 1 */
  make21 = p.newVar("make21"); /* Amount of prod. 2 to make at factory 1 */
  make12 = p.newVar("make12"); /* Amount of prod. 1 to make at factory 2 */
  make22 = p.newVar("make22"); /* Amount of prod. 2 to make at factory 2 */

/****OBJECTIVE****/
              /* Define & set objective function: maximize total profit */ 
  p.setObj(make11.mul(50).add(make21.mul(125)).add(make12.mul(47))
    .add(make22.mul(132)) );

/****CONSTRAINTS****/
  p.newCtr("MxMake1", make11.add(make21).lEql(400) );
                               /* Capacity limit at factory 1 */

  p.newCtr("MxMake2", make12.add(make22).lEql(500) );
                               /* Capacity limit at factory 2 */

  p.newCtr("MxSell1", make11.add(make12).lEql(650) );
                               /* Limit on the amount of prod. 1 to be sold */

  p.newCtr("MxSell2", make21.add(make22).lEql(600) );
                               /* Limit on the amount of prod. 2 to be sold */

/****SOLVING + OUTPUT****/
  p.setSense(XPRB.MAXIM);      /* Choose the sense of the optimization */
  p.lpOptimize("");            /* Solve the LP-problem */
  System.out.println("Objective: " + p.getObjVal());  /* Get objective value */

               /* Print out the solution values for all variables */
  System.out.println(make11.getName() +": " + make11.getSol());
  System.out.println(make21.getName() +": " + make21.getSol());
  System.out.println(make12.getName() +": " + make12.getSol());
  System.out.println(make22.getName() +": " + make22.getSol()); 
 }
} 
