pythonpyomogurobi

Keeping variable names when exporting Pyomo into a .mps file


So, i'm currently working with a pyomo model with multiple instances that are being solved in parallel. Issue is, solving them takes pyomo quite a long time (like 2 to 3 secs, even though the solving part by gurobi takes about 0.08s). I've found out that, by exporting a pyomo instance into an .mps file and then giving it to gurobipy i can get like an increase of 30% in overall speed.

The problem comes later, when i want to work with the variables of the solved model, because ive noticed that, when exporting the original instance from pyomo into a .mps file, variable names get lost; they all get named "x" (so, for example, model.Delta, model.Pg, model.Alpha, etc get turned into x1, x2, ... ,x9999 instead of Delta[0], Delta[1], ... Alpha[99,99]).

Is there a way to keep the original variable name when exporting the model?


Solution

  • Managed to solve it! To anyone who might find this useful, i passed a dictionary with "symbolic_solver_labels" as an io_options argument for the method, like this:

    instance.write(filename = str(es_) + ".mps", io_options = {"symbolic_solver_labels":True})
    

    Now my variables are correctly labeled in the .mps file!