how can I compare two optimization variables before running the model?

4 ビュー (過去 30 日間)
Sohrab Abedini
Sohrab Abedini 2018 年 5 月 17 日
回答済み: Walter Roberson 2018 年 5 月 18 日
Hi guys I am using matlab 2018B with optimization toolbox. Can any one help me with this error "Error using max Invalid data type. First argument must be numeric or logical.
Error in int_TCT (line 38)" C_k_2{j,k} = max(C_1_k(1,k),C_k_2(j,k-1)) + (x(j,k) * P(2,j));" on the following code and how to overcome:
P = [24 6 7 9 24 12 11; 8,8,21,16,9,6,17];
n = size(P,2);
prob = optimproblem('ObjectiveSense','min'); %to define the maximization function
x = optimvar('x',[n,n],'LowerBound',0,'UpperBound',1,'Type','integer');
SumToOne_row = sum(x,2) == 1; % Eqation(18): sum(z_jk=1, for all k
prob.Constraints.row = SumToOne_row;
SumToOne_col = sum(x,1) == 1; % Eqation(18): sum(z_jk=1, for all j
prob.Constraints.col = SumToOne_col;
for j = 1:n
for k = 1:n
W(j,k) = P(1,j) * x(j,k) ;% processing time of the job in position k
end
end
W1 = sum(W);
C_1_k(1,1) = W1(1,1); % completion time of position 1 on machine 1
for k = 2:n
C_1_k(1,k) = W1(1,k) + (C_1_k(1,k-1)); % completion time of position k > 1 on machine 1
end
for j = 1:n
C_k_2(j,1) = (P(1,j) + P(2,j)) * x(j,1); % completion time of the first position on machine 2 %k=1
end
for k = 2:n
for j = 1:n
C_k_2{j,k} = max(C_1_k(1,k),C_k_2(j,k-1)) + (x(j,k) * P(2,j));
end
end

採用された回答

Walter Roberson
Walter Roberson 2018 年 5 月 18 日
You cannot do that.
optimproblem() is only for use with the Optimization Toolbox, and all of the optimizers for the Optimization Toolbox are restricted to problems that have continuous first derivatives. Taking max() does not have a continuous first derivative, so none of the tools in the Optimization Toolbox can be used for your optimization problem.
You have two choices:
  1. rewrite your code to use the tools of the Global Optimization Toolbox, several of which do not require continuous first derivatives; or
  2. break your problem up into pieces along the boundary where one or the other of the choices becomes the maximum, and optimize each of the pieces separately and then choose the optimal of all of the fragments.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProblem-Based Optimization Setup についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by