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.
From Gurobi 12 onwards it is possible to set the parameter IgnoreNames=1 which will cause all file formats, such as SOL and MST files, to be written in anonymous mode.
For Gurobi 11, or earlier, there is no anonymized equivalent for other file formats. However, the IgnoreNames parameter can be combined with gurobipy's Model.copy method to create an equivalent model with anonymized variable and constraint names. These names can then be used to overwrite the names in the original model, as well as in files written using the original model.
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.