[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-glpk] fraction with vars
From: |
Michael Hennebry |
Subject: |
Re: [Help-glpk] fraction with vars |
Date: |
Fri, 27 Apr 2012 16:15:16 -0500 (CDT) |
User-agent: |
Alpine 1.00 (DEB 882 2007-12-20) |
On Fri, 27 Apr 2012, glpk xypron wrote:
# Solve
# x = p * y / w
# where x, y, w are natural numbers and
# p = 11 / 17
# x in [23, 100]
# y in [10, 200]
# w in [3, 7]
param eps := 1E-5;
param M := 1000;
param w_min := 3;
param w_max := 7;
param p := 11 / 17;
set I := {w_min..w_max};
var w{I}, binary;
var y, integer, >= 10, <= 200;
var x, integer, >= 23, <= 100;
s.t. ub{i in I} :
x <= p * y / i + M * (1 - w[i]) + eps;
s.t. lb{i in I} :
x >= p * y / i - M * (1 - w[i]) - eps;
s.t. sm :
sum{i in I} w[i] = 1;
solve;
printf "x = %f\ny = %f\nw = %f\n", x, y, sum{i in I} w[i] * i;
end;
Not bad. I'd missed the integer requirement.
If the range is small enough, that simplifies things a bit.
That said, I'd go for all-integer constraints.
That would eliminate the need for eps.
Also, M shouold be as small as possible and therefore
it should not be the same for every big-M constraint.
# Solve
# x = p * y / w
# w * pd * x = pn * y
# where x, y, w are natural numbers and
# p = 11 / 17
# pn = 11
# pd = 17
# x in [23, 100]
# y in [10, 200]
# w in [3, 7]
param w_min := 3;
param w_max := 7;
param pn := 11;
param pd := 17;
set I := {w_min..w_max};
var w{I}, binary;
var y, integer, >= 10, <= 200;
var x, integer, >= 23, <= 100;
s.t. lb{i in I} :
i * pd * x >= pn * y - (1-w[i]) * (pn*200-i*pd*23);
s.t. ub{i in I} :
i * pd * x <= pn * y + (1-w[i]) * (i*pd*100-pn*10);
s.t. sm :
sum{i in I} w[i] = 1;
solve;
printf "x = %f\ny = %f\nw = %f\n", x, y, sum{i in I} w[i] * i;
end;
-------- Original-Nachricht --------
Datum: Fri, 27 Apr 2012 09:57:10 +0200
Von: Kasper Tordrup <address@hidden>
An: help-glpk <address@hidden>
Betreff: [Help-glpk] fraction with vars
Hi guys
I have a problem with calculating a fraction, the reason is that both the
nominator and denominator are variables.
So I am looking for some way to make this linear:
x_suj = p_s * (y_suj/w_su) or well just find what this fraction is:
y_suj/w_su
where p_s is a constant, x,y and w are integer variables. and I also need
to avoid the division with 0 problem.
Anyone know some tips/tricks for this?
Regards,
Kasper
--
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
_______________________________________________
Help-glpk mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-glpk
--
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