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

How to transcribe an arpeggiated 4-note chord to be playable on a violin?

As a team leader is it appropriate to bring in fundraiser candy?

Decision Variable Value from a Set (Gurobi)

Are there types of animals that can't make the trip to space? (physiologically)

How dangerous are my worn rims?

Is there a pattern for handling conflicting function parameters?

Giving a good fancy look to a simple table

French license plates

Looking for circuit board material that can be dissolved

Everyone Gets a Window Seat

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 is this situation not a checkmate?

Shell Sort, Insertion Sort, Bubble Sort, Selection Sort Algorithms (Python)

Missing quartile in boxplot

Why does `FindFit` fail so badly in this simple case?

How to find places to store/land a private airplane?

Why does it seem the best way to make a living is to invest in real estate?

How deep is the liquid in a half-full hemisphere?

Why such a singular place for bird watching?

What's the global, general word that stands for "center tone of a song"?

Is there an in-universe explanation of how Frodo's arrival in Valinor was recorded in the Red Book?

How to identify whether a publisher is genuine or not?

Confusion regarding control system of Mars Rover?

Can anyone give me the reason why music is taught this way?



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













4












$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).










share|improve this question











$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















4












$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).










share|improve this question











$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













4












4








4





$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).










share|improve this question











$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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 3 hours ago









LarrySnyder610

6,59215 silver badges67 bronze badges




6,59215 silver badges67 bronze badges










asked 9 hours ago









GeorgiosGeorgios

33313 bronze badges




33313 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
















  • $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










2 Answers
2






active

oldest

votes


















4














$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$)






share|improve this answer









$endgroup$










  • 1




    $begingroup$
    Quite similar to my suggestion. Nevertheless, thanks for a clear answer.
    $endgroup$
    – Georgios
    8 hours ago


















2














$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.






share|improve this answer









$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
    5 hours ago












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
);



);














draft saved

draft discarded
















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









4














$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$)






share|improve this answer









$endgroup$










  • 1




    $begingroup$
    Quite similar to my suggestion. Nevertheless, thanks for a clear answer.
    $endgroup$
    – Georgios
    8 hours ago















4














$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$)






share|improve this answer









$endgroup$










  • 1




    $begingroup$
    Quite similar to my suggestion. Nevertheless, thanks for a clear answer.
    $endgroup$
    – Georgios
    8 hours ago













4














4










4







$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$)






share|improve this answer









$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$)







share|improve this answer












share|improve this answer



share|improve this answer










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












  • 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











2














$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.






share|improve this answer









$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
    5 hours ago















2














$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.






share|improve this answer









$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
    5 hours ago













2














2










2







$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.






share|improve this answer









$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.







share|improve this answer












share|improve this answer



share|improve this answer










answered 8 hours ago









Oguz ToragayOguz Toragay

3,5871 gold badge3 silver badges30 bronze badges




3,5871 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
    5 hours ago












  • 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
    5 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
5 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
5 hours ago


















draft saved

draft discarded















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單