About the parameter input and output of iterative algorithm in gurobi
AnsweredHi,
I'm using gurobi to build an iterative algorithm whose input and output variables are matrices. I have successfully solved single problem with gurobi, but I can not use the optimal solution of single solution as input of the next solution process. I have not found any relevant introduction in API document. If anyone can help me, I will be very grateful to you.
After I have solved the q of one iteration, I can't assign q to qc to complete the next calculation. Their form is as follows.
gurobi_sca(qc):
q = (4, 3, lb = -500, vtype = GRB.CONTINUOUS, name = 'q')
# Calculating functions about q and qc
return q
def main():
qc = np.array([[500, 500, 100], [500, -500, 100], [-500, 500, 100], [-500, -500, 100]])
while True:
result = gurobi_sca(qc)
qc = result
-
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?. -
Hi,
It is hard to determine what you are trying to achieve from your description and the short code snippets.
I guess you are adding \(\texttt{q}\) via the addVars function correct? After a successful optimization run, you can retrieve all variable solution values via the X attribute. So you could go with something like
if model.Status == GRB.OPTIMAL:
for i in range(4):
for j in range(3):
qc[i][j] = q[i,j].XBest regards,
Jaromił0 -
Hi,
Thanks to your help, I have successfully solved the problem.
Best regards,
Yanbo
0 -
Hi Jaromił Najman,
Could you help me answer my new question? My question has been posted for a few days, but no one answered it.
Best regards,
Yanbo
0
Post is closed for comments.
Comments
4 comments