5

How do I deal with sparse matrices in JuMP?

For example, suppose I want to impose a constrain of the form:

A * x == 0

where A is a sparse matrix and x a vector of variables. I assume that the sparsity of A could be exploited to make the optimization faster. How can I take advantage of this in JuMP?

Fengyang Wang
  • 11,901
  • 2
  • 38
  • 67
a06e
  • 18,594
  • 33
  • 93
  • 169

1 Answers1

3

JuMP already benefits from sparse matrix in different ways, I've not checked the source but refer to a cited paper from JuMP.jl:

In the case of LP, the input data structures are the vectors c and b and the matrix A in sparse format, and the routines to generate these data structures are called matrix generators

One point to note is that, the main task of algebraic modeling languages (AMLs) like JuMP is to generate input data structures for solvers. AMLs like JuMP do not solve generated problems themselves but they call standard appropriate solvers to do the task.

Reza Afzalan
  • 5,646
  • 3
  • 26
  • 44
  • I know JuMP only serves as an interface between the user and the solver. My question (more clear now) is whether if I supply JuMP with an sparse matrix (in a constrain of the form A * x == 0, for example, where A is a sparse matrix and x a vector), the data translated by JuMP and supplied to the solver will also be sparse (assuming that the solver is optimized to deal with sparse matrices). – a06e Apr 21 '16 at 15:48
  • @becko I think that JuMP does this under the hood. If you are skeptical, then try running a toy example with and without a sparse linear constraint matrix `A` to see for yourself. – Kevin L. Keys Jun 14 '16 at 03:40