# How to introduce an optional decision variable

I try to model a decision process in which I first need to decide about a binary variable $$x$$. In case $$x=1$$, I also need to decide upon variable $$y$$ and the value of $$y$$ is not defined otherwise. Especially, I do not know how to correctly introduce constraints. Assume that I want to model a constraint that states that $$y$$ needs to be greater than 5. Of course I could then just state: $$$$\label{eq:cap} y > 5$$$$ But this would suggest that $$y$$ has a defined value, which does not need to be the case (if $$x = 0$$).

Is there a standard way how to introduce such a variable and associated constraints (e.g. in an IP or MDP)?

• The answer will depend on whether $y$ appears in the objective function and how it appears in the constraints. Basically, there are two possibilities for when $x=0$: either you do not care what value $y$ takes, or you need it to take a specific value (most likely 0, possibly 1 if it multiplies other variables) that would be the algebraic equivalent of omitting it from the constraints. So we need more detail about how $y$ is used in the model.
– prubin
Jan 19, 2022 at 17:35
• You could add $y\ge 5 x$. This way, if $x=1$, you have $y\ge 5$, but if $x=0$, $y$ can take any non negative value. I agree with @prubin, more detail is needed to provide a complete answer though. Jan 20, 2022 at 9:38
• Thank you for your answers @prubin. I cannot just set the value of y to 0, because it corresponds to a geographical position and appears in the objective function. Any value of y would lead to costs > 0. A solution would be (similar to the suggestion of @Kuifje) to multiply the term in the objective function by x, so that the value of y only matters if x=1. But I was wondering if there is another standard way of introducing such a relationship mathematically. Jan 20, 2022 at 17:43
• The usual approaches to that would basically amount to doing what you suggest (multiplying the cost term by $x$) and then linearizing it.
– prubin
Jan 20, 2022 at 18:58

Optional decision variables are part of the building block of scheduling within CPLEX CPOptimizer.

For instance

using CP;

dvar interval s size 1;
dvar interval e size 1;
dvar interval itvs optional size 7;

maximize presenceOf(itvs);
subject to
{
startOf(s)==1;
startOf(e)==8;
startBeforeStart(itvs,s);
startBeforeEnd(e,itvs);
}

int isPresent=presenceOf(itvs);
execute
{
writeln("isPresent=",isPresent);
}


gives

isPresent=1


but if I turn

dvar interval itvs optional size 7;


into

dvar interval itvs optional size 5;


then we get

isPresent=0


The constraints on itvs (start and end) are valid as long as the optional interval is present.