Binary solutions with GA
Show older comments
Hi
I am currently working with GA on resource allocation and the goal is to find binary solutions with a non linear objective and linear constraints.
At the beginning of the project, I had a problem with more than 700 variables with many constraints and the solutions that I had from GA were very irrelevant. I thought the size of the problem was the issue.
So I broke down the problem into many models in order to have less that hundreds variables (in occurrence 30 variables for the current model I am building) and around hundreds constraints too for each model (in occurrence 95 linear constraints for the same current model). Besides, some of the constraints are normally equality constraints that I transformed into inequality constraints to help GA to find a solution. BUT at the end I still have solutions that don't correspond to the constraints. For the instance, for example if we want to allocate 30 bags in 5 cabinets so that each bag is allocated only in one cabinet, I got some results where one bag is allocated in many cabinets, even though the inequality constraints that I wrote seem totally correct.
I have this report at the end "Optimization terminated: average change in the penalty fitness value less than options.FunctionTolerance and constraint violation is less than options.ConstraintTolerance".
I don't really know what to do with this problem and I am quite in a need of a solution for an industrial (confidential) problem after having purchased GA weeks ago (the trials for smaller sizes seemed to work previously). Please could you give any support for that?
Thanks,
Loic
8 Comments
Walter Roberson
on 20 Jun 2017
For your "30 bags in 5 cabinets" portion, are you handling that by using 30*5 = 150 binary decision variables, like taking the vector equivalent of (a 30 x 5 matrix in which a 1 in the J'th column indicated that the bag was in the J'th cabinet) ?
You are already using integer constraints in order to do binary, so you are already unable to use a nonlinear constraint function except by supplying your own population and mutation functions, so it might seem to make some sense to use a single integer in the range 1 to 5 for each bag, indicating which cabinet it is in, thus making it impossible for the system to consider it in multiple cabinets at the same time. (I think I worked out once how you could do capacity restraints on integer variables but it does not come to mind immediately.... perhaps I only worked out how to do it for binary decision variables.)
Loic Wilfried Biakeu Njia
on 20 Jun 2017
Walter Roberson
on 20 Jun 2017
nonlcon - nonlinear constraint function
"Function handle that returns two outputs:
[c,ceq] = nonlcon(x)
ga attempts to achieve c ≤ 0 and ceq = 0. c and ceq are row vectors when there are multiple constraints. Set unused outputs to [].
ga does not enforce nonlinear constraints to be satisfied when the PopulationType option is set to 'bitString' or 'custom'.
If IntCon is not empty, the second output of nonlcon (ceq) must be an empty entry ([])."
===
This has nothing to do with your objective function being non-linear: there are restrictions on using constraints with intcon set. nonlinear constraints are the easy way to code the kind of bounds you mentioned, but nonlinear equality constraints are not supported if you have IntCon set. Also,
"Note: When IntCon is nonempty, Aeq and beq must be an empty entry ([]), and nonlcon must return empty for ceq. For more information on integer programming, see Mixed Integer Optimization."
so linear equality constraints are not supported either. That makes it a nuisance to code equalities such as that the number of bags in a cabinet must be exactly 5. However, in some situations you can recode the equality constraint by first coding -1 entries in the A matrix and setting the b entry to the negative of the total: this ensures that at least that many entries are set. Then you code +1 entries in the A and set the corresponding b to the positive of the total: this ensures that no more than that many entries are set. The combination of "at least" and "no more than" can achieve an equality. However, at the moment I am not confident that the same kind of technique can be applied to non=binary integer decision variables.
Loic Wilfried Biakeu Njia
on 21 Jun 2017
Loic Wilfried Biakeu Njia
on 26 Jun 2017
Walter Roberson
on 26 Jun 2017
"Is it any way possible to still have integer solutions without IntCon but only using Aeq and Ceq?"
No. In order to get integer solutions, you need to use IntCon or you need to provide custom creation and mutation functions that just happen to only return integers in the range you want. It is not possible to get integer solutions only using Aeq and Ceq. However, if you provide a custom creation and mutation function, and use PopulationType 'doubleVector' (the default) then you can use Aeq and Ceq. (You might need to provide custom crossover function as well.)
I have not figured out yet if it is possible to use just the nonlinear constraints to enforce maximum number of bags per cabinet when the variables are set to the cabinet number. Looking again, though, I do not see you mention a maximum number of bags per cabinet: you say 30 must go into 5 cabinets, but you did not (in what you posted) say that it was not permitted for all 30 bags to go into a single cabinet. Are there maximums? Is the requirement that each cabinet receive exactly 6 bags?
Loic Wilfried Biakeu Njia
on 28 Jun 2017
Walter Roberson
on 28 Jun 2017
Ah, good point about the number sometimes having to vary.
Answers (1)
Brendan Hamm
on 20 Sep 2017
0 votes
This will be a bit length to answer this question again, but I have provided a way you can solve this problem in a previous post:
This does use a multiobjective problem, but the idea of writing the population, crossover and mutation functions is the same.
2 Comments
Loic Wilfried Biakeu Njia
on 27 Sep 2017
Brendan Hamm
on 30 Sep 2017
If you post it on here I will take a look when I have some time and suggest some possible alternatives.
Categories
Find more on Linear Least Squares in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!