/**********************************************************************************\ * 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.mps 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 com.dashoptimization.*; public class Trimloss implements AutoCloseable { /** * Execute example from command-line **/ public static void main(String[] args) { String model = args.length == 0 ? "../data/trimloss" : args[0]; try (Trimloss trimloss = new Trimloss()) { trimloss.run(model); } } /** * 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 close() { probg.close(); } /** * Execute Trimloss example **/ public void run(String model) { /* Setup the logfile */ File logfile = new File("trimloss.log"); if (logfile.exists()) logfile.delete(); probg.setLogFile(logfile.toString()); /* Load initial problem */ loadInitialProblem(model); /* 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(String model) { probg.readProb(model); } /** * 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