FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

UG - Examples from 'BCL Reference Manual'

Description
The following examples are discussed in detail in the 'BCL User Guide and Reference Manual':
  • modeling and solving a small MIP scheduling problem (xbexpl1 version BASIC)
  • using variable arrays and constraint templates (xbexpl1 versions ARRAY and ARRAYC)
  • definition of SOS-1 (xbexpl1 version SOS)
  • data input from file, index sets (xbexpl1i)
  • user error handling, output redirection (xbexpl3)
  • solving multiple scenarios of a transportation problem in parallel (xbexpl2: standard, single thread version)
  • cut generation / adding cuts at MIP tree nodes (xbcutex)
  • quadratic programming (quadratic objective: xbqpr12, quadratic constraints: xbairport)
  • combine BCL problem input with problem solving in Xpress Optimizer (xbcontr1)
  • use an Xpress Optimizer solution callback with a BCL model (xbcontr2s: single MIP thread; xbcontr2: multiple MIP threads)
Further explanation of this example: 'BCL Reference Manual', Appendix B Using BCL with the Optimizer library


Source Files

Data Files





xbqpr12.cs

/********************************************************
  Xpress-BCL C# Example Problems
  ==============================

  file xbqpr12.cs
  ```````````````
  Small Quadratic Programming example from
  Release 12 Supplement.
       minimize x1 + x1^2 +2x1x2 +2x2^2 +x4^2
       s.t. C1:  x1 +2x2 -4x4 >= 0
            C2: 3x1 -2x3 - x4 <= 100
            C3: 10 <= x1 +3x2 +3x3 -2x4 <= 30
            0<=x1<=20
            0<=x2,x3
            x4 free

  (c) 2008-2024 Fair Isaac Corporation
      authors: S.Heipcke, D.Brett.
********************************************************/

using System;
using System.Text;
using System.IO;
using BCL;


namespace Examples
{

    public class TestUGQpr12
    {

        const int NXPRBvar = 4;

        /***********************************************************************/

        public static void Main()
        {
            XPRB.init();
            XPRBctr c;
            XPRBexpr qobj;
            XPRBvar[] x = new XPRBvar[NXPRBvar];
            int i;
            XPRBprob p = new XPRBprob("QPr12");     	/* Initialize a new problem in BCL */

            /**** VARIABLES ****/
            x[0] = p.newVar("x1", BCLconstant.XPRB_PL, 0, 20);
            x[1] = p.newVar("x2");
            x[2] = p.newVar("x3");
            x[3] = p.newVar("x4", BCLconstant.XPRB_PL, -BCLconstant.XPRB_INFINITY, BCLconstant.XPRB_INFINITY);

            /****OBJECTIVE****/
            /* Define the objective function */
            qobj = new XPRBexpr(x[0]) + x[0].sqr()  + 2*(x[0]*x[1])  + 2*x[1].sqr()  + x[3].sqr();
            p.setObj(qobj);

            /**** CONSTRAINTS ****/
            p.newCtr("C1", x[0] + 2*x[1] - 4*x[3] >= 0);
            p.newCtr("C2", 3*x[0] - 2*x[2] -x[3] <= 100);
            c = p.newCtr("C3", x[0] + 3*x[1] + 3*x[2] - 2*x[3] );
            c.setRange(10,30);

            /****SOLVING + OUTPUT****/
            p.print();			  /* Print out the problem definition */
            p.exportProb(BCLconstant.XPRB_MPS, "QPr12");  /* Output the matrix in MPS format */
            p.exportProb(BCLconstant.XPRB_LP, "QPr12");   /* Output the matrix in LP format */

            p.setSense(BCLconstant.XPRB_MINIM);      	  /* Choose the sense of the optimization */
            p.lpOptimize();          		  /* Solve the QP-problem */

            System.Console.WriteLine("Objective function value: " + p.getObjVal());
            for(i=0;i<NXPRBvar;i++)
                System.Console.Write(x[i].getName() + ": " + x[i].getSol() + ", ");
            System.Console.WriteLine();

            return;
        }

    }

}
Back to examples browserPrevious exampleNext example