How to Set a Minimum Step Size for Variables in GA Solver (Global Optimization Toolbox)?
Ältere Kommentare anzeigen
Hello,
I am using the GA solver from the Global Optimization Toolbox and I was wondering if it is possible to specify a minimum variation for the variables. I have already set the lower bound (lb) and upper bound (ub), but I would like to define a minimum step size. For example, let's say the variables range from -1 to 1 (ub=1 and lb=-1), but I would like them to take only values that are multiples of 0.1, such as -1, -0.9, -0.8, ..., 0.9, 1, and not values like 0.0X. Thank you in advance.
Akzeptierte Antwort
Weitere Antworten (2)
I solved it complete.
Solution AB1:
close all force;
clc;
clear all
clear global;
tol = 2.7756e-1;
format('long','g') %format of the numeric values: each number represented by about 15 digits
ub = 1;
lb = -1;
pop_size = 40;
step = 0.1;
A = 10;
xval = lb:step:ub;
yval = lb:step:ub;
x = optimvar('x',1,1,1,'Type','continuous','LowerBound',lb,'UpperBound',ub)
y = optimvar('y',1,1,1,'Type','continuous','LowerBound',lb,'UpperBound',ub)
f1 = A*sqrt(y.^2 + x.^2 + 5);
prob = optimproblem(Objective=f1);
vals = optimvalues(prob,x=xval,y=yval);
opts = optimoptions("ga",PopulationSize=400);
[sol,fv] = solve(prob,vals,Solver="ga",Options=opts)
% Your needs = ... []-> to continue ... []-> to keep doing...
%Constructed by P.Mazniker
%+380990535261
%https://diag.net/u/u6r3ondjie0w0l8138bafm095b
%https://github.com/goodengineer
%https://orcid.org/0000-0001-8184-8166
%https://join.skype.com/invite/oXnJhbgys7oW
% https://willwork781147312.wordpress.com/portfolio/cp/
% https://nanohub.org/members/130066
% https://www.youtube.com/channel/UCC__7jMOAHak0MVkUFtmO-w
Define 21 integer variables x_i that can take values 0 or 1 (by using the "intcon" input to "ga" and setting the lower and upper bounds for the x_i to 0 and 1, respectively)
Set the linear equality constraint that the sum over these 21 integer variables x_i equals 1 (by using Aeq and beq).
Then the variable
y = -1 + 0.1*sum_{i=0}^{i=20} i*x_i
is the variable you are after: it can only take values -1,-0.9,-0.8,...,1.9,2.
Kategorien
Mehr zu Get Started with Optimization Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!