/******************************************************** Xpress-BCL C# Example Problems ============================== file xbcontr2.cs ```````````````` Contract allocation example. Combining BCL problem input with problem solving and callbacks in Xpress-Optimizer. --- MIP Single-threaded --- (c) 2008 Fair Isaac Corporation authors: S.Heipcke, D.Brett. ********************************************************/ using System; using System.Text; using System.IO; using Optimizer; using BCL; namespace Examples { public class TestUGContr2s { const int District = 6; /* Number of districts */ const int Contract = 10; /* Number of contracts */ /**** DATA ****/ int[] OUTPUT = {50, 40, 10, 20, 70, 50}; /* Max. output per district */ int[] COST = {50, 20, 25, 30, 45, 40}; /* Cost per district */ int[] VOLUME = {20, 10, 30, 15, 20, 30, 10, 50, 10, 20}; /* Volume of contracts */ /*********************************************************************/ public void printsolution(XPRSprob xprsp, object vp) { int num, d, c; XPRBprob bprob; XPRBvar y; bprob = (XPRBprob)vp; bprob.beginCB(xprsp); num = xprsp.MIPSols; bprob.sync(BCLconstant.XPRB_XPRS_SOL); /* Update BCL solution values */ System.Console.WriteLine("Solution " + num + ": Objective value: " + bprob.getObjVal()); for(d=0;d-1) && (y.getSol() != 0)) System.Console.WriteLine(y.getName() + ": " + y.getSol()); } bprob.endCB(); return; } /*********************************************************************/ public static void Main() { XPRB.init(); int d,c; XPRBexpr l1,l2,lobj; XPRBvar[,] x = new XPRBvar[District,Contract]; /* Variables indicating whether a project is chosen */ XPRBvar[,] y = new XPRBvar[District,Contract]; /* Quantities allocated to contractors */ XPRBprob p = new XPRBprob("Contr2"); /* Initialize a new problem in BCL */ TestUGContr2s TestInstance = new TestUGContr2s(); IntsolCallback del = new IntsolCallback(TestInstance.printsolution); XPRSprob xprsp; /**** VARIABLES ****/ for(d=0;d= TestInstance.VOLUME[c]); /* "Size": cover the required volume */ p.newCtr("Min", l2 >= 2 ); /* "Min": at least 2 districts per contract */ } for(d=0;d