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

Coco - A full production planning example

Description
The Coco productional planning problem: multi-item, multi-period, multi-site production planning. A sequence of model versions show how the model was developed, to (a) use more sophisticated modeling features and (b) to extend the model, taking it from a simple linear model to one with fixed prices and logical decisions.
  1. xbcoco1: initial formulation, data, variables and constraints fixed
  2. xbcoco2: use parameters, data tables and subscripted variables.

    read data tables in from text data files (short-term planning).
  3. xbcoco3: like xbcoco2.c, but several time periods (mid-term planning).
  4. xbcoco : complete problem, data defined in the model definition (long-term planning).

xbcocojava.zip[download all files]

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
xbcoco1.java[download]
xbcoco2.java[download]
xbcoco3.java[download]
xbcoco.java[download]

Data Files





xbcoco1.java

/********************************************************
 * Xpress-BCL Java Example Problems
 * ================================
 *
 * file xbcoco1.java
 * `````````````````
 * Coco Problem Phase 1.
 * Initial formulation: data, variables and constraints fixed.
 *
 * (c) 2008-2024 Fair Isaac Corporation
 * author: S.Heipcke, Jan. 2000, rev. Mar. 2011
 ********************************************************/

import com.dashoptimization.*;

public class xbcoco1 {
  public static void main(String[] args) {
    try (XPRBprob p = new XPRBprob("Coco1"); /* Initialize BCL and create a new problem */
        XPRBexprContext context =
            new XPRBexprContext() /* Release XPRBexpr instances at end of block. */) {
      XPRBvar make11, make21, make12, make22;

      /****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());
    }
  }
}

Back to examples browserPrevious exampleNext example