Dimension error with genetic algorithm optimization variable
3 views (last 30 days)
Show older comments
Quinten Rademakers
on 1 Mar 2021
Answered: Quinten Rademakers
on 2 Mar 2021
Hello, I am trying to solve a nonlinear constrained integer problem from a paper from Daniels & Carillo (1997) on beta-robust scheduling. I failed to use a BNB method as I couldn't get it to work for a matrix input.

C = jobmeans(:,1); % 10x1 vector
v = jobvars(:,1); % 10x1 vector
Aeq = [ones(length(C),length(C))]; %10x10 matrix
beq = [ones(1,length(C))]; %1x10 vector
lb = zeros(length(C),length(C)); %10x10 matrix
ub = ones(length(C),length(C)); %10x10 matrix
T = 220;
fun = @(x)(-(T-C'*((n(1)+1-[1:n(1)])*x')')/sqrt(v'*((n(1)+1-[1:n(1)]).^2*x')'));
intcon = 100;
x = ga(fun,100,[],[],Aeq,beq,lb,ub,[],intcon);
I want to optimize for a n(1) x n(1) = 10x10 integer matrix. If I define the amount of optimization variables (nvars) to be 100, Matlab states that the number of columns in Aeq (10) is not the same as the length of x0. If I set nvars = 10 without intcon = 10 I only get 1x10 non-integer vector x, and with intcon = 10 I do not get a solution. The output of the 'fun' function for a test matrix of x = rand(10,10) is a scalar result so I'm not sure what the issue could be here.
How can I get the solver to solve for a 10x10 integer matrix?
The Matlab error is
Error using preProcessLinearConstr (line 71)
The number of columns in Aeq must be the same as the length of X0.
Error in gacommon (line 97)
[Iterate.x,Aineq,bineq,Aeq,beq,lb,ub,msg,exitFlag] = preProcessLinearConstr( ...
Error in ga (line 363)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, ...
Error in BRSP (line 78)
x = ga(fun,100,[],[],Aeq,beq,lb,ub,[],100);
0 Comments
Accepted Answer
Alan Weiss
on 1 Mar 2021
In general, if you have an n-by-n matrix of variables x, the linear inequality constraint A*x <= b (and linear equality constraint Aeq*x = beq) operates on x as the column vector x(:). In other words, the number of columns of A or Aeq must be equal to the number of elements in x. Your Aeq matrix needs to have 100 columns.
Also, if you want all 100 variables to be integer-valued, you need to specify
intcon = 1:100; % Not 100
Also, the ga solver expects your variables to be a row vector, not a matrix. This affects your objective function. You might need to reshape x to a matrix before calculating the objective function.
Alan Weiss
MATLAB mathematical toolbox documentation
2 Comments
Alan Weiss
on 1 Mar 2021
Sorry, I don't know. I suggest that you step through with the debugger and find out what is going wrong that way.
Alan Weiss
MATLAB mathematical toolbox documentation
More Answers (1)
See Also
Categories
Find more on Genetic Algorithm 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!