FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserNext example

Folio - Advanced modeling and solving tasks from 'Getting Started'

Description
Working with multiple MIP solutions:
  • foliomatenumsol.java - using the MIP solution enumerator
  • foliomatsolpool.java - using the MIP solution pool

foliooptadvj.zip[download all files]

Source Files

Data Files





foliomatenumsol.java

/********************************************************
  Xpress Optimizer Example Problems
  =================================

  file foliomatenumsol.java
  `````````````````````````
  Using the MIP solution enumerator with a MIP problem
  input from a matrix file.

  (c) 2009 Fair Isaac Corporation
      author: D.Nielsen, S.Heipcke, July 2009, rev. Jan. 2013
********************************************************/

import com.dashoptimization.*;

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

  try {
   IntHolder maxSols = new IntHolder();
   int i, s, nSols, nCols, presolveOps;
   int[] solID = new int[1];
   double[] sol = new double[1];
   IntHolder solStatus = new IntHolder();
   DoubleHolder objval = new DoubleHolder();

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

   /* Use the default handler for the solutions found when we run mse */
   XPRSdefaultMipSolEnumHandler handler = new XPRSdefaultMipSolEnumHandler();

   /* Read in the matrix file */
   prob.readProb("folio10_7.lp", "");

   /* Get the number of columns in the problem */
   nCols = prob.getIntAttrib(XPRS.ORIGINALCOLS);

   /* Disable heuristics to avoid duplicate solutions being found and stored */
   prob.setIntControl(XPRS.HEURSTRATEGY, 0);

   /* Disable presolve operations that attempt to improve the efficiency by 
      cutting off MIP solutions from the feasible region that are either:-
       1) Degenerate (i.e., that have equivalent representations with 
          different feasible values of the variables) or
       2) Dominated (i.e., that can be deduced to be worse than solutions 
          contained in the remaining feasible region). 
   */
   presolveOps = prob.getIntControl(XPRS.PRESOLVEOPS);  
   presolveOps = ~(1 << 5);     /* Disable duplicate column removal  */
   presolveOps = ~(1 << 3);     /* Disable dual reduction operations */
   prob.setIntControl(XPRS.PRESOLVEOPS, presolveOps);  
   presolveOps = prob.getIntControl(XPRS.MIPPRESOLVE);  
   presolveOps = ~(1 << 4);     /* Disable dual reductions  */
   prob.setIntControl(XPRS.MIPPRESOLVE, presolveOps);  
   prob.setIntControl(XPRS.SYMMETRY, 0);   /* Disable symmetry detection */

   /* Run the enumeration */
   maxSols.value = 10;
   mse.maxim(prob, msp, handler, maxSols);

   /* Get the number of solutions found */
   nSols = mse.getIntAttrib(XPRS.MSE_SOLUTIONS);

   /* Print out the solutions found */
   for(i=1; i<=nSols; i++)
   {
    mse.getSolList(XPRS.MSE_METRIC_MIPOBJECT, i, i, solID, null, null);
    mse.getSolMetric(solID[0], solStatus, XPRS.MSE_METRIC_MIPOBJECT, objval);
    System.out.println("--------\nSolution " + i + ":  Objective: " + objval);
    for(s=0; s<nCols ;s++) {
     msp.getSol(solID[0], solStatus, sol, s, s, null);
     if(sol[0]!=0) System.out.println((s+1) + ": "+ sol[0]);
    }
   }
  } catch(XPRSprobException xpe) {
   xpe.printStackTrace();
  }

  XPRS.free();
 }
}

Back to examples browserNext example