Solving goal programming problem with MATLAB
조회 수: 6 (최근 30일)
이전 댓글 표시
Please, can someone help me chech what is wrong with my code for the problem below:
Question:
Solve the following goal programming problem given below
objective 1 (yield goal)
208*x(1)^0.323168*x(2)^0.172084*x(3)^0.085998*x(4)^0.188794*x(5)^0.229956 >= 6611
objective 2 (budget goal)
2.8*x(1)+22*x(2)+4*x(3)+0.272*x(4)+x(5) <= 492
Objective 3 (Chemical goal)
22*x(2)+4*x(3) <= 212
Objective 4 (Seed goal)
x(4) <= 70
Weights = [0.5 0.17 0.13 0.25]
Solution:
fun = @(x)[208*x(1)^0.323168*x(2)^0.172084*x(3)^0.085998*x(4)^0.188794*x(5)^0.229956;2.8*x(1)+22*x(2)+4*x(3)+0.272*x(4)+x(5);22*x(2)+4*x(3)];
goal = [6611,492,212,70];
weight = [0.5,0.17,0.13, 0.25];
x0 = [3000,2000,100,35];
x = fgoalattain(fun,x0,goal,weight)
Error Message:
Index exceeds matrix dimensions.
Error in
@(x)[208*x(1)^0.323168*x(2)^0.172084*x(3)^0.085998*x(4)^0.188794*x(5)^0.229956;2.8*x(1)+22*x(2)+4*x(3)+0.272*x(4)+x(5);22*x(2)+4*x(3)]
Error in goalcon (line 64)
f = feval(funfcn{3},x,varargin{:});
Error in fgoalattain (line 406)
[ctmp,ceqtmp] = feval(cfun{3},xnew,extravarargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. Optimization cannot continue.
댓글 수: 0
답변 (2개)
Torsten
2024년 2월 15일
편집: Torsten
2024년 2월 15일
x0 must be a vector of size 1x5, not 1x4.
Further, your function must return a vector of length 4, not 3.
Further, the first objective must be multiplied by (-1) in order to get <= instead of >=.
fun = @(x)[-208*x(1)^0.323168*x(2)^0.172084*x(3)^0.085998*x(4)^0.188794*x(5)^0.229956;2.8*x(1)+22*x(2)+4*x(3)+0.272*x(4)+x(5);22*x(2)+4*x(3);x(4)];
goal = [-6611,492,212,70];
weight = [0.5,0.17,0.13, 0.25];
x0 = [3000,2000,100,35,22];
x = fgoalattain(fun,x0,goal,weight)
댓글 수: 0
John D'Errico
2024년 2월 15일
편집: John D'Errico
2024년 2월 15일
READ THE ERROR MESSAGE! What did it say?
"Failure in initial user-supplied objective function evaluation. Optimization cannot continue."
Surely that was returned for a reason. Here was your code:
fun = @(x) [208*x(1)^0.323168*x(2)^0.172084*x(3)^0.085998*x(4)^0.188794*x(5)^0.229956;2.8*x(1)+22*x(2)+4*x(3)+0.272*x(4)+x(5);22*x(2)+4*x(3)];
x0 = [3000,2000,100,35];
Now, a thing I always strongly suggest when someone uses an optimizer, is to test to see if the objective function even works.
fun(x0)
Now, why might that fail? Your objective is a function of FIVE unkowns. Yet you gave it only 4 starting values.
댓글 수: 1
Ezra
2024년 2월 15일
Thank you all for your observations, comments and solutions. I would take time to go over them and do all the necessary amendment.
Merci beaucoup
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!