Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Question about CPLEX example mipex.c

    Posted 01/26/10 02:07 AM

    Originally posted by: ilovetoyota


    If I need to construct very big matrix with zero and non-zero coefficient,

    it is very hard to count NUMNZ, is there any easy way to construct lp, such that I can just add row by row, without caring how many non-zero coefficient?

    Thanks
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Question about CPLEX example mipex.c

    Posted 01/26/10 02:23 AM

    Originally posted by: SystemAdmin


    You can do CPXnewcols() to create empty columns (variables) and then
    use CPXaddrows() to add the constraints row-by-row.
    You will have to compute the number of non-zeroes per row, though.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Question about CPLEX example mipex.c

    Posted 01/26/10 01:47 PM

    Originally posted by: ilovetoyota


    Is there any way to bypass the step of counting the number of zeros or non-zeros per row etc?

    Or is there any published code on the internet that can help me to read in a matrix directly? How do most of you handle the input of a matrix?

    Thanks a lot!
    ========================================
    You can do CPXnewcols() to create empty columns (variables) and then
    use CPXaddrows() to add the constraints row-by-row.
    You will have to compute the number of non-zeroes per row, though.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Question about CPLEX example mipex.c

    Posted 01/28/10 02:25 PM

    Originally posted by: SystemAdmin


    I don't see why counting the number of non-zeroes in a row is such a big issue for you.
    Assume you have the number of columns in variable 'cols' and the row in 'row':
    int cols = ...;
    double *row = ...;
     
    int i, nzs = 0;
    double *compressed = malloc(sizeof(*compressed) * cols);
     
    if ( !compressed ) {
       /* Out of memory. */
       ...
    }
     
    for (i = 0; i < cols; ++i) {
       if ( fabs(row[i]) > 0.0 =
          compressed[nzs++] = row[i];
    }
    

    After that you have the non-zeroes in 'compressed' and the number of non-zeroes in 'nzs'.
    I guess most people store their matrices in compressed form and so don't have the issue
    of reading a dense matrix.

    You can also try to pass the dense row to CPXaddrows(). I think the zeroes in the row
    won't do any harm to CPLEX. It is just a big waste of space unless the matrix is dense.
    #CPLEXOptimizers
    #DecisionOptimization