Initializing help system before first use

10 best solutions with the MIP solution enumerator


Type: Power generation
Rating: 3 (intermediate)
Description: We take the power generation problem stored in hpw15.mat which seeks to optimise the operating pattern of a group of electricity generators. We run the MIP solution enumerator on the problem using the default setup obtaining the best 10 solutions. The best 10 solutions are stored to a MIP solution pool. The solutions' objectives and solution values are printed to screen.
File(s): MipSolEnum.cs
Data file(s): hpw15.mat


MipSolEnum.cs
/***************************************************************************************\
* Name:        MipSolEnum.cs                                     Fair Isaac 13/06/2008 *
* Purpose:     10 best solutions with the MIP solution enumerator                      *
* Description: We take the power generation problem stored in hpw15.mat which seeks to *
*              optimise the operating pattern of a group of electricity generators. We *
*              run the MIP solution enumerator on the problem using the default setup  *
*              obtaining the best 10 solutions. The best 10 solutions are stored to a  *
*              MIP solution pool.  The solutions' objectives and solution values are   *
*              printed to screen.                                                      *
* Input:       hpw15.mat                                                               *
\***************************************************************************************/

using System;
using System.IO;
using Optimizer;

namespace XPRSExamples
{
    class MipSolEnum
    {
        static void Main(string[] args)
        {
            XPRS.Init();

            XPRSprob prob = new XPRSprob();
            prob.AddMsgHandlerCallback(Console.Out);

            XPRSmipsolpool msp = new XPRSmipsolpool();
            XPRSmipsolenum mse = new XPRSmipsolenum();

            prob.MPSFormat = -1;
            prob.ReadProb(@"..\..\..\data\hpw15");
            int nCols = prob.Cols;

            /* Disable heuristics to avoid duplicate solutions being stored */
            prob.HeurStrategy = 0; ;

            int iPresolveOps = prob.PresolveOps;
            iPresolveOps &= ~(1 << 3); /* Disable dual reduction operations */
            iPresolveOps &= ~(1 << 5); /* Disable duplicate column removal  */
            prob.PresolveOps = iPresolveOps;

            int iMIPPresolve = prob.MIPPresolve;
            iMIPPresolve &= ~(1 << 4); /* Disable MIP dual reduction operations */
            prob.MIPPresolve = iMIPPresolve;

            /* Run the enumeration */
            int nMaxSols = 10;
            mse.Minim(prob, msp, XPRSdefaultMipSolEnumHandler.GetDefaultHandlerCallback(), null, ref nMaxSols);

            /* Print out the solutions found */
            int nSols = mse.Solutions;
            for (int i = 1; i <= nSols; i++)
            {
                int[] iSolutionId = new int[1];
                double dObj;
                int nSols2, nReturnedSolIds, solutionIdStatus;
                mse.GetSolList((int)XPRSattribute.Mse_Metric_MipObject, i, i, iSolutionId, out nReturnedSolIds, out nSols2);
                mse.GetSolMetric(iSolutionId[0], out solutionIdStatus, (int)XPRSattribute.Mse_Metric_MipObject, out dObj);
                Console.WriteLine("--------\n" + i + " = " + dObj);
                for (int j = 0; j < nCols; j++)
                {
                    double[] dSol = new double[1];
                    int nValuesReturned;
                    msp.GetSol(iSolutionId[0], out solutionIdStatus, dSol, j, j, out nValuesReturned);
                    Console.WriteLine(j + " = " + dSol[0]);
                }
            }

            XPRS.Free();
        }
    }
}