I have a nonlinear discrete minimization problem, where x(j,k) is a binary variable (1 if the condition holds, 0 otherwise). I need to find x(j,k) for all j and k in a way that the objective value is minimized. I used symbolic variables to represent the x(j,k) by using a genetic algorithm. but after I run my code I get this error: _"Not enough input arguments.
Error in symengine>@(x11,x12,x21,x22)"_ Here is my code in the attached file:
P = [24 6;8 8];n = size(P,2);x = cell(n, n);for k = 1:n for j = 1:n x{k,j} = sprintf('x%d%d',j,k); % decision variable if job j is assigned to position k x(j,k) = 1
% otherwise 0
endendx = x(:); % now x is a n^2-by-1 vector
x = sym(x, 'integer');J = 0;for j = 1:n for k = 1:n W(j,k) = P(1,j) * x(J + k,1) ;% processing time of the job in position k
end J = J + n;endW1 = sum(W);C_1_k(1,1) = W1(1,1); % completion time of position 1 on machine 1
for k = 2:nC_1_k(1,k) = W1(1,k) + (C_1_k(1,k-1)); % completion time of position k > 1 on machine 1
endSumC1 = sum(C_1_k);J = 0;for j = 1:n WW(j,1) = (P(1,j) + P(2,j)) * x(J+j,1); % completion time of the first position on machine 2 %k=1
J = J + n-1;endC_2_k(1,1) = sum(WW); %x(kj)
for k = 2:n K = 0; MAX_function = 0.5*(C_1_k(1,k) + C_2_k(1,k-1) + abs(C_1_k(1,k) - C_2_k(1,k-1))); %max function does not work with symbolic variables I wrote simple equivalent
for j = 1:n W_2_k(j,1) = (x(K+k,1) * P(2,j)); K = K + n; end C_2_k(1,k) = MAX_function + sum(W_2_k,1); %Completion time job in position k on machine 2
end Fun_C_2_k = matlabFunction(C_2_k);SumC = sum(C_2_k);Fun_SumC = matlabFunction(SumC); % to form optimization settings
A = zeros(n,n^2); B = zeros(n,n^2); K = 0; for j = 1:n for k = 1:n A(j,K+k) = 1; end K = K+n; end for j = 1:n K = j -1; for k = 1:n B(j,K+k) = 1; K = K+n-1; end end Aeq = [A;B]; %LHS of equality constriants
beq = ones(2*n,1); %RHS of equality constriants
%Aeq*x = beq EQUALITY constraints
LB = zeros(n,n);%lower bonud for x, since x is a binary variable the lower bound is zero
LB = LB(:); UB = ones(n,n); %Upper bonud for x, since x is a binary variable the upper bound is one
UB = UB(:); nvars = n^2;% for i = 1:nvars
% IntCon(i,1) = i;
% end
[x, fval] = ga(Fun_SumC,nvars,[],[],Aeq,beq,LB,UB);
Best Answer