| |||||||||||||
Folio - Advanced modeling and solving tasks from 'Getting Started' Description Working with multiple MIP solutions:
Source Files By clicking on a file name, a preview is opened at the bottom of this page.
Data Files foliomatsolpool.java /******************************************************** Xpress Optimizer Example Problems ================================= file foliomatsolpool.java ````````````````````````` Using the MIP solution pool with a MIP problem input from a matrix file. (c) 2009 Fair Isaac Corporation author: D.Nielsen, S.Heipcke, July 2009, rev. June 2010 ********************************************************/ import com.dashoptimization.*; class foliomatsolpool { public static void main(String args[]) { try { XPRS.init (); } catch (Exception e) { System.out.println("Failed to initialize"); return; } try { int s, nSols, nCols; DoubleHolder objval = new DoubleHolder(); double[] sol = new double[1]; IntHolder solID = new IntHolder(); IntHolder solStatus = new IntHolder(); XPRSprob prob = new XPRSprob(); XPRSmipsolpool msp = new XPRSmipsolpool(); /* Read in the matrix file */ prob.readProb("folio10_7.lp", ""); /* Attach the mip solution pool to the problem so it will automatically receive the solutions as they are found */ msp.probAttach(prob); /* Solve the problem */ prob.chgObjSense(XPRSenumerations.ObjSense.MAXIMIZE); prob.mipOptimize(); /* Get the number of solutions found */ nSols = msp.getIntAttrib(XPRS.MSP_SOLUTIONS); if(nSols > 0) { System.out.println("Number of solutions: " + nSols); /* Get the best objective value of the solutions found */ msp.getDblAttribProbExtreme(prob, 1, solID, XPRS.MSP_SOLPRB_OBJ, objval); System.out.println("Optimal solution ID: " + solID.value); System.out.println("Optimal objective : " + objval.value); /* Get the number of columns in the solutions */ nCols = msp.getIntAttribSol(solID.value, solStatus, XPRS.MSP_SOL_COLS); /* Print out the solution values of the best solution */ for(s=0; s<nCols ;s++) { msp.getSol(solID.value, solStatus, sol, s, s, null); if(sol[0]!=0) System.out.println((s+1) + ": "+ sol[0]); } } } catch(XPRSprobException xpe) { xpe.printStackTrace(); } XPRS.free(); } } | |||||||||||||
© Copyright 2024 Fair Isaac Corporation. |