Decision Optimization

Decision Optimization

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

 View Only
  • 1.  About large sparse matrix

    Posted Mon June 20, 2016 08:58 PM

    Originally posted by: qtbgo


    Hello, I have a large mxn matrix A, elements in it is 0 or 1 or -1, which is very sparse.  The file storing A is 300M large (if I zip this file, the zipped file becomes 3M large). I use java concert to model AX<=M.  X is a var array including 30000 binary variable.

    1  I wonder if cplex can compress matrix A automatically in memory? if  IloLPMatrix can compress the matrix?

     

    2  can I preprocess the file to compress it so that it becomes smaller and can be read into model eaiser?


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: About large sparse matrix

    Posted Tue June 21, 2016 03:24 AM

    1. Just don't submit the terms with coefficient 0 to CPLEX. That is the best you/CPLEX can do.

    2. Remove all 0s from the file and store the remaining data in a sparse way, for example as triples (row, column, coefficient).


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: About large sparse matrix

    Posted Tue June 21, 2016 08:47 AM

    Originally posted by: qtbgo


    about question 1:

    I read the manual here. it talks about sparse. I am not sure if I understand it well. I guess if I use  IloLPMatrix to store sparse matrix, then it will remove all 0s automaticly, am I right?

     

    about question 2:

    Is there an example demonstrating your idea?


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: About large sparse matrix

    Posted Thu June 23, 2016 01:39 AM

    1. No, IloLPMatrix will not automatically remove 0's from your data. This is illustrated by the following example

    import ilog.cplex.*;
    import ilog.concert.*;
    
    public final class Sparse {
       public static void main(String[] args) throws IloException {
          final IloCplex cplex = new IloCplex();
          try {
             IloNumVar x = cplex.boolVar("x");
             IloNumVar y = cplex.boolVar("y");
             IloNumVar z = cplex.boolVar("z");
    
             IloLinearNumExpr expr = cplex.linearNumExpr();
             expr.addTerm(1.0, x);
             expr.addTerm(0.0, y);
             expr.addTerm(1.0, z);
    
             System.out.println(expr);
    
             IloRange rng = cplex.range(1.0, expr, 2.0);
             System.out.println(rng);
    
             IloLPMatrix matrix = cplex.LPMatrix();
             matrix.addRow(rng);
             matrix.addRow(2.0, 3.0, new int[]{ 0, 1, 2 },
                           new double[]{ 0.0, 1.0, 2.0 });
             System.out.println(matrix);
          }
          finally {
             cplex.end();
          }
       }
    }
    

    which prints

    (1.0*x + 0.0*y + 1.0*z)
    IloRange  : 1.0 <= (1.0*x + 0.0*y + 1.0*z) <= 2.0
    IloLPMatrix  {
      IloRange  : 1.0 <= (1.0*x + 0.0*y + 1.0*z) <= 2.0
      IloRange  : 2.0 <= (0.0*x + 1.0*y + 2.0*z) <= 3.0
    }

     

    2. I don't think there is an example shipped with CPLEX. But it should be rather obvious what to do: instead of storing a matrix in the file, only store the triples of non-zeros.


    #CPLEXOptimizers
    #DecisionOptimization