Decision Variable Value from a Set (Gurobi)When does Gurobi add cuts from callbackIn an integer program, how...
Drawing Maps; flat distortion
What does "execute a hard copy" mean?
How dangerous is a very out-of-true disc brake wheel?
As a team leader is it appropriate to bring in fundraiser candy?
Can anyone give me the reason why music is taught this way?
Is there anything on the ISS that would be destroyed if that object were returned to Earth?
Knights and Knaves: What does C say?
Caro-Kann c4-c5 push
How to identify whether a publisher is genuine or not?
Booting Ubuntu from USB drive on MSI motherboard -- EVERYTHING fails
Why the first octet of a MAC address always end with a binary 0?
How can Germany increase investments in Russia while EU economic sanctions against Russia are still in place?
Why does `FindFit` fail so badly in this simple case?
If I travelled back in time to invest in X company to make a fortune, roughly what is the probability that it would fail?
How dangerous are my worn rims?
How to transcribe an arpeggiated 4-note chord to be playable on a violin?
Meaning of "fin" in "fin dai tempi"
SOQL injection vulnerability issue
Disable all sound permanently
Would a horse be sufficient buffer to prevent injury when falling from a great height?
PhD Length: are shorter PhD degrees (from different countries) valued differently in other counter countries where PhD Is a longer process?
Are there types of animals that can't make the trip to space? (physiologically)
Replace zeros in a list with last nonzero value
Parent asking for money after moving out
Decision Variable Value from a Set (Gurobi)
When does Gurobi add cuts from callbackIn an integer program, how I can force a binary variable to equal 1 if some condition holds?In an integer program, how can I “activate” a constraint only if a decision variable has a certain value?Does the API affect the time Gurobi requires to find an optimum?How to write a mixed-integer linear programming formulation in Python using Gurobi?Finding an optimal set without forbidden subsetsQuerying attributes of LP relaxation at MIP-optimality in GurobiCommon structures in Gurobi - PythonWhat do solvers like Gurobi and CPLEX do when they run into hard instances of MIPExtract info from Gurobi binary variables during run-time
$begingroup$
Is there a way to set a decision variable to take values from a set?
Example:
decision variable $x in {0,50,100}$
So this variable can only take one of these three values and not more.
I have found a documentation online which unfortunately does not state such a thing:
Gurobi Documentation
For this example, I could probably set two different decision variables, with lower bound 0 and 50 or 100, respectively. I am not satisfied with this method, though.
This is how it would probably look like in Java:
//GRBVar addVar(double lb, double ub, double obj, char type, String name)
GRBVar x = model.addVar(50.0,50.0,null,GRB.SEMIINT,"x");
GRBVar y = model.addVar(100.0,100.0,null,GRB.SEMIINT,"y");
Note:
A semi-continous variable has the property that it takes a value of 0, or a value between the specified lower and upper bounds. A semi-integer variable adds the additional restriction that the variable also take an integral value (GRB.SEMIINT).
integer-programming gurobi
$endgroup$
add a comment
|
$begingroup$
Is there a way to set a decision variable to take values from a set?
Example:
decision variable $x in {0,50,100}$
So this variable can only take one of these three values and not more.
I have found a documentation online which unfortunately does not state such a thing:
Gurobi Documentation
For this example, I could probably set two different decision variables, with lower bound 0 and 50 or 100, respectively. I am not satisfied with this method, though.
This is how it would probably look like in Java:
//GRBVar addVar(double lb, double ub, double obj, char type, String name)
GRBVar x = model.addVar(50.0,50.0,null,GRB.SEMIINT,"x");
GRBVar y = model.addVar(100.0,100.0,null,GRB.SEMIINT,"y");
Note:
A semi-continous variable has the property that it takes a value of 0, or a value between the specified lower and upper bounds. A semi-integer variable adds the additional restriction that the variable also take an integral value (GRB.SEMIINT).
integer-programming gurobi
$endgroup$
$begingroup$
I removed the tag or-tools because this question is not about OR Tools, Google's OR solver. If I was wrong to do so, please add it back, along with clarification in the question. Thanks!
$endgroup$
– LarrySnyder610♦
3 hours ago
add a comment
|
$begingroup$
Is there a way to set a decision variable to take values from a set?
Example:
decision variable $x in {0,50,100}$
So this variable can only take one of these three values and not more.
I have found a documentation online which unfortunately does not state such a thing:
Gurobi Documentation
For this example, I could probably set two different decision variables, with lower bound 0 and 50 or 100, respectively. I am not satisfied with this method, though.
This is how it would probably look like in Java:
//GRBVar addVar(double lb, double ub, double obj, char type, String name)
GRBVar x = model.addVar(50.0,50.0,null,GRB.SEMIINT,"x");
GRBVar y = model.addVar(100.0,100.0,null,GRB.SEMIINT,"y");
Note:
A semi-continous variable has the property that it takes a value of 0, or a value between the specified lower and upper bounds. A semi-integer variable adds the additional restriction that the variable also take an integral value (GRB.SEMIINT).
integer-programming gurobi
$endgroup$
Is there a way to set a decision variable to take values from a set?
Example:
decision variable $x in {0,50,100}$
So this variable can only take one of these three values and not more.
I have found a documentation online which unfortunately does not state such a thing:
Gurobi Documentation
For this example, I could probably set two different decision variables, with lower bound 0 and 50 or 100, respectively. I am not satisfied with this method, though.
This is how it would probably look like in Java:
//GRBVar addVar(double lb, double ub, double obj, char type, String name)
GRBVar x = model.addVar(50.0,50.0,null,GRB.SEMIINT,"x");
GRBVar y = model.addVar(100.0,100.0,null,GRB.SEMIINT,"y");
Note:
A semi-continous variable has the property that it takes a value of 0, or a value between the specified lower and upper bounds. A semi-integer variable adds the additional restriction that the variable also take an integral value (GRB.SEMIINT).
integer-programming gurobi
integer-programming gurobi
edited 3 hours ago
LarrySnyder610♦
6,59215 silver badges67 bronze badges
6,59215 silver badges67 bronze badges
asked 8 hours ago
GeorgiosGeorgios
32813 bronze badges
32813 bronze badges
$begingroup$
I removed the tag or-tools because this question is not about OR Tools, Google's OR solver. If I was wrong to do so, please add it back, along with clarification in the question. Thanks!
$endgroup$
– LarrySnyder610♦
3 hours ago
add a comment
|
$begingroup$
I removed the tag or-tools because this question is not about OR Tools, Google's OR solver. If I was wrong to do so, please add it back, along with clarification in the question. Thanks!
$endgroup$
– LarrySnyder610♦
3 hours ago
$begingroup$
I removed the tag or-tools because this question is not about OR Tools, Google's OR solver. If I was wrong to do so, please add it back, along with clarification in the question. Thanks!
$endgroup$
– LarrySnyder610♦
3 hours ago
$begingroup$
I removed the tag or-tools because this question is not about OR Tools, Google's OR solver. If I was wrong to do so, please add it back, along with clarification in the question. Thanks!
$endgroup$
– LarrySnyder610♦
3 hours ago
add a comment
|
2 Answers
2
active
oldest
votes
$begingroup$
I don't think directly, but one way to model that would be to:
define a parameter as the vector of the possible values: $p = [0,50,100]$
define three binary decision variables that each correspond to whether a value in the set is selected ($y_i in {0,1}, i = 1,2,3$)
enforce constraints:
$sum_{iin {1,2,3} } y_i = 1$ (select exactly 1 of the values to use)
$x=sum_{iin {1,2,3} } p_iy_i $ (apply the chosen value to the variable $x$)
$endgroup$
1
$begingroup$
Quite similar to my suggestion. Nevertheless, thanks for a clear answer.
$endgroup$
– Georgios
8 hours ago
add a comment
|
$begingroup$
In the case of the example that you provided,(and generally, if you have a pattern in the set of available values for $x$), I am assuming that you have the mentioned pattern in the values of the set, you can define your variable $x$ as the integer and then multiply the value of $x$ by a constant. To explain what I mean:
$x in {0, 50, 100}$ can be equivalently replaced by $x' in {0, 1, 2}$ and then $x = 50 times x'$ in all constraints and objective function.
But if the general form of decision variable's set is not like the example that you mentioned, this approach won't work. Comment on this solution if my assumption is not correct.
$endgroup$
1
$begingroup$
Brilliant answer if the values are the same as in my example. What if I had values such as $x in {0,2,5,11}$ that are not succeeding one another?
$endgroup$
– Georgios
8 hours ago
$begingroup$
@Georgios One option is to create three binary DVs: x_gt_0, x_gt_2, x_gt_5, constrained s.t. x_gt_5 <= x_gt_2 <= x_gt_0, and constrain x = 2*x_gt_0 + (5-2)*x_gt_2 + (11-5)*x_gt_5.
$endgroup$
– Geoffrey Brent
4 hours ago
add a comment
|
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "700"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2for.stackexchange.com%2fquestions%2f2659%2fdecision-variable-value-from-a-set-gurobi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
I don't think directly, but one way to model that would be to:
define a parameter as the vector of the possible values: $p = [0,50,100]$
define three binary decision variables that each correspond to whether a value in the set is selected ($y_i in {0,1}, i = 1,2,3$)
enforce constraints:
$sum_{iin {1,2,3} } y_i = 1$ (select exactly 1 of the values to use)
$x=sum_{iin {1,2,3} } p_iy_i $ (apply the chosen value to the variable $x$)
$endgroup$
1
$begingroup$
Quite similar to my suggestion. Nevertheless, thanks for a clear answer.
$endgroup$
– Georgios
8 hours ago
add a comment
|
$begingroup$
I don't think directly, but one way to model that would be to:
define a parameter as the vector of the possible values: $p = [0,50,100]$
define three binary decision variables that each correspond to whether a value in the set is selected ($y_i in {0,1}, i = 1,2,3$)
enforce constraints:
$sum_{iin {1,2,3} } y_i = 1$ (select exactly 1 of the values to use)
$x=sum_{iin {1,2,3} } p_iy_i $ (apply the chosen value to the variable $x$)
$endgroup$
1
$begingroup$
Quite similar to my suggestion. Nevertheless, thanks for a clear answer.
$endgroup$
– Georgios
8 hours ago
add a comment
|
$begingroup$
I don't think directly, but one way to model that would be to:
define a parameter as the vector of the possible values: $p = [0,50,100]$
define three binary decision variables that each correspond to whether a value in the set is selected ($y_i in {0,1}, i = 1,2,3$)
enforce constraints:
$sum_{iin {1,2,3} } y_i = 1$ (select exactly 1 of the values to use)
$x=sum_{iin {1,2,3} } p_iy_i $ (apply the chosen value to the variable $x$)
$endgroup$
I don't think directly, but one way to model that would be to:
define a parameter as the vector of the possible values: $p = [0,50,100]$
define three binary decision variables that each correspond to whether a value in the set is selected ($y_i in {0,1}, i = 1,2,3$)
enforce constraints:
$sum_{iin {1,2,3} } y_i = 1$ (select exactly 1 of the values to use)
$x=sum_{iin {1,2,3} } p_iy_i $ (apply the chosen value to the variable $x$)
answered 8 hours ago
E. TuckerE. Tucker
1,0222 silver badges19 bronze badges
1,0222 silver badges19 bronze badges
1
$begingroup$
Quite similar to my suggestion. Nevertheless, thanks for a clear answer.
$endgroup$
– Georgios
8 hours ago
add a comment
|
1
$begingroup$
Quite similar to my suggestion. Nevertheless, thanks for a clear answer.
$endgroup$
– Georgios
8 hours ago
1
1
$begingroup$
Quite similar to my suggestion. Nevertheless, thanks for a clear answer.
$endgroup$
– Georgios
8 hours ago
$begingroup$
Quite similar to my suggestion. Nevertheless, thanks for a clear answer.
$endgroup$
– Georgios
8 hours ago
add a comment
|
$begingroup$
In the case of the example that you provided,(and generally, if you have a pattern in the set of available values for $x$), I am assuming that you have the mentioned pattern in the values of the set, you can define your variable $x$ as the integer and then multiply the value of $x$ by a constant. To explain what I mean:
$x in {0, 50, 100}$ can be equivalently replaced by $x' in {0, 1, 2}$ and then $x = 50 times x'$ in all constraints and objective function.
But if the general form of decision variable's set is not like the example that you mentioned, this approach won't work. Comment on this solution if my assumption is not correct.
$endgroup$
1
$begingroup$
Brilliant answer if the values are the same as in my example. What if I had values such as $x in {0,2,5,11}$ that are not succeeding one another?
$endgroup$
– Georgios
8 hours ago
$begingroup$
@Georgios One option is to create three binary DVs: x_gt_0, x_gt_2, x_gt_5, constrained s.t. x_gt_5 <= x_gt_2 <= x_gt_0, and constrain x = 2*x_gt_0 + (5-2)*x_gt_2 + (11-5)*x_gt_5.
$endgroup$
– Geoffrey Brent
4 hours ago
add a comment
|
$begingroup$
In the case of the example that you provided,(and generally, if you have a pattern in the set of available values for $x$), I am assuming that you have the mentioned pattern in the values of the set, you can define your variable $x$ as the integer and then multiply the value of $x$ by a constant. To explain what I mean:
$x in {0, 50, 100}$ can be equivalently replaced by $x' in {0, 1, 2}$ and then $x = 50 times x'$ in all constraints and objective function.
But if the general form of decision variable's set is not like the example that you mentioned, this approach won't work. Comment on this solution if my assumption is not correct.
$endgroup$
1
$begingroup$
Brilliant answer if the values are the same as in my example. What if I had values such as $x in {0,2,5,11}$ that are not succeeding one another?
$endgroup$
– Georgios
8 hours ago
$begingroup$
@Georgios One option is to create three binary DVs: x_gt_0, x_gt_2, x_gt_5, constrained s.t. x_gt_5 <= x_gt_2 <= x_gt_0, and constrain x = 2*x_gt_0 + (5-2)*x_gt_2 + (11-5)*x_gt_5.
$endgroup$
– Geoffrey Brent
4 hours ago
add a comment
|
$begingroup$
In the case of the example that you provided,(and generally, if you have a pattern in the set of available values for $x$), I am assuming that you have the mentioned pattern in the values of the set, you can define your variable $x$ as the integer and then multiply the value of $x$ by a constant. To explain what I mean:
$x in {0, 50, 100}$ can be equivalently replaced by $x' in {0, 1, 2}$ and then $x = 50 times x'$ in all constraints and objective function.
But if the general form of decision variable's set is not like the example that you mentioned, this approach won't work. Comment on this solution if my assumption is not correct.
$endgroup$
In the case of the example that you provided,(and generally, if you have a pattern in the set of available values for $x$), I am assuming that you have the mentioned pattern in the values of the set, you can define your variable $x$ as the integer and then multiply the value of $x$ by a constant. To explain what I mean:
$x in {0, 50, 100}$ can be equivalently replaced by $x' in {0, 1, 2}$ and then $x = 50 times x'$ in all constraints and objective function.
But if the general form of decision variable's set is not like the example that you mentioned, this approach won't work. Comment on this solution if my assumption is not correct.
answered 8 hours ago
Oguz ToragayOguz Toragay
3,5771 gold badge3 silver badges30 bronze badges
3,5771 gold badge3 silver badges30 bronze badges
1
$begingroup$
Brilliant answer if the values are the same as in my example. What if I had values such as $x in {0,2,5,11}$ that are not succeeding one another?
$endgroup$
– Georgios
8 hours ago
$begingroup$
@Georgios One option is to create three binary DVs: x_gt_0, x_gt_2, x_gt_5, constrained s.t. x_gt_5 <= x_gt_2 <= x_gt_0, and constrain x = 2*x_gt_0 + (5-2)*x_gt_2 + (11-5)*x_gt_5.
$endgroup$
– Geoffrey Brent
4 hours ago
add a comment
|
1
$begingroup$
Brilliant answer if the values are the same as in my example. What if I had values such as $x in {0,2,5,11}$ that are not succeeding one another?
$endgroup$
– Georgios
8 hours ago
$begingroup$
@Georgios One option is to create three binary DVs: x_gt_0, x_gt_2, x_gt_5, constrained s.t. x_gt_5 <= x_gt_2 <= x_gt_0, and constrain x = 2*x_gt_0 + (5-2)*x_gt_2 + (11-5)*x_gt_5.
$endgroup$
– Geoffrey Brent
4 hours ago
1
1
$begingroup$
Brilliant answer if the values are the same as in my example. What if I had values such as $x in {0,2,5,11}$ that are not succeeding one another?
$endgroup$
– Georgios
8 hours ago
$begingroup$
Brilliant answer if the values are the same as in my example. What if I had values such as $x in {0,2,5,11}$ that are not succeeding one another?
$endgroup$
– Georgios
8 hours ago
$begingroup$
@Georgios One option is to create three binary DVs: x_gt_0, x_gt_2, x_gt_5, constrained s.t. x_gt_5 <= x_gt_2 <= x_gt_0, and constrain x = 2*x_gt_0 + (5-2)*x_gt_2 + (11-5)*x_gt_5.
$endgroup$
– Geoffrey Brent
4 hours ago
$begingroup$
@Georgios One option is to create three binary DVs: x_gt_0, x_gt_2, x_gt_5, constrained s.t. x_gt_5 <= x_gt_2 <= x_gt_0, and constrain x = 2*x_gt_0 + (5-2)*x_gt_2 + (11-5)*x_gt_5.
$endgroup$
– Geoffrey Brent
4 hours ago
add a comment
|
Thanks for contributing an answer to Operations Research Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2for.stackexchange.com%2fquestions%2f2659%2fdecision-variable-value-from-a-set-gurobi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
I removed the tag or-tools because this question is not about OR Tools, Google's OR solver. If I was wrong to do so, please add it back, along with clarification in the question. Thanks!
$endgroup$
– LarrySnyder610♦
3 hours ago