Re: Problem with Maximize and conditions.
- To: mathgroup at smc.vnet.net
- Subject: [mg51064] Re: Problem with Maximize and conditions.
- From: "Curt Fischer" <crf3 at po.cwru.edu>
- Date: Sun, 3 Oct 2004 05:47:35 -0400 (EDT)
- References: <cjlna7$q7f$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Nacho wrote:
> Hello.
>
> I was trying to solve a problem with Mathematica 5 and I am getting
> strange results.
>
> The problem is:
>
> Minimize x+y+z, with the condition that 1/20x+y+5z==100 and x,y,z are
> Integers between 1 and 98 (inclusive).
>
> So I use:
>
> Minimize[{x+y+z, 1/20 x+y+5z\[Equal]100, x \[Element] Integers,
> y \[Element] Integers, z\[Element]Integers, 0<x<99,0<y<99,0<z<99},
> {x,y,
> z}]
>
> I have copied the text using "Plain text" option, I hope it's fine.
>
> This returns the same expression, I suppose that Mathematica cannot
> resolve it. So I use NMinimize:
>
> NMinimize[{x+y+z, 1/20 x+y+5z\[Equal]100, x \[Element] Integers,
> y \[Element] Integers, z\[Element]Integers, 0<x<99,0<y<99,0<z<99},
> {x,y,
> z}]
>
> Now I get a result, but rather weird...
>
> \!\({25.`, {x -> 1, y -> 5, z -> 1899\/100}}\)
>
> The minimum of x+y+z is 25 but z is 1899/100
> 1899/100 is not a Integers, and the nearest Integer, 19, doesn't
> satisfy 1/20x+y+5z==100, and also x+y+z is not 25 but 24.99
>
> I don't know why Mathematica has returned a Real when I specified an
> Integers. I suppose that it is related to the use of NMinimize. I
> suppose that it considers that 18.99 is so near of 19 that it can be
> considered an Integer.
>
> If you remove the condition of z being an Integer, the result changes,
> so it is affecting. Also, if you ask for "1899/100 e Integers" it
> returns False.
>
> So, does anybody know how to solve this? Ideally, I would like to know
> why Minimize doesn't work (so I have to use NMinimize), but in any
> case, how to solve the problem.
I don't know why Minimize[] and NMinimize[] are not working but the problem
is small enough that an exhaustive search can find the answer easily.
In[1]:=
constraintmatrix=
Table[Table[Table[x/20 + y + 5z,{z,1,98}],{y,1,98}],{x,1,98}];
In[2]:=
feasiblespace=Position[constraintmatrix,100];
In[3]:=
cost=Apply[Plus,feasiblespace,{1}];
In[4]:=
feasiblespace[[#]]&/@Position[cost,Min[cost]]
Out[4]=
{{{20,4,19}}}
Therefore, the optimal values for {x,y,z} is {20,4,19} and the minimal cost
x+y+z is thus 43. The answer NMinimize was giving did not satisfy the
integer constraints. In fact, because y and z must be integers, and x/20 +
y + 5z must sum to an integer, we can tell right away that x must be a
multiple of 20.
--
Curt Fischer