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
By clicking on a file name, a preview is opened at the bottom of this page.
foliomatenumsol.java[download]
foliomatsolpool.java[download]

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. 2023
********************************************************/

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;
   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.HEUREMPHASIS, 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). 
   */
   prob.setIntControl(XPRS.MIPDUALREDUCTIONS, 0);

   /* 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