MATLAB: Genetic Algorithm – Special constraint

genetic algorithm

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 ?

Best Answer

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.
Related Question