1
$\begingroup$

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.

\begin{equation} \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} \end{equation}

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

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

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.

$\endgroup$
7
  • $\begingroup$ 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. $\endgroup$ Commented Jan 3, 2023 at 1:22
  • $\begingroup$ @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. $\endgroup$
    – Hernan19
    Commented Jan 3, 2023 at 1:49
  • $\begingroup$ @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. $\endgroup$
    – Hernan19
    Commented Jan 3, 2023 at 1:59
  • $\begingroup$ 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. $\endgroup$ Commented Jan 3, 2023 at 2:47
  • $\begingroup$ @Hernan19, you defined $D$ as a binary variable while its results would be a float number. Are you sure it is correct? $\endgroup$
    – A.Omidi
    Commented Jan 3, 2023 at 11:34

1 Answer 1

1
$\begingroup$

What about:
$ \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)
   
model.addGenConstrIndicator(delta[2],1,z[u,u]+z[vv]==2)
            
model.addGenConstrIndicator(delta[3],1,z[u,v]+z[v,u]==1)
        
model.addConstr(delta.sum()==1)
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.