As described in How do I upload or send files to Gurobi? it is possible to anonymize an MPS file by using the REW format, in which default names are given to variables and constraints. The REW format can be desirable when privacy is of great concern, but it does reduce the ability of our support staff to provide insights on the model.
Unlike MPS files, there is no anonymized equivalent for the SOL, MST, or other file formats currently available for use with Gurobi. There are plans to make this easily achievable in a future Gurobi release. We can however use a workaround using the IgnoreNames parameter, with the Model.copy method in gurobipy to create an equivalent model with anonymized names. These names can then be used to overwrite the names in the original model and the new files written.
Please see the following example:
import gurobipy as gp
m = gp.read("test.mps")
m.read("test.attr")
m.read("test.hnt")
m.read("test.sol")
m.params.IgnoreNames = 1
m_anon = m.copy()
m.params.IgnoreNames = 0
anon_var_names = m_anon.getAttr("VarName", m_anon.getVars())
anon_constr_names = m_anon.getAttr("ConstrName", m_anon.getConstrs())
anon_genconstr_names = m_anon.getAttr("GenConstrName", m_anon.getGenConstrs())
anon_qconstr_names = m_anon.getAttr("QCName", m_anon.getQConstrs())
m.setAttr("VarName", m.getVars(), anon_var_names)
m.setAttr("ConstrName", m.getConstrs(), anon_constr_names)
m.setAttr("GenConstrName", m.getGenConstrs(), anon_genconstr_names)
m.setAttr("QCName", m.getQConstrs(), anon_qconstr_names)
m.update()
m.params.SolutionLimit = 1
m.optimize() # only needed for mst or sol files
m.write("test_anon.mps")
m.write("test_anon.attr")
m.write("test_anon.hnt")
m.write("test_anon.sol")
Comments
0 comments
Article is closed for comments.