A linear objective against a combination of variables.
回答済みI've read through all the existing post titles; but the few possibles I read quickly went over my head. So, here's a simplified version of what I'm doing.
Suppose I have five variables: A, B, C, D, and E. I want to encourage A + B to be greater than 2000. Typically, it shouldn't actually get up to 2000, due to other constraints in the model. However, I want to encourage it to get up to 2000, or more, if it can. What would be a standard way of doing this?
Keep in mind that this is just a part of the model; the resources the five variables represent are also in demand elsewhere in the model. My situation is less about solving hard constraints; it's more about setting up a lot of competing objectives and then using Gurobi to find an optimal balance between all those objectives.
Here's what I've tried; but, I haven't gotten it to work yet. I create a linear expression that is A + B. I then create a constraint that a new variable X must equal that linear expression (i.e. constraint: X = A + B). I then set a piecewise linear objective on the variable X. Specifically, (I'm in LP maximization mode.) when X is 0, the objective value is 0. When X is 2000, the objective value is maximized, say 1000. It remains at 1000 as X continues to increase. So in summary, X = LinExpr = A + B, where X has an objective that encourages it to get to 2000 or more.
Some notes - I also haven't had success by setting a simple linear objective on X, instead of a piecewise one. In the example, I have two basic variables; but, there could be more than two, perhaps 10. No matter how high I turn up the objective value, it still has zero impact.
Thanks ahead of time, and please feel free to ask me for clarification! -JP
-
正式なコメント
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 John,
thanks for reaching out.
First of all, I would have modeled the expression slightly differently:
2000*y <= A + B
where y is an auxiliary binary variable. Combined with a high value in the objective function, this means that y "wants" to be 1, but can only do so if A+B >= 2000.
However, what you say should also work equally well, so I think there may be a conceptual problem here. Do you only want to create a reward for passing 2000, or do you want to motivate the problem to get as high up to 2000 as possible?
The key difference between these two statements it that in the first one, the problem will try to get to 2000, and if it cannot (as you suggested that it actually cannot), it will simply ignore that. In the second case, even if it cannot reach 2000, it will still push as much as possible to get there. To model that statement, I would write:
maximize X
subject to X <= 2000
X <= A + BWhat this does it that it tries to push A+B higher (which will increase X) up to the value 2000. If A+B > 2000, then the second constraint becomes non-binding (=redundant).
Hope this helps, let me know.
Best
Richard
0 -
Thanks much Richard! Both of those strategies help out a lot. They both introduce me to the idea of using intermediary variables (y and X) to help shape the results. To answer your question, in my case at least, I do indeed want to reward objective value smoothly all the way up to 2000 as well, not just once it hits 2000.
I'll try your idea of using an X intermediary ("shepard") variable. There's a chance it'll be more efficient than my latest implementation. Currently, I use what I'm calling a slack variable: A + B + slackVariable >= 2000. The slack variable ranges from 0 to 2000 but has a strong negative objective, encouraging it to get smaller, which implicitly ends up making A + B larger. It's quite effective; but, I'm struggling to find ways to make it faster.
So again, thanks much for the response Richard and I'm excited to try out the X "shepard variable" approach.
0
投稿コメントは受け付けていません。
コメント
3件のコメント