# forum.alglib.net

ALGLIB forum
 It is currently Sat May 18, 2024 1:26 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.

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Linear Optimization with Sparse MatrixPosted: Sun Nov 19, 2023 7:40 pm

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

 Post subject: Re: Linear Optimization with Sparse MatrixPosted: Sun Nov 19, 2023 7:43 pm

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

 Post subject: Re: Linear Optimization with Sparse MatrixPosted: Tue Nov 21, 2023 3:14 pm

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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: Bing [Bot] and 3 guests

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

Search for: