[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-glpk] function
From: |
Michael Hennebry |
Subject: |
Re: [Help-glpk] function |
Date: |
Fri, 17 Aug 2012 10:32:53 -0500 (CDT) |
User-agent: |
Alpine 1.00 (DEB 882 2007-12-20) |
On Fri, 17 Aug 2012, Mate Hegyhati wrote:
Hi Zvonko,
maybe something like this?
R >= 0
R <= P - PMIN*X
R <= PMAX*X - P
This fails for X=0.
R >= 0
PMAX >= P >= 0 // might be redundant
if X==1 P >= PMIN // might be redundant
if X==1 R <= P - PMIN
if X==1 R <= PMAX - P
if X==0 P <= 0
if X==0 R <= 0
Add binary Y
if Y==0 R >= PMAX - P
if Y==1 R >= P - PMIN
Note that if X==0 then Y==1.
It won't hurt to put it in explicitly:
Y >= 1-X // might be redundant
Use small M for the conditional constraints, e.g.:
if Y==1 R >= P - PMIN
R >= P - PMIN - M*(1-Y)
This is correct for Y==1 or M big enough.
Make M as small as possible and still big enough.
Since it works for Y==1 assume Y==0 and X==1:
R >= P - PMIN - M
M >= P - PMIN - R <= PMAX - PMIN - 0
Any M >= PMAX - PMIN is valid
Use PMAX - PMIN
Simply picking a huge M is the wrong way to go.
It generates notoriously loose linear constraints
and causes numerical problems.
R >= P - PMIN - (PMAX - PMIN)*(1-Y)
R >= P + (PMAX-PMIN)*Y - PMAX
As Mate Hegyhati noted, you do not necesarily
need Y and the constraints that involve it.
If, for example,
one is minimizing a functions that only has one local minimum,
one does not need upper bounds on the function.
This should be enough, if R is not represented anywhere else, and it
should be as much as possible in the objective.
Otherwise I think You need an additional binary variable, Y,
representing whether P is closer to PMIN or to PMAX.
P <= (PMIN + PMAX) / 2 + (1-Y) * (PMAX-PMIN)/2
P >= (PMIN + PMAX) / 2 - (1-Y) * (PMAX-PMIN)/2
And then You can add these to the above constraints:
R >= P - PMIN - Y * PMAX
R >= PMAX - P - (1-Y)*PMAX
Hope this is what You are looking for, best regards,
Mate
On 08/17/2012 10:02 AM, Zvonko Bregar wrote:
Hi,
My name is Zvonko Bregar.
Please help me with the following problem.
There is a real variable P having disjunct definition area {0} + [PMIN, PMAX].
There is also a binary variable X helping in this definition.
If X = 0 then P = 0
And if X = 1 then PMIN < P < PMAX.
So variables X an P work simultaneously.
This should be a rather standard construction.
The question is to construct another variable, say R, from X an P
Such that
If X = P = 0 then also R = 0
Else R = min {P-PMIN,PMAX-P}
In other words, R measures the minimal distance of P to its boundaries PMIN and
PMAX.
But if P = 0 then R must be set to 0 too.
For example, if PMIN = 200 and PMAX = 400, than the required function should be something
like the "upside down" absolute value function:
R = - | P - 300 | + 100 if 200 < P < 400
But also R = 0 if P = 0.
--
Michael address@hidden
"On Monday, I'm gonna have to tell my kindergarten class,
whom I teach not to run with scissors,
that my fiance ran me through with a broadsword." -- Lily