- rewrite your code to use the tools of the Global Optimization Toolbox, several of which do not require continuous first derivatives; or
- 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.
how can I compare two optimization variables before running the model?
4 views (last 30 days)
Show older comments
Sohrab Abedini
on 17 May 2018
Answered: Walter Roberson
on 18 May 2018
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
0 Comments
Accepted Answer
Walter Roberson
on 18 May 2018
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:
0 Comments
More Answers (0)
See Also
Categories
Find more on Problem-Based Optimization Setup in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!