forum.alglib.net

ALGLIB forum
It is currently Fri Nov 08, 2024 5:09 pm

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Linear Optimization with Sparse Matrix
PostPosted: Sun Nov 19, 2023 7:40 pm 
Offline

Joined: Sun Nov 19, 2023 7:23 pm
Posts: 4
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());



Top
 Profile  
 
 Post subject: Re: Linear Optimization with Sparse Matrix
PostPosted: Sun Nov 19, 2023 7:43 pm 
Offline

Joined: Sun Nov 19, 2023 7:23 pm
Posts: 4
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. :)


Top
 Profile  
 
 Post subject: Re: Linear Optimization with Sparse Matrix
PostPosted: Tue Nov 21, 2023 3:14 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 925
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group