On Apr 6, 8:27 pm, "minb...@gmail.com"
> Suppose there is a continuous variable X (it can be negative) and two
> constants a and b, and I want to define a variable Y and let Y equal
> to a*X(if X>=0) or b*X(if X<0),how can I define such constraint in
> linear way?
It depends on whether you are minimizing or maximizing. You want the
function f(X) = a*X if X >= 0 and f(X) = b*X if X < 0. Write f(X) =
c*X + e*|X|, and figure out what c and e must be to get your desired
f(.). Now the question becomes: can you represent |X| in a linear way?
The standard way is to write X = Xp - Xn, where Xp, Xn >=0, and to
write |X| = Xp + Xn. This will be OK if we have at most one of Xp or
Xn positive, which will be true of the optimal solution to a linear
problem involving minimization of f(X) in the case that e > 0.
However, it will not be true of maximizing solutions (or minimizing
solutions when e < 0), in which case you need to impose the extra
constraint Xp*Xn = 0. This can be done by introducing a binary
variable, so you get a mixed integer problem.
R.G. Vickson