Three state variable

Take a read of Please read: make it easier to help you.

In particular, take the time to make a minimal working example (i.e., code that we can copy-and-paste) that demonstrates what you are trying to achieve and why.

If vector1 and vector2 are vectors, but x1 and x2 are scalars, the result is a vector, so computing the sign doesn’t make sense.

If your model is linear, you can use a MILP reformulation:

model = Model()
L, U = -100, 100
@variable(model, L <= x <= U)
@variable(model, y, Bin)
@constraint(model, x <= U * y)
@constraint(model, x >= L * (1 - y))
@expression(model, sgn, 2 * y - 1)

If your model is nonlinear, you may be better off with a smooth approximation:
https://math.stackexchange.com/questions/1264681/how-to-smoothly-approximate-a-sign-function

1 Like