Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Help in addRow/addRange API

    Posted 06/23/10 04:21 PM

    Originally posted by: enthuTyro


    double numberOne, numberTwo;

    for(int k=0; k<50000; k++) {
    try {
    matrix.addRow(cplex.addRange(-Double.MAX_VALUE , cplex.sum(cplex.prod(numberTwo, intergerValue[k]), cplex.negative(binaryValue[k]) ),0, "1st constraint"));
    matrix.addRow(cplex.addRange(0 , cplex.sum(cplex.prod(numberOne, intergerValue[k]), cplex.negative(binaryValue[k]) ),Double.MAX_VALUE, "2nd constraint"));
    } catch (IloException e) {
    e.printStackTrace();
    }
    }

    I am using the IloLPMatrix format for the coding. Both integerValue and binaryValue are of type IloNumVarArray with the first one as positive integer (with upper bound) and second one with lb=0 & ub=1. Above two lines of the program is taking quite high time. Any suggestion for the rephrasing these two lines so that I can pass integerValue and binaryValue as array in one shot. I hope this will save time as there will be no frequent interaction between JAVA and CPLEX.

    Thanks in Advance
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Help in addRow/addRange API

    Posted 06/23/10 05:18 PM

    Originally posted by: SystemAdmin


    I don't use IloLPMatrix, so I'm not 100% sure, but I think the fact that you are using cplex.addRange rather than cplex.range is costing you some time (not to mention memory). The former method creates the range, adds it to the IloCplex instance, nad it returns it as an IloRange (which you then add to the matrix). The latter method creates and returns the range but does not add it to the matrix. If you're adding the matrix to cplex, you're adding the same ranges twice.

    That may turn out to be irrelevant, though. There's a form of the IloLPMatrix.addRanges method that accepts as input 1D arrays of lower and upper bounds, a 2D array of coefficients (just the nonzeros), and a 2D array of indices of variables whose coefficients are being specified. So if you keep track of which column in the matrix corresponds to integerValue[k] etc. (see IloLPMatrix.getIndex), this sounds like the method you want.

    /Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Help in addRow/addRange API

    Posted 06/24/10 02:56 AM

    Originally posted by: SystemAdmin


    I think this is what you want to do (untested)
    IloLPMatrix matrix = cplex.LPMatrix();
     
    // Add variables to matrix and remember index at which first column was added.
    int intIdx = matrix.addCols(integerValue, 0, 50000);
    int binIdx = matrix.addCols(binaryValue, 0, 50000);
     
    // Create 1st constraint: numberTwo*integerValue[k] - binaryValue[k] <= 0
    {
        double[] lb = new double[] { Double.NEGATIVE_INFINITY };
        double[] ub = new double[] { 0.0 };
     
        double[] lhsVal = new double[]{ numberTwo, -1.0 };
        double[][] val = new double[]{ lhsVal };
     
        int[][] ind = new int[][]{ lhsInd };
        int[] lhsInd = new int[2];
     
        for (int i = 0; i < 50000; ++i) {
            lhsInd[0] = intIdx + i;
            lhsInd[1] = binIdx + i;
            matrix.addRows(lb, ub, ind, val);
        }
    }
     
    // Create 2nd constraint: numberOne*integerValue[k] - binaryValue[k] >= 0
    {
        double[] lb = new double[] { 0.0 };
        double[] ub = new double[] { Double.POSITIVE_INFINITY };
     
        double[] lhsVal = new double[]{ numberOne, -1.0 };
        double[][] val = new double[]{ lhsVal };
     
        int[][] ind = new int[][]{ lhsInd };
        int[] lhsInd = new int[2];
     
        for (int i = 0; i < 50000; ++i) {
            lhsInd[0] = intIdx + i;
            lhsInd[1] = binIdx + i;
            matrix.addRows(lb, ub, ind, val);
        }
    }
    

    This still creates the rows one at a time but it should be easy to change the code so that it creates multiple rows in one shot.
    #CPLEXOptimizers
    #DecisionOptimization