1
$\begingroup$

I have the following problem in Gurobi (Java).

I have a binary variable $b$ that is supposed to be $1$ or $0$ depending on my optimisation variable $x$. It should be true that $b = 1$ if $c_1 \le x \le c_2$, otherwise $0$. The values of $c_1$ and $c_2$ are constant.

I wanted to solve the whole thing using a constraint, which then determines my binary variable with the method model.addGenConstrIndicator, but it is still $1$ for values above $c_2$. Maybe someone can help me or has another idea.

Furthermore I have the problem, that even when i don't use the binary variable in my objective function my result and the value of $x$ will be changed by this constraint.

for (int t = 0; t < 3; t++)
    {
        for (int j = 0; j < 5; j++)
        {
                for (int m = 0; m < 12; m++)
                {   
                    constra = new GRBLinExpr();
                    
                    constra.addTerm(1.0, x[m]);
                    
                    model.addGenConstrIndicator(b[t][j][m], 1, constra, GRB.GREATER_EQUAL, c1, "is one" + t + j + m);
                    model.addGenConstrIndicator(b[t][j][m], 0, constra, GRB.GREATER_EQUAL, c2, "is zero" + t + j + m);
                }
        }
}
    
$\endgroup$
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.