coin-or / python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Eclipse Public License 2.0
530 stars 92 forks source link

dictionary or sparse matrices support #307

Closed JoOkuma closed 1 year ago

JoOkuma commented 1 year ago

Hi,

I'm working on cell tracking using ILP. We've been using gurobi for a while but I'm looking for other alternatives that don't require installing/buying licenses.

The problem can reach millions of variables but it's very sparse and it can take a while to build it when using pure python loops.

Is any of the approaches below supported by python-mip? If not, how hard would it be to add this to the current code base, I might have some bandwidth to implement it.

Other alternatives are welcome.

christian2022 commented 1 year ago

It would be helpful, if you provide some executable example code, showing your issue.

sebheger commented 1 year ago

@JoOkuma thanks for posting your idea here. I would say the same as @christian2022 that we need to understand in more detail what is slow, what is your requirement in details to determine what is necessary and what need to be done

JoOkuma commented 1 year ago

Sorry for the late response. While implementing a reproducible example I found an efficient implementation by mapping the keys to an index array from 0 to N-1 and using the existing var_tensor API.

To query the keys I used the group_by operator from the pandas.DataFrame, when called multiple times it's much faster than selecting from a numpy array directly.

@sebheger and @christian2022, I'm ok with closing the issue since a solution was found.