excluding a number before sending x vector to optimization?
Afficher commentaires plus anciens
Hi,
I am using a huristic algorithm for optimization. x-variable vector range is as given below.
xU = [16 16 16 16 1 1 1 1];%upper bound on decision variables
xL = [-16 -16 -16 -16 0 0 0 0];%lower bound on decision variables
If I want to exclude 0 from the first 4-variable how I can estaiblesh?
When I define sub groups from 1:16 and -16:-1 then combine as x vector for the first 4 variable, it increases the number of variables not just removing the 0.
thank you
5 commentaires
I'm not sure if I understand what you're asking, but if you want to exclude zero from a vector, then it is very easy:
x = -1:5;
x
x(x==0) = [];
x
Gulcihan Ozdemir
le 17 Déc 2022
Déplacé(e) : John D'Errico
le 17 Déc 2022
Askic V
le 17 Déc 2022
Déplacé(e) : John D'Errico
le 17 Déc 2022
Is your x a matrix with 8 columns where column k is bounded between xU(k) and xL(k)? You want to remove zeros from the first 4 columns of x?
John D'Errico
le 17 Déc 2022
@Gulcihan Ozdemir - Please don't post an answer just to make a comment.
Gulcihan Ozdemir
le 17 Déc 2022
Réponses (1)
John D'Errico
le 17 Déc 2022
Modifié(e) : John D'Errico
le 17 Déc 2022
You don't tell us WHICH heuristic algorithm you are using, so that means it is a homebrew algorithm of your own choosing or creation. It also tells me I cannot be more accurate about an answer.
And it is not even clear if your problem is an integer one. If the variables are continuous, then no, there is no tool where you can tell it that you have a continuous domain, that DOES not include some interior point of that domain. You cannot tell an optimizer like fmincon to not allow some specific value within the bounds for that variable.
The only optimizers that can solve an integer problem like this are tools like GA, so an algorithm that can handle integer variables. GA can handle it with no problem. And any algorithm that can handle integer variables in a nonlinear context should be ok too. So I'll show how to solve it using GA.
help ga
For example, suppose I want to find the minimum of a VERY simple, two variable function. So minimize X^2+Y^2, subject to the constraint that X lies in the set [-5 -4 -3 2 4 9 12], and Y lies in the set [-14 -11 -5 3 6 10 16]? These are totally arbitrary sets of integers.
Yesh, I know, utterly trivial. And I can surely find many ways to solve the problem. I might use a table lookup, for example.
xvalid = [-6 -5 -4 -3 2 4 9 12];
yvalid = [-14 -11 -5 3 6 10 16];
fun = @(xyind) xvalid(xyind(1)).^2 + yvalid(xyind(2)).^2;
intcon = [1 2];
LB = [1 1];
UB = [8 7];
[xyind,fval,exitflag] = ga(fun,2,[],[],[],[],LB,UB,[],intcon)
[xvalid(xyind(1)),yvalid(xyind(2))]
As you can see, there is no problem at all, since the algorithm itself thinks the set of choices are the integers 1:8 for X and 1:7 for Y.
Anything you will do will probably be in some way equivalent to that.
2 commentaires
Gulcihan Ozdemir
le 17 Déc 2022
Torsten
le 17 Déc 2022
The value "3" does not stem from 1:8 and 1:7. The "2" comes from xvalid and the "3" comes from yvalid. If you don't want to see certain numbers in the solution, you just have to remove these numbers from xvalid resp. yvalid. 1:8 resp. 1:7 are just the number of elements of the two valid number sets.
Catégories
En savoir plus sur Choose a Solver dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!