Initializing help system before first use

Purchase - Definition of SOS-2


Type: Purchasing with pricebreaks
Rating: 3
Description: A model for optimal purchasing with price-breaks featuring a complex MIP model, data input from file and using SOS-2.
File(s): xbpurch.cs
Data file(s): params.dat, maxperc.dat, required.dat, pricebk.dat


xbpurch.cs
/********************************************************
  Xpress-BCL C# Example Problems
  ==============================

  file xbpurch.cs
  ```````````````
  Purchasing problem using SOS-2.

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

/* WARNING. This model is not for the novice, but it does contain many  *
 * useful ideas.                                                        *
 * The formulation is tricky because the discounts are all-quantity,    *
 * so the graph of cost against quantity purchased is discontinuous.    *
 * To maintain sanity in the special ordered set formulation, we must   *
 * coarsen the discontinuity by stopping purchases just at the break    *
 * point. */

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


namespace Examples
{
    public class TestProduction
    {
    
        //Define XPRBDATAPATH to whatever folder you wish.
        const string XPRBDATAPATH = "../../data";
        string PARAMSFILE = XPRBDATAPATH + "/purchase/params.dat";
        string MAXPERCFILE = XPRBDATAPATH + "/purchase/maxperc.dat";
        string REQFILE = XPRBDATAPATH + "/purchase/required.dat";
        string PRICEFILE = XPRBDATAPATH + "/purchase/pricebk.dat";

        /****TABLES****/
        int NS;             /* Number of suppliers */
        int NB;             /* Number of price breaks */
        int NB2;            /* Useful parameter */

        double[,] UC;        /* Unit cost */
        double[,] BR;        /* Breakpoints (quantities at which unit 
        				                 cost changes) */
        double[,] X;         /* Coarsened break points */
        double[,] C;         /* Total cost at break points */
        double[] DELTA;      /* Coarsening factors */
        double[] MAXPERC;    /* Maximum percentage from each supplier */
        double REQ;          /* Total quantity required */

        double delta = 0.10;        /* Base coarsening factor */

        /* Initialize a new problem in BCL */
        XPRBprob p = new XPRBprob("Purchase");     

        public static void Main()
        {
            System.Console.WriteLine("Started Production Test.\n");
            XPRB.init();

            TestProduction InitClassInstance = new TestProduction();

            /* Data input from file */
            InitClassInstance.readData();            
            
            /* Formulate and solve the problem */
            InitClassInstance.modPurchase();         
             
            return;
        } 
 
        /*********************************************************************/

        public void modPurchase()
        {
         XPRBexpr lobj, lc;
         XPRBexpr[] lr;
         int s,b;
         XPRBvar[] x;
         XPRBvar[,] lam;

        /****VARIABLES****/
         x = new XPRBvar[NS];       /* Quantity to purchase from supplier s */
         for(s=0;s= REQ);

        /****BOUNDS****/
            /* No more than the maximum percentage from each supplier */
         for(s=0;s