List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] Simplex Bug (?)
| [MUG] Simplex Bug (?) |
|
Author: PierLuigi Zezza
Posted: Sun, 13 Oct 2002 22:31:18 +0200
|
>> From: PierLuigi Zezza "pzezza"
In the description of many commands of the simplex package one of the input
is a set or list of equations (the constraints). The use of a list of
equation can lead easily to wrong results as it is shown by the following
trivial example
> restart: with(simplex):
Warning, new definition for maximize
Warning, new definition for minimize
Constraints
> cnsts:={2*x[2]- x[3]<=3,x[1]-3*x[2]- x[3]<=2,x[1]+3*x[2]+x[3]<=5};
cnsts := {2 x[2] - x[3] <= 3, x[1] - 3 x[2] - x[3] <= 2,
x[1] + 3 x[2] + x[3] <= 5}
Objective function
> ob:=x[1]-3*x[2]+3*x[3];
ob := x[1] - 3 x[2] + 3 x[3]
Slack variables
> eqs:=setup(cnsts);
eqs := {_SL1 = 3 - 2 x[2] + x[3], _SL2 = 2 - x[1] + 3 x[2] + x[3],
_SL3 = 5 - x[1] - 3 x[2] - x[3]}
The pivot variable
> pivotvar(ob);
x[3]
THE RATIO TEST
> ratio(eqs,%);
{infinity, 5}
Since two of ratios are infinity we obtain a set of TWO elements (The pivot
equation should be the third and it will never be the one !!!)
> pivoteqn(eqs,%%);
[_SL2 = 2 - x[1] + 3 x[2] + x[3]]
> eqs:=pivot(eqs,pivotvar(ob),pivoteqn(eqs,pivotvar(ob)));
eqs := {x[3] = -2 + x[1] - 3 x[2] + _SL2,
_SL1 = 1 - 5 x[2] + x[1] + _SL2, _SL3 = 7 - 2 x[1] - _SL2}
> basis(%)=cterm(%);
{x[3], _SL1, _SL3} = {1, -2, 7}
and we end up with negative values !!!
gigi zezza
PierLuigi Zezza
"pzezza"
|
| [MUG] Re: Simplex Bug (?) |
|
Author: Robert Israel
Posted: Thu, 17 Oct 2002 15:33:51 -0700
|
>> From: Robert Israel "israel"
On the contrary, the problem comes from the use of a _set_ of equations
rather than a list. Since the ordering of elements of a set is arbitrary,
and duplicate entries are removed, it does not really make much sense to
use this on a set.
The description in the help page ?simplex,ratio is incorrect:
-------------
simplex[ratio] - return a list of ratios
...
C - set of linear equations
...
The call ratio(C, x) returns a list of ratios
...
-------------
It should say that C is a list or set of ratios, and ratio(C,x) returns
a list or set (whichever type is C). And there should probably be a
warning that if you use a set the results should not be expected to
be in the same order as the constraints. Since there may be some
rare cases where you would want to use this on a set (where you aren't
going to rely on the order of the results), I hesitate to say that
the use of a set here should be an error. But probably it should at
least result in a warning.
Robert Israel "israel"
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia
Vancouver, BC, Canada V6T 1Z2
On Sun, 13 Oct 2002, PierLuigi Zezza wrote:
> In the description of many commands of the simplex package one of the input
> is a set or list of equations (the constraints). The use of a list of
> equation can lead easily to wrong results as it is shown by the following
> trivial example
>
> > restart: with(simplex):
> Warning, new definition for maximize
> Warning, new definition for minimize
> Constraints
> > cnsts:={2*x[2]- x[3]<=3,x[1]-3*x[2]- x[3]<=2,x[1]+3*x[2]+x[3]<=5};
>
> cnsts := {2 x[2] - x[3] <= 3, x[1] - 3 x[2] - x[3] <= 2,
>
> x[1] + 3 x[2] + x[3] <= 5}
>
> Objective function
> > ob:=x[1]-3*x[2]+3*x[3];
>
> ob := x[1] - 3 x[2] + 3 x[3]
>
> Slack variables
> > eqs:=setup(cnsts);
>
> eqs := {_SL1 = 3 - 2 x[2] + x[3], _SL2 = 2 - x[1] + 3 x[2] + x[3],
>
> _SL3 = 5 - x[1] - 3 x[2] - x[3]}
>
> The pivot variable
> > pivotvar(ob);
>
> x[3]
>
> THE RATIO TEST
> > ratio(eqs,%);
>
> {infinity, 5}
>
> Since two of ratios are infinity we obtain a set of TWO elements (The pivot
> equation should be the third and it will never be the one !!!)
> > pivoteqn(eqs,%%);
>
> [_SL2 = 2 - x[1] + 3 x[2] + x[3]]
>
> > eqs:=pivot(eqs,pivotvar(ob),pivoteqn(eqs,pivotvar(ob)));
>
> eqs := {x[3] = -2 + x[1] - 3 x[2] + _SL2,
>
> _SL1 = 1 - 5 x[2] + x[1] + _SL2, _SL3 = 7 - 2 x[1] - _SL2}
>
> > basis(%)=cterm(%);
>
> {x[3], _SL1, _SL3} = {1, -2, 7}
>
> and we end up with negative values !!!
> gigi zezza
>
>
> PierLuigi Zezza
> "pzezza"
>
>
|
Previous by date: [MUG] Problem with inequal, Dean Bernsten
Next by date: [MUG] convert question, Carl Eberhart
Previous thread: [MUG] Symbol display problem, Maple
Next thread: [MUG] convert question, Carl Eberhart
|