How to set a constraint which needs the value of variables to calculate
回答済みHello,
I am having a trouble of setting up a constraint. My constraint includes the metrics that needs the value of variables to be calculated. The variables are binary and are treated as the selection of some features, then I need to use these binary values for the hit ratio and NDCG calculation. This is part of my constraint. However, the var.X attribute can only be accessed after optimization. How can I use the intermediate solutions or variable values to build my constraint? Thank you.
-
正式なコメント
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 Hanxiong,
You have to write the model in a form that Gurobi can solve. You won't be able to define your own black-box function and add it to a constraint.
If your constraint isn't in a form supported by Gurobi (e.g., has some non-quadratic nonlinear relationships), you can try building a piecewise-linear approximation of the function. In the Python API, you can do this with Model.addGenConstrPWL().
Does this answer your question?
Eli
0 -
Thank you
0
投稿コメントは受け付けていません。
コメント
3件のコメント