Skip to main content

Retrieving MVar from Model read from file

Answered

Comments

4 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Juliano Camargo
    • Gurobi-versary
    • First Comment

    Apparently it is a new feature, but it would be really nice to be able to retrieve them as a matrix.

    1
  • Tobias Achterberg
    • Gurobi Staff Gurobi Staff

    Unfortunately, this is not how gurobipy and Gurobi work. The Python API in gurobipy is, by design, just a layer around the C API of Gurobi. And the C API does not understand the concept of matrix variables. The writing and reading of model files happens on the C layer. Hence, the structure of matrix variables is not contained in the *.mps files.

    Regards,

    Tobias

    0
  • Jiří Němeček
    • Gurobi-versary
    • First Comment
    • First Question

    I have come across the same issue. What works well for me is creating a model with the same variables (MVars), then reading the values to model from the *.sol file.

    In Python:

    model = gb.Model()
    var = model.addMVar((correct, dimensions), name="var")
    model.update() # prepare the variables to be accessible to read
    model.read("solution.sol") # load up the values
    model.optimize() # without constraints, this is almost instant
    print(val.X) # val.X can now be accessed
    0

Post is closed for comments.