/**********************************************************************************\ * Name: Trimloss.c Fair Isaac 14/03/2014 * * Purpose: Modify a problem by adding an extra variable within an additional * * constraint. * * Description: We take a trimloss problem in which each integer variable x(p) * * represents the number of rolls cut to pattern p. * * We define a new integer variable y=SUM(p)x(p) and add the associated* * constraint * * x(1)+x(2)+...+x(N)-y = 0 * * We do this by first adding a row containing the (unitary) * * coefficients of the x(p), and then a column corresponding to y. * * We output the revised matrix to a file and then solve the revised * * MIP, giving y the highest branching priority. Finally, we output * * the solution, both to the screen and to an ASCII solution file. * * Input: trimloss.mat original matrix file * * Output: trimloss.log log file * * Trimloss.sol binary solution file - produced by default * * Revised.mps revised matrix file * * Revised.asc ASCII solution file * * Revised.hdr header for the ASCII solution file * \**********************************************************************************/ import java.io.*; import java.text.DecimalFormat; import com.dashoptimization.*; public class Trimloss { /** * Execute example from command-line **/ public static void main(String[] args) { Trimloss trimloss = null; XPRS.init(); try { System.out.println(XPRS.getBanner()); trimloss = new Trimloss(); trimloss.run(); } finally { if (trimloss!=null) trimloss.destroy(); XPRS.free(); } } /** * XPRSprob for the trimloss problem **/ private XPRSprob probg; /** * The index of the newly-added now **/ private int addedRowIndex; /** * The index of the newly-added column **/ private int addedColIndex; /** * Initialize Trimloss problem **/ public Trimloss() { probg = new XPRSprob(); } /** * Destroy the Trimloss problem **/ public void destroy() { probg.destroy(); } /** * Execute Trimloss example **/ public void run() { /* Setup the logfile */ File logfile = new File("trimloss.log"); if (logfile.exists()) logfile.delete(); probg.setLogFile(logfile.toString()); /* Print Xpress version number */ DecimalFormat versionNumberFormatter = new DecimalFormat("0.00"); System.out.println("Xpress Optimizer Subroutine Library Release "+versionNumberFormatter.format( (double)probg.controls().getVersion()/100 )); /* Load initial problem */ loadInitialProblem(); /* Add new row */ addNewRow(); /* Add new column */ addNewColumn(); /* Output the revised matrix */ probg.writeProb("revised"); /* Solve the MIP */ solveProblem(); /* Display solution */ printSolution(); /* Write solution to an ASCII file */ probg.writeSol("revised"); } /** * Loads the initial trimloss matrix into the Xpress-Optimizer problem **/ private void loadInitialProblem() { probg.readProb("../data/trimloss"); } /** * Adds a new row to the matrix **/ private void addNewRow() { int nCol = probg.attributes().getCols(); /* nCol = number of columns in the matrix */ int nNewRows = 1; /* Adding 1 new row */ double[] dRHS = {0.0}; int[] nRowStart = {0}; byte[] sRowType = {'E'}; /* Store the coefficients of x(p); */ int nRowElem = nCol; /* New row has a coefficient in every column */ double[] pRowVal = new double[nRowElem]; int[] pColInd = new int[nRowElem]; for (int i=0;i