/******************************************************** Xpress-BCL Java Example Problems ================================ file xbcontr2.java `````````````````` Contract allocation example. Combining BCL problem input with problem solving and callbacks in Xpress-Optimizer. (c) 2008 Fair Isaac Corporation author: S.Heipcke, 2005, rev. Dec. 2011 ********************************************************/ import java.io.*; import com.dashoptimization.*; public class xbcontr2 { static final int District = 6; /* Number of districts */ static final int Contract = 10; /* Number of contracts */ /**** DATA ****/ static final int[] OUTPUT = {50, 40, 10, 20, 70, 50}; /* Max. output per district */ static final int[] COST = {50, 20, 25, 30, 45, 40}; /* Cost per district */ static final int[] VOLUME = {20, 10, 30, 15, 20, 30, 10, 50, 10, 20}; /* Volume of contracts */ /***********************************************************************/ static class IntSolCallback implements XPRSintSolListener { public void XPRSintSolEvent(XPRSprob oprob, Object data) { int num, d, c; XPRBprob bprob; XPRBvar y; try { bprob = (XPRBprob)data; bprob.beginCB(oprob); num = oprob.getIntAttrib(XPRS.MIPSOLS); /* Get number of the solution */ bprob.sync(XPRB.XPRS_SOL); /* Update BCL solution values */ System.out.println("Solution " + num + ": Objective value: " + bprob.getObjVal()); for(d=0;d-1) && (y.getSol() != 0)) System.out.println(y.getName() + ": " + y.getSol()); } bprob.endCB(); } catch(XPRSprobException e) { System.out.println("Error " + e.getCode() + ": " + e.getMessage()); } } } /***********************************************************************/ public static void main(String[] args) throws XPRSexception { int d, c, i, stat, ncol, len; double [] sol; double val; java.lang.String [] names; XPRSprob op; IntSolCallback cb; XPRBexpr l1,l2,lobj; XPRBvar[][] x; /* Variables indicating whether a project is chosen */ XPRBvar[][] y; /* Quantities allocated to contractors */ try (XPRBprob p = new XPRBprob("Contract2"); /* Initialize BCL and create a new problem BCL */ XPRS xprs = new XPRS()) { /* Initialize Xpress-Optimizer */ /**** VARIABLES ****/ x = new XPRBvar[District][Contract]; y = new XPRBvar[District][Contract]; for(d=0;d