How to write this logical expression with Gurobi + Java, or express it as a big-m formulation

I am trying to write the following expression in Gurobi+Java or Gurobi+python, if it is more practical It could be expressed as a big-M formulation.

$$$$\label{const4} \text{D}_{uv} = \begin{cases} \quad 0 & \quad \text{if } \quad Z_{uv}+Z_{vu} = 1\\ \quad 0.3 & \quad \text{if } \quad Z_{uu}+Z_{vv} = 2 \\ \quad 0.7 & \quad \text{if } \quad P_{u}= 1 \\ \end{cases}$$$$

the variable $$D_{uv}$$ is used in a minimization objective function, where $$C_{uv}$$ is the parameter cost. I want to update the value for the variable $$D_{uv}$$, according to the behaviour of variable $$Z_{uv}$$ and $$P_{u}$$.

$$$$f_{min}= \sum_{(u,v) \in P(i,j)} C_{uv} (\text{D}_{uv})$$$$

I used the method GRBModel.AddGenConstrIndicator() (Gurobi+Java), but, when any of the conditions are fulfilled I do not see any changes in the value for variable $$D_{uv}$$, it does not change at all.

I want to express these conditional statements using the indicator constraints by gurobi, if it is not possible, I would like to use a big-M formulation. I have tried to express the conditional statements as big-M formulations without success.

• What exactly is relation between UB and $Z_{u,v}$? Because if $D_{u,v}$ can only take values in $\{0.5,0.9\}$, then UB will remain 1. Commented Jan 3, 2023 at 1:22
• @RobPratt If non of the condition holds, the value for $D_{uv}$ is going to be zero. And I think the subscipts are ok, I checked the LP file and I changed manually the values for the UB. Thanks. Commented Jan 3, 2023 at 1:49
• @Sutanu UB is the value for the upper bound of variable $D_{UV}$. $D_{UV}$ is a discount factor than can take value of 0.5 when $Z_{uv}$ + $Z_{vu}$=1, 0.9 when $Z_{uu}$ + $Z_{vv}$=2, or 0 when non of those conditions are achieved. The value for $Z$ variable is subject to other constraints. I solved the current formulation, and I saw that some of these conditions are achieved, but the value for $D_{uv}$ remains equal to 1. Thank you. Commented Jan 3, 2023 at 1:59
• Try making UB as a variable. Add constraint $D_{u,v} \le UB$, remove UB as upper bound while creating D and also add any relation of UB with Z as a constraint. Commented Jan 3, 2023 at 2:47
• @Hernan19, you defined $D$ as a binary variable while its results would be a float number. Are you sure it is correct? Commented Jan 3, 2023 at 11:34

$$\delta_1,\delta_2$$ binary

$$D_{uv} = 0.3\delta_1 + 0.7\delta_2$$

$$1-z_{min}(1 - \delta_3) \le z_{uv}+z_{vu}\le 1+z_{max}(1-\delta_3)$$

$$2 - z_{min}(1-\delta_2) \le z_{uu}+z_{vv}\le 2 + z_{max}(1-\delta_2)$$

$$1-z_{min}(1-\delta_1) \le z_{uu} \le 1 + z_{max}(1-\delta_1)$$

$$\delta_1+\delta_2 +\delta_3 = 1$$

If using indicator variable for Gurobi,

model.addGenConstrIndicator(delta[1],1,z[u,u]==1)