FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserNext example

Chess - Composing constraints and solving

Description
A tiny LP problem concerning the manufacture of chess boards. The example composes constraints term by term and then solves the problem.

xbchessjava.zip[download all files]

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





xbchess.java

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

  file xbchess.java
  `````````````````
  Small LP-problem.

  (c) 2008-2024 Fair Isaac Corporation
      author: S.Heipcke, Jan. 2000, rev. Mar. 2011
********************************************************/

import com.dashoptimization.*;

public class xbchess {
    public static void main(String[] args) {
        XPRBvar xs;                /* Number of small chess sets to make */
        XPRBvar xl;                /* Number of large chess sets to make */

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

            /****VARIABLES****/
            xs = p.newVar("xs");
            xl = p.newVar("xl");

            /****OBJECTIVE****/
            p.setObj(xs.mul(5).add(xl.mul(20)));
            /* Define & set the obj. function 5*xs + 20*xl */

            /****CONSTRAINTS****/
            /* Define the constraint 3*xs + 2*xl <= 400 */
            p.newCtr("mc_time", xs.mul(3).add(xl.mul(2)).lEql(400) );

            /* Define the constraint xs + 3*xl <= 200 */
            p.newCtr("wood", xs.add(xl.mul(3)).lEql(200) );

            /****SOLVING****/
            p.setSense(XPRB.MAXIM);
            p.lpOptimize("");          /* Solve the LP-problem */
        }
    }
}

Back to examples browserNext example