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.

回答(2 个)

Torsten
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)
Local minimum possible. Constraints satisfied. fgoalattain stopped because the size of the current search direction is less than twice the value of the step size tolerance and constraints are satisfied to within the value of the constraint tolerance.
x = 1×5
1.0e+03 * 3.0000 1.8302 0.0691 0.0350 0.0220

John D'Errico
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)
Index exceeds the number of array elements. Index must not exceed 4.

Error in solution>@(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)] (line 1)
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)];
Now, why might that fail? Your objective is a function of FIVE unkowns. Yet you gave it only 4 starting values.
  1 个评论
Ezra
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 CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by