• Gurobi Staff

This can be done by writing the model to an rlp file it and then reading the rlp file before the model is optimized.

import gurobipy as gpm = gp.Model()# construct model#...# write model to rlp filem.write("model.rlp")# read model from rlp file to overwrite variable and constraint namesm = gp.read("model.rlp")# optimize modelm.optimize()# write solution file# the solution file holds variable names from the rlp file and thus,# can be read in for the rlp fileif m.SolCount > 0:  m.write("solution_rlp.sol")# ...# read rlp filem = gp.read("model.rlp")# read solution for rlp file generated abovem.read("solution_rlp.sol")

Best regards,
Jaromił

Thanks, but in my situation, I don't want to call optimize, which will cost a lot of time without any feasible solution. However, I have a mps and a sol to it, I want to convert the sol of mps into a sol of rlp. Is there a easy way to do that？

• Gurobi Staff

If you have an MPS file and a corresponding SOL file then this can be achieved with quite low effort

import gurobipy as gp# read mps file and corresponding solution filem = gp.read("model.mps")m.read("solution.sol")m.update()# save the initial solution valuesstart = []for v in m.getVars():  start.append(v.Start)# write the model as rlp file to convert variable namesm.write("model.rlp")# read the rlp model to use new variable namesm = gp.read("model.rlp")# set initial point valuesvars = m.getVars()for i in range(len(vars)):  vars[i].Start = start[i]# set SolutionLimit parameter to 1 to terminate# immediately after using MIP start valuesm.setParam("SolutionLimit",1)m.optimize()# write the MIP start values out with rlp variable namesm.write("solution_rlp.sol")

The key points in the above is that the variable ordering stays the same the reading an MPS file and the corresponding RLP file and that setting the parameter SolutionLimit to 1 avoids unnecessary optimization.

Best regards,
Jaromił

Thanks, that solves my problem.

From your code, I finally realize that reading a sol file and a mst file has the same effect, which set the start attribute of each variable in the file, right?

As the documentation says, lp format won't keep column order. Is that different for lp and rlp file?

• Gurobi Staff

From your code, I finally realize that reading a sol file and a mst file has the same effect, which set the start attribute of each variable in the file, right?

This is correct with the subtle difference that an MST file holds integer information only. A SOL file holds also solution values of continuous variables.

As the documentation says, lp format won't keep column order. Is that different for lp and rlp file?

Good point. While usually the order should be prevailed when reading an LP file, it is definitely not guaranteed. This also holds for RLP files. In this case, I would recommend to change the above code to write and read a REW file, which is the RLP equivalent of MPS files.

# ...# write the model as rew file to convert variable namesm.write("model.rew")# read the rew model to use new variable namesm = gp.read("model.rew")# ...

Best regards,
Jaromił