forum.alglib.net
http://forum.alglib.net/

Linear Optimization with Sparse Matrix
http://forum.alglib.net/viewtopic.php?f=2&t=4587
Page 1 of 1

Author:  burakozyurek [ Sun Nov 19, 2023 7:40 pm ]
Post subject:  Linear Optimization with Sparse Matrix

Hello everyone!
I am a biologist and trying to perform flux balance analysis(a biological simulation technique with constraint based linear optimization) with Alglib & C++. I was used minlpsetlc() function but I want to use minlpsetlc2() with sparse matrix because of performance issues. But minlpsetlc2() function returns a vector with size 3 instead of 13K(=columnsize). I was able to get vector with size 13K when using minlpsetlc. I expected that the function can inference the real size of my dense matrix which is approximately 8K x 13K. You can find my code below.
One other thing: I assumed minlpsetlc2() perform calculations way faster than the other one. If not it is unnecessary to use this function for me. Thanks!


Code:
std::vector<std::vector<double>> S(rowsize, std::vector<double>(colsize, 0));
      int rowsize = 8460, colsize=12969;
      alglib::sparsematrix A;
      alglib::sparsecreate(rowsize, colsize, A);

                // Fill sparse matrix
      for (int i = 0; i < rowsize[code][/code]; i++)
      {
         for (int j = 0; j < colsize-1; j++)
         {
            S[i][j] = S_matrix[i * colsize + j];
            alglib::sparseset(A, i, j, S[i][j]);
         }
      }


      // ALGLIB PARAMETERS
      alglib::real_1d_array x;
      alglib::minlpreport rep;
      alglib::minlpstate state;

      // SET LINEAR SOLVER
      alglib::minlpcreate(3, state);

      // OBJECTIVE FUNCTION
      std::vector<double> f(colsize, 0);
      //f[12790] = -1;
      alglib::real_1d_array C = "[]";
      C.setcontent(colsize, f.data());
      alglib::minlpsetcost(state, C);

      std::vector<double> dummy(rowsize, 0);
      alglib::real_1d_array d1 = "[]";
      alglib::real_1d_array d2 = "[]";
      d1.setcontent(rowsize-1, dummy.data());
      d2.setcontent(rowsize-1, dummy.data());


      minlpsetalgoipm(state, 0);
      alglib::minlpsetlc2(state, A, d1, d2, rowsize);


      //real_1d_array s = "[55557,3]";
      //minlpsetscale(state,s);
      //  SOLVE
      // alglib::minlpsetalgodss(state, 0.9);


      alglib::minlpoptimize(state);

      // FLUX OUYPUTS
      alglib::minlpresults(state, x, rep);
      // set_single_behavior(pCell, "cycle entry", x[9]);

      // PRINT THE RESULTS
      printf("%s\n", x.tostring(2).c_str());


Author:  burakozyurek [ Sun Nov 19, 2023 7:43 pm ]
Post subject:  Re: Linear Optimization with Sparse Matrix

I was emphasized that I am a biologist because I have no knowledge of linear programming or mathematics. I'm just trying to apply linear optimization to my cell simulations. :)

Author:  Sergey.Bochkanov [ Tue Nov 21, 2023 3:14 pm ]
Post subject:  Re: Linear Optimization with Sparse Matrix

Hi!

Why do you create the solver with minlpcreate(3,..)? You have colsize variables, and colsize=12969 in your case.

Speaking of the performance, yes, setlc2() is much more efficient than setlc() with twice as many rows.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/