Initializing help system before first use

Using the Optimizer with BCL Java

Starting with Release 3.0 of BCL it is possible to combine BCL Java problem definition with direct access to the Optimizer problem in Java. All that is said in the previous sections about BCL-compatible functions remains true. The only noticeable difference is that the Optimizer Java needs to be initialized explicitly (by calling XPRSinit) before the Optimizer problem is accessed.

The following are Java implementations of the code extracts showing the use of BCL-compatible functions:

Setting and accessing parameters (this code throws the exceptions XPRSprobException and XPRSexception):

int rows;
XPRB bcl;
XPRSprob opt_prob;
XPRBprob bcl_prob;

bcl = new XPRB();              /* Initialize BCL */
bcl_prob = bcl.newProb("Example1");  /* Create a new problem in BCL */
XPRS.init();                   /* Initialize Xpress Optimizer */
   ...                         /* Define the problem */
bcl_prob.loadMat();
opt_prob = bcl_prob.getXPRSprob();
opt_prob.setIntControl(XPRS.MAXTIME, 60);
                               /* Set a time limit of 60 seconds */
opt_prob.setDblControl(XPRS.MIPADDCUTOFF, 0.999);
                               /* Set an ADDCUTTOFF value */
rows = opt_prob.getIntAttrib(XPRS.ORIGINALROWS);
                               /* Get number of rows */
bcl_prob.setSense(XPRB.MAXIM); // Select maximization
bcl_prob.lpOptimize();         // Maximize the LP problem

Using Xpress Optimizer callbacks (multi-threaded MIP):

static class IntSolCallback implements XPRSintSolListener
{
  public void XPRSintSolEvent(XPRSprob opt_prob, Object my_object)
  {
    XPRBprob bcl_prob
    XPRBvar x;
    int num;

    bcl_prob = (XPRBprob)my_object;
    try {
      bcl_prob.beginCB(opt_prob);
                               /* Use local Optimizer problem in BCL */
      num = opt_prob.getIntAttrib(XPRS.MIPSOLS);
                               /* Get number of the solution */
      bcl_prob.sync(XPRB.XPRS_SOL);
                               /* Update BCL solution values */
      System.out.println("Solution " + num + ": Objective value: " +
                         bcl_prob.getObjVal());
      x = bcl_prob.getVarByName("x_1");
      if(x.getColNum()>-1)     /* Test whether variable is in the
                                  matrix */
        System.out.println(x.getName() + ": " + x.getSol());
      bcl_prob.endCB();        /* Reset BCL to main problem */
    }
    catch(XPRSprobException e) {
      System.out.println("Error " + e.getCode() + ": " + e.getMessage());
    }
  }
}

public static void main(String[] args) throws XPRSexception
{
  XPRB bcl;
  XPRBprob bcl_prob;
  XPRSprob opt_prob;
  IntSolCallback cb;
  XPRBvar x;

  bcl = new XPRB();                    /* Initialize BCL */
  bcl_prob = bcl.newProb("Example1");  /* Create a new problem in BCL */
  XPRS.init();                         /* Initialize Xpress Optimizer */

  x = bcl_prob.newVar("x_1", XPRB_BV); /* Define a variable */
     ...                       /* Define the rest of the problem */
  opt_prob = bcl_prob.getXPRSprob();
  cb = new IntSolCallback();
  opt_prob.addIntSolListener(cb, bcl_prob);
                               /* Define an integer solution callback */
  bcl_prob.setSense(XPRB.MAXIM);      /* Select maximization */
  bcl_prob.mipOptimize();             /* Maximize the MIP problem */
}

The code extract below shows how to access MIP solution information directly through the Optimizer library functions using the column or row indices saved for BCL modeling objects. In this case there is no need for synchronization of BCL with the local solution information.

static class IntSolCallback implements XPRSintSolListener
{
  public void XPRSintSolEvent(XPRSprob opt_prob, Object my_object)
  {
    XPRBprob bcl_prob
    XPRBvar x;
    int num;
    double [] sol;

    bcl_prob = (XPRBprob)my_object;
    try {
      ncol = opt_prob.getIntAttrib(XPRS.ORIGINALCOLS);
                               /* Get the number of columns */
      sol = new double[ncol];
      opt_prob.getSol(sol, null, null, null);   /* Get the solution */
      num = opt_prob.getIntAttrib(XPRS.MIPSOLS);
                               /* Get number of the solution */
      System.out.println("Solution " + num + ": Objective value: " +
                         opt_prob.getDblAttrib(XPRS.LPOBJVAL));
      x = bcl_prob.getVarByName("x_1");
      if(x.getColNum()>-1)     /* Test whether variable is in the
                                  matrix */
        System.out.println(x.getName() + ": " + sol[x.getColNum()]);
      sol = null;
    }
    catch(XPRSprobException e) {
      System.out.println("Error " + e.getCode() + ": " + e.getMessage());
    }
  }
}

© 2001-2019 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.