I am using the Genetic Algorithm to solve a particular problem. I am optimizing scheduled over the day vs a price. The schedule is wether On or Off. So the parameters from the genetic algorithm are the index of starting of each range. Ex :
Range 1 : 0h --> x(1) = 0
Range 2 : 07h --> x(2) = 7....
To do this I need to put a constraint that will tell the algorithm that x(4)>x(3)>x(2)>x(1)... Unfortunately, I am not able to do so with the existing constraints :
A*x = b
lb & ub
Does anyone have an idea to do this ?

 Akzeptierte Antwort

John D'Errico
John D'Errico am 7 Nov. 2018
Bearbeitet: John D'Errico am 7 Nov. 2018

0 Stimmen

Um, the constraints allow you to supply inequality constraints. In fact, the A and b arguments are INEQUALITY constraints, NOT EQUALITY constraints as you indicted. (READ THE HELP.) So you can indeed specify what you want, with one caveat.
So, if you want to enforce that
x(4)>x(3)>x(2)>x(1)
then set A, such that A*x<=b. That means here, we would have
A = [1 -1 0 0;0 1 -1 0;0 0 1 -1];
b = [0;0;0];
That will constrain the variables such that
x(4) >= x(3) >= x(2) >= x(1)
However, there is NO provision for strict inequality constraints. In fact, pretty much no optimizer allows that, although there are tricks you can use.
The simplest thing to do is to specify an offset, thus a minimum distance between elements. Don't go too small, but this should suffice:
delta = 1e-6;
b = -delta*ones(3,1)
You need to watch out for the constraint tolerance.
There are other ways to solve this, using a transformation of the variables, but the simple solution is usually the best.

1 Kommentar

Thib Lab
Thib Lab am 8 Nov. 2018
Bearbeitet: Thib Lab am 8 Nov. 2018
Thanks for your answer ! It should work but actually the parameters don't reply to the constraints. I defined A and b as you said and I still get this kind of matrix :
[0 18 8 47 16 1]

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by