/******************************************************** Xpress-BCL Java Example Problems ================================ file xbburgl.java ````````````````` Burglar problem. Binary variable formulation with index sets. -- Formulating logical conditions with indicator constraints -- (c) 2009 Fair Isaac Corporation author: S.Heipcke, June 2009, rev. Mar. 2011 ********************************************************/ import com.dashoptimization.*; public class xbburgl { /****DATA****/ /* Item: ca ne va pi tv vi ch br */ static final double[] VALUE = {15,100, 90, 60, 40, 15, 10, 1}; /* Value of items */ static final double[] WEIGHT = { 2, 20, 20, 30, 40, 30, 60, 10}; /* Weight of items */ static final double WTMAX = 102; /* Max weight allowed for haul */ static final String[] ITEMNAMES = {"camera", "necklace", "vase", "picture", "tv", "video", "chest", "brick"}; static int NItems; /* Number of items */ public static void main(String[] args) { XPRB bcl; XPRBvar[] x; XPRBindexSet ITEMS; /* Set of items */ int i; XPRBexpr lobj, kn; XPRBctr Log3a,Log3b; XPRBprob p; bcl = new XPRB(); /* Initialize BCL */ p = bcl.newProb("BurglarL"); /* Create a new problem in BCL */ /****INDICES****/ ITEMS=p.newIndexSet("Items",ITEMNAMES.length); /* Create the index set */ for(i=0;i= 2 */ /* Turn the 2 constraints into indicator constraints */ Log3a.setIndicator(1, x[ITEMS.getIndex("vase")]); /* x["vase"]=1 -> x["tv"]+x["video"]=0 */ Log3b.setIndicator(-1, x[ITEMS.getIndex("vase")]); /* x["vase"]=0 -> x["tv"]+x["video"]=2 */ /* Alternative MIP formulation (instead of Log3a and Log3b) */ /* p.newCtr("Log3", x[ITEMS.getIndex("tv")].add(x[ITEMS.getIndex("vase")]).eql(1) ); */ /* x["tv"] = 1 - x["vase"] */ /****SOLVING + OUTPUT****/ p.setSense(XPRB.MAXIM); /* Choose the sense of the optimization */ p.mipOptimize(""); /* Solve the MIP-problem */ System.out.println("Objective: " + p.getObjVal()); /* Get objective value */ for(i=0;i0) System.out.println(ITEMS.getIndexName(i) + ": " + x[i].getSol()); } }