How to get the optimum answer for this problem?

I solved the following problem using linprog and got optimum results,
A= [-(1/0.07) 0 0 0 0 1;
0 -(1/0.45) 0 0 0 1;
0 0 -(1/0.37) 0 0 1;
0 0 0 -(1/0.88) 0 1;
0 0 0 0 -(1/0.38) 1;
1 1 1 1 1 0];
b=[0;0;0;0;0;30];
lb=[0;0;0;0;0;0];
ub=[30;30;30;30;30;30];
f=-[0;0;0;0;0;1];
[x_1]=linprog(f,A,b,[],[],lb,ub)
but for the want of integer results I’l have to solve it using genetic algorithm. I tried the following code,
A= [-(1/0.07) 0 0 0 0 1; 0 -(1/0.45) 0 0 0 1; 0 0 -(1/0.37) 0 0 1;...
0 0 0 -(1/0.88) 0 1; 0 0 0 0 -(1/0.38) 1; 1 1 1 1 1 0];
b=[0;0;0;0;0;30];
lb=[0;0;0;0;0;0];
ub=[30;30;30;30;30;30];
IntCon=[1 2 3 4 5];
opts = gaoptimset('StallGenLimit',1000,'TolFun',1e-10,...
'Generations',500,'PlotFcns',@gaplotbestf);
[x] = ga(@data,6,A,b,[],[],lb,ub,[],IntCon,opts)
(function declaration in a separate file)
function scores = data(f)
f=[0;0;0;0;0;1];
scores = max(f);
but could not get an optimum result. Don’t know where I’ve gone wrong. Please help solving this one. Thank you

 Accepted Answer

Your fitness function data() always returns a constant value because you overwrite the input f with
f=[0;0;0;0;0;1];
Obviously, therefore, it cannot be meaningfully optimized.
In any case, you could solve the whole problem by exhaustive search. There are only 31465 combinations of integers between 0 and 30 that satisfy your constraint
sum(x(1:5))<=30

4 Comments

There are also other ways you could break down the problem. Note that once x(6) is specified, the remaining constraints reduce to simple bound constraints on x(1:5). The minimization problem then reduces to a Knapsack Problem
which can be solved efficiently using dynamic programming. You could therefore loop over all possible values of x(6) and solve each sub-problem pretty quickly.
Though it wouldn't be a problem to loop over x(6) from 0 to 30, you can actually show that 0<=x(6)<=13. This is because your first five inequality constraints can be rewritten
x(1)>=x(6)*0.07;
x(2)>=x(6)*0.45;
x(3)>=x(6)*0.37;
x(4)>=x(6)*0.88;
x(5)>=x(6)*0.38;
Summing these inequalities and combining with sum(x(1:5))<=30 leads to
2.5 x(6) <= sum(x(1:5)) <=30
which cannot be satisfied for x(6)>13
Thank you for your suggestion, but the constraint should be,
sum(x(1:5))=30
I have been directed to solve this using GA only, Can you please tell me what would be the fitness function to get the following results which I got using linprog, only for the first five rows to be integers while being run in GA.
x_1 =
0.9767
6.2791
5.1628
12.2791
5.3023
13.9535
Thank you for your suggestion, but the constraint should be, sum(x(1:5))=30
Then you should fix your posted code. It shows this as an inequality constraint. My remarks about exhaustive search remain unchanged, though, because I had equality in mind when I said there are 32465 combinations.
Can you please tell me what would be the fitness function to get the following results which I got using linprog,
function scores = data(x)
f=-[0;0;0;0;0;1];
scores = dot(f,x);
Fantastic.... I have got the answer... You are a genius. Thank you very much

Sign in to comment.

More Answers (0)

Asked:

on 9 Jun 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!