Initializing help system before first use

Irreducible Infeasible Set Search


Type: Programming
Rating: 4 (medium-difficult)
Description:

Anlaysing an infeasible problem by identifying an irreducible infeasible subset (IIS)

File(s): IISExample.java
Data file(s): iisexample.mps


IISExample.java
import com.dashoptimization.*;

class IISExample implements XPRSmessageListener
{
    public void Run_getIISData(XPRSprob problem, int i)
    {
      IntHolder ncol = new IntHolder(), nrow = new IntHolder();
      problem.getIISData(i, nrow, ncol, null, null, null, null, null, null, null, null);
      int[]     miisrow         = new int[nrow.value];
      int[]     miiscol         = new int[ncol.value];
      byte[]    constrainttype  = new byte[nrow.value];
      byte[]    colbndtype      = new byte[ncol.value];
      double[]  duals           = new double[nrow.value];
      double[]  rdcs            = new double[ncol.value];
      byte[]    isolationrows   = new byte[nrow.value];
      byte[]    isolationcols   = new byte[ncol.value];
      problem.getIISData(i, nrow, ncol, miisrow, miiscol, constrainttype, colbndtype, duals, rdcs, isolationrows, isolationcols);
    }

    public void Run_IISStatus(XPRSprob problem, int i)
    {
      IntHolder count = new IntHolder();
      problem.IISStatus(count, null, null, null, null);
      int[]     rowsizes        = new int[count.value + 1];
      int[]     colsizes        = new int[count.value + 1];
      double[]  suminfeas       = new double[count.value + 1];
      int[]     numinfeas       = new int[count.value + 1];
      problem.IISStatus(count, rowsizes, colsizes, suminfeas, numinfeas);
    }

    public void run (int iMode)
    {
      try {
        XPRSprob problem = new XPRSprob ();
        int i = 0;

        problem.setIntControl (XPRS.LPLOG, 1);
        problem.addMessageListener(this,null);

        problem.readProb ("iisexample","");

        problem.setIntControl(XPRS.PRESOLVE, -1);
        problem.lpOptimize ("");

        switch(iMode) {
        case(0) :
          /* Get all iis at once and then iterate through the results */
          problem.IISAll();
          for(i = 1; i < problem.getIntAttrib(XPRS.NUMIIS); i++) {
            Run_getIISData(problem, i);
            Run_IISStatus(problem, i);
            problem.writeIIS(i, "iis_result" + i, 0);
          }
          break;
        case(1) :
          i = 0;
          /* Get the iis one at a time */
          if(problem.firstIIS(1) == 0) {
            do {
              i++;
              Run_getIISData(problem, i);
              Run_IISStatus(problem, i);
              problem.writeIIS(i, "iis_result" + i, 0);
            } while(problem.nextIIS() == 0);
          }
          break;
        }

        problem.removeMessageListener();
      } catch(XPRSprobException xpe) {
        xpe.printStackTrace();
      }
    }

    public void XPRSmessageEvent(XPRSprob prob,
          Object data, String msg, int len, int type)
    {
      if(msg != null)
      System.out.println (msg);
    }

    public static void main(String [] args)
    {
      try {
        XPRS.init ();
      } catch (Exception e) {
        System.out.println ("Failed to initialize due to: "+e);
        return;
      }

      try {
        IISExample c = new IISExample ();
        c.run (0);
        c.run (1);

      } finally {
        XPRS.free ();
      }

    }
}