Copying Model and Revising Basis Questions
Dear Community Members,
1-) I want to keep my basis of the model. After changing rhs of the model and solve the model again, I want to back old basis(before change) of the model. I tried to apply on Pytho. However it gives "File "C:/Users/Administrator/Documents/Python/tabu_tr_3.py", line 264, in <module>
detmas.read("det.bas")
File "model.pxi", line 1539, in gurobipy.Model.read
GurobiError: MPS reader: row name c0 doesn't exist
"
I use only this two lines:
detmas.write("det.bas")
detmas.read("det.bas")
2-)I wanted to code an algorithm which includes 3 deep copies of same model. After copying model I wanted to change rhs of my model. However it gives "File "constr.pxi", line 65, in gurobipy.Constr.__setattr__ File "constr.pxi", line 162, in gurobipy.Constr.setAttr GurobiError: Constraint has not yet been added to the model" error. I wrote a part of code to clarify my point:
detmas2.update()
detmas=detmas2.copy()
athu=unop[j]
hopen[athu]=1
for k in Nset:
detmas.setAttr("RHS",covcon[athu,k], A[athu,k]*d[k]*hopen[athu] )
#covcon[athu,k].RHS=A[athu,k]*d[k]*hopen[athu]
for i in Nset:
covcot[i,athu].RHS=A[i,athu]*o[i]*hopen[athu]
I tried with commented line firstly. After that I want to try with different approaches. However it gave different error "
File "C:/Users/Administrator/Documents/Python/tabu_tr_2.py", line 276, in <module>
detmas.setAttr("RHS",covcon[athu,k], A[athu,k]*d[k]*hopen[athu] )
File "model.pxi", line 1711, in gurobipy.Model.setAttr
TypeError: object of type 'Constr' has no len()
How can I handle these situations?
Thanks in advance,
Warm regards,
-
Official comment
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?. -
- When programming, it's better to save the basis status in code rather than a file. If you must save as a file, make sure you use the same names for variables and constraints.
- Which line is causing the error?
1 -
Thank you for your quick response,
For second question, I guess "detmas.setAttr("RHS",covcon[athu,k], A[athu,k]*d[k]*hopen[athu] ) " line causes error.
I want to do in both codes that: There is a main model in a loop. In this loop some RHS values of the constraints of the model change in each loop. End of the each loop, changes in the RHS are taken back and transformed to the main model. So I think keeping the main model's basis helps us to reducing computational time. However there are inappropriate things in my models.
Thanks in advance,
Warm regards,
1
Post is closed for comments.
Comments
3 comments