Hello everybody,
I have a study of a suitcase problem.
There is a suitcase which is 20 kg and there is the items with values and utilities, I should put it in it.
set
i item /oliveoil,olive,tomatosauce,jam,meat,butter,honey,cheese/;
parameters
we(i) weight
/oliveoil 4.5
olive 0.5
tomatosauce 3
jam 0.45
meat 1
butter 2
honey 0.75
cheese 2 /,
v(i) value
/oliveoil 188
olive 12.95
tomatosauce 37.50
jam 16.90
meat 120
butter 150
honey 75
cheese 70/,
u(i) utility
/oliveoil 0.0555
olive 0.1388
tomatosauce 0.2222
jam 0.1111
meat 0.1944
butter 0.0833
honey 0.1666
cheese 0.0277/;
scalar W capacity of bag /20/
L limit of utility /0.05/ ;
positive variables
X(i);
free variables
Z aim function ;
equations
aim,
weight,
preference;
aim.. Z =e= sum(i, v(i) *u(i) *X(i));
weight.. sum(i, we(i) *X(i)) =l= W;
preference.. if u(i) =g= L, Z=1 ;
model suitcase /all/;
solve suitcase using MIP maximizing Z;
There is always a problem with if code. Unless I write the if, the code is running but in the solution, I should have put only meat.
Can someone help me what is wrong with my equations and how can I fix it?
Sincerely
Mel
Adding if value
Re: Adding if value
Hi Mel
A few things:
- You can't use "if" in an equation.
- You write MIP, but there are no integer variables.
- The If-condition is a little weird: If you leave it out, Z is more than 400, so setting it to 1 makes no sense.
Your solution without this if-equation makes sense, as meat gives the highest value * weight * utility for a suitcase with a weight less than 20.
You probably need a non-linear utility function to get a more diverse bundle, for example:
and add a constraint on the expenditure (not more than x$).
Cheers
Renger
PS. If you want to add code, please use the "</>" button, so the text is properly formatted.
A few things:
- You can't use "if" in an equation.
- You write MIP, but there are no integer variables.
- The If-condition is a little weird: If you leave it out, Z is more than 400, so setting it to 1 makes no sense.
Your solution without this if-equation makes sense, as meat gives the highest value * weight * utility for a suitcase with a weight less than 20.
You probably need a non-linear utility function to get a more diverse bundle, for example:
Code: Select all
U = sum(i, we(i) ** u(i));
Cheers
Renger
PS. If you want to add code, please use the "</>" button, so the text is properly formatted.
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist