Clear Filters
Clear Filters

Surrogate optimization with different size constraints

3 views (last 30 days)
I have this problem for optimization (22-dimensional):
Min sum(t1/x1,t2/x2,...,t22/x22)
Subject to:
x1 + x2 + ... + x22 -140 - tol <= 0
-x1 - x2 - ... - x22 +140 - tol <= 0
-x1 <= -1
-x2 <= -1
...
-x22 <= -1
In surrogate optimization I have to add the constraints into the objective function handle, like this:
function F = transport(x)
% transporte is a 22-D problem
D = 22;
t = [3717,4982,3688,4337,6405,3769,3968,4900,5746,5753,7388,2832,4182,3618,4009,5291,5710,3742,3875,3436,5167,3950];
z = sum(t./x);
tol = 1e-3;
c1 = [sum(x) - 140 - tol;sum(-x) + 140 - tol];
A = ones(1,D)*(-1);
A = diag(A);
b = ones(D,1)*(-1);
c2 = A - b;
c = [c1 c2];
F.Fval = z;
F.Ineq = c;
end
I get this error, because c1 and c2 have different sizes:
Dimensions of arrays being concatenated are not consistent.
How can I create this constraints and pass to surrogate model?
My script:
% Mixed Integer Surrogate Optimization
clear all %#ok
close all
clc
rng default
D = 22;
lb = ones(1,D);
ub = ones(1,D)*10;
IntCon = 1:D;
options = optimoptions('surrogateopt','ConstraintTolerance',1e-6,'ObjectiveLimit',1e-6);
[xmin,fval,exitflag,output] = surrogateopt(@transport,lb,ub,IntCon,options);
Thanks a lot!

Accepted Answer

Alan Weiss
Alan Weiss on 1 Mar 2021
Your problem is this line:
c = [c1 c2];
The variable c1 is a 2-by-1 column. c2 is, I think, a 22-by-22. Maybe a 22-by-1. In any case, they cannot be concatenated like this.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Comments
David Franco
David Franco on 1 Mar 2021
You're right, Alan. I found on the page Solve Feasibility Problem the answer:
c(:,1:2) = [sum(x) - 140 - tol, sum(-x) + 140 - tol];
c(:,3:D+2) = (sum(A,2) - b)';
Each column in the structure field Ineq is a constraint.
Write each inequality as a function c(x), meaning the inequalities c(x) ≤ 0.
Thank you!
David Franco
David Franco on 1 Mar 2021
Interesting that both GA and Surrogate in Matlab gave me a worse response than GA in Excel. And Surrogate was much slower.

Sign in to comment.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!