How to get the optimum answer for this problem?

2 Ansichten (letzte 30 Tage)
Nirmal
Nirmal am 9 Jun. 2013
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

Akzeptierte Antwort

Matt J
Matt J am 9 Jun. 2013
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 Kommentare
Matt J
Matt J am 9 Jun. 2013
Bearbeitet: Matt J am 9 Jun. 2013
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);
Nirmal
Nirmal am 9 Jun. 2013
Fantastic.... I have got the answer... You are a genius. Thank you very much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by