Quadratic function as objective function
回答済みHello,
I am working on a maximization problem.
This is the original objective function:
model.setObjective(v @ x, GRB.MAXIMIZE)
But I need to make it a quadratic function: (v@x)**2.
If I write it like the following I get an error, so I am not sure how I should formulate it.
model.setObjective((v @ x)**2, GRB.MAXIMIZE)
Could someone help me with this issue?
Thank you in advance!!
Fatima
-
正式なコメント
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 try Gurobot, our chatbot interface offering instant, expert-level support. -
You seem to be using the matrix expressions for \(v\) and \(x\), is this correct? If yes, you need to define your objective as MQuadExpr.
If you store your variables and parameters in (tuple)dicts, this example should shed some light.
Best regards
Jonasz1 -
Thank you for your answer Jonasz.
Could you explain how I can use MQuadExpr in my case? I didn't understand how to write the code..
0 -
Assuming \(x\) corresponds to the variable matrix and \(v\) to some coefficients, I'd imagine the following to work:
model.setObjective(x @ v @ x, GRB.MAXIMIZE)
Best regards
Jonasz1 -
Thank you!!
Kind regards.
Fatima
0
投稿コメントは受け付けていません。
コメント
5件のコメント