Error Using Optimization with Integer Variables and Non-linear Constraints
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi guys! I would be very grateful if you could help me!
I'm trying to minimize the norm of a vector using optimization algorithms in MATLAB, but I'm getting an error that says "Problems with integer variables and nonlinear equality constraints are not supported."
Could someone help me understand how I can solve this and minimize the norm of the vector?
Here's the implemented code:
wpass = 0.0318*pi;
wstop = 0.15*pi;
pb_ripple = 0.03;
sb_ripple = 0.03;
n = 25;
l = 7;
k = 2^l;
N = 15*n;
w = linspace(0,pi,N);
A = [ones(N,1) 2*cos(kron(w',1:n))];
Ap = A((0 <= w) & (w <= wpass),:);
As = A((wstop <= w) & (w <= pi),:);
H_dac=sinc(w);
H_dac_p=H_dac(1,(0 <= w) & (w <= wpass));
H_dac_s=H_dac(1,(wstop <= w) & (w <= pi));
h = optimvar('h',(n+1), 'Type','integer','LowerBound',-inf,'UpperBound',inf);
norm_h=optimvar('norm_h','Type','integer');
prob = optimproblem('ObjectiveSense','minimize');
prob.Constraints.cons1 = norm_h==norm(cat(1,h(end:-1:2),h),1);
prob.Objective = norm_h;
prob.Constraints.cons2 = Ap*h <= k*(1 + pb_ripple);
prob.Constraints.cons3 = Ap*h >= k*(1 - pb_ripple);
prob.Constraints.cons4 = As*h <= k*(sb_ripple);
prob.Constraints.cons5 = As*h >= -k*(sb_ripple);
sol = solve(prob);
0 Kommentare
Antworten (1)
Torsten
am 28 Apr. 2024
Bearbeitet: Torsten
am 28 Apr. 2024
Replace
norm_h=optimvar('norm_h','Type','integer');
prob = optimproblem('ObjectiveSense','minimize');
prob.Constraints.cons1 = norm_h==norm(cat(1,h(end:-1:2),h),1);
prob.Objective = norm_h;
by
%norm_h=optimvar('norm_h','Type','integer');
prob = optimproblem('ObjectiveSense','minimize');
%prob.Constraints.cons1 = norm_h==norm(cat(1,h(end:-1:2),h),1);
prob.Objective = norm(cat(1,h(end:-1:2),h),1);
Since h is integer valued, its 1-norm will also be integer-valued automatically.
The ga solver does not accept integer variables together with nonlinear equality constraints.
I think you can formulate the problem such that "intlinprog" can be used to solve it. This has several advantages over "ga" (which will most probably be chosen by MATLAB as solver for your problem).
2 Kommentare
Torsten
am 29 Apr. 2024
Bearbeitet: Torsten
am 29 Apr. 2024
Which MATLAB version do you use ?
pb_ripple = sb_ripple = 0.03 gives the message that the linear bounds are infeasible.
For pb_ripple = sb_ripple = 0.3, your problem is solved by "ga".
If you use the 1-norm or infinity-norm instead of the 2-norm in your objective function, you can formulate the problem such that MATLAB is able to use "intinprog" instead of "ga" for its solution. This would be much faster and more reliable.
wpass = 0.0318*pi;
wstop = 0.15*pi;
pb_ripple = 0.3;
sb_ripple = 0.3;
n = 5;
l = 7;
k = 2^l;
N = 15*n;
w = linspace(0,pi,N);
A = [ones(N,1) 2*cos(kron(w',1:n))];
Ap = A((0 <= w) & (w <= wpass),:);
As = A((wstop <= w) & (w <= pi),:);
H_dac=sinc(w);
H_dac_p=H_dac(1,(0 <= w) & (w <= wpass));
H_dac_s=H_dac(1,(wstop <= w) & (w <= pi));
h = optimvar('h',n+1,'Type','integer');
Obj = sqrt(sum(cat(1,h(end:-1:1),h).^2));
prob = optimproblem("Objective",Obj);
prob.Constraints.cons2 = Ap*h <= k*(1 + pb_ripple);
prob.Constraints.cons3 = Ap*h >= k*(1 - pb_ripple);
prob.Constraints.cons4 = As*h <= k*(sb_ripple);
prob.Constraints.cons5 = As*h >= -k*(sb_ripple);
x0.h = randi([0 0],n+1,1);
[sol,fval] = solve(prob,x0)
sol.h
Siehe auch
Kategorien
Mehr zu Surrogate Optimization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!