Initializing help system before first use

Workshop - Displaying solution information


Type: Production planning
Rating: 1 (simple)
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.
File(s): xbworks.java, xbworkrng.java


xbworks.java
/********************************************************
  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;
        XPRBexpr l;
        XPRBvar[] x;                   /* Amount of product p */

        try (XPRBprob pb = new XPRBprob("Workshop")) { /* Initialize BCL and create a new problem */

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

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;
        XPRBexpr l;
        XPRBvar[] x;                   /* Amount of product p */
        XPRBctr[] c;

        try (XPRBprob pb = new XPRBprob("Workshop")) { /* Initialize BCL and create a new problem */

            /****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****/
            c = new XPRBctr[NShop];
            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]));
                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));

        }
    }
}

© 2001-2023 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.