How to get the total coeff matrix of MILP model
AnsweredI am working on research of ML4CO with gurobi optimizer and wish to utilize the coeff matrix as some kind of input of neural networks. If I have problems in format of problem.lp, after loading it into a gurobi model, I wonder how can I directly get the total coeff matrix instead of iterating the model.getRow or other iterative method.
-
Official comment
Hi Shiyuan,
We appreciate your reply.
Based on your answers, we would recommend this Python Gurobi function to extract constraint coefficients as a Scipy matrix in CSR format.
With respect to the RHS and objective coefficients, you could use:
rhs = m.getAttr("RHS",m.getConstrs()) obj = m.getAttr("Obj",m.getVars())
You may need to modify the data structures for rhs and obj, but that depends on how you structure them as input to your NN.
Warm thanks,
Erik H.
-
Hi Shiyuan,
We appreciate your question.
To get started, we do have some questions:
1. In the context of your research, what software programming language are you currently using to interact with the Gurobi API?
2. When you say the "total coeff matrix", do you mean the coefficients of only the constraints? Or constraint coefficients, right-hand side coefficients, and objective coefficients?
3) Are you looking to execute an optimization process with Gurobi, and then send this "total coeff matrix" into the neural network as training input? Or as neural weights?
Warm thanks,
Erik H.
0 -
Thx for your reply~
1. I use python as my programming language.
2. I would better have the constraints coefficients, RHS and objective coefficients.
3. In short, it can be understood that I try to gain a matrix of all of the coeff above and use them as input of NN.
0 -
I sincerely appreciate your genuine help and prompt response. The method you provided has significantly improved my work efficiency, and my questions have been thoroughly resolved.
0
Please sign in to leave a comment.
Comments
4 comments