I have been working with the mealpy Python library for quite some time-- the repository of around 200 metaheuristic algorithms including GA, DE, ACO, PSO, ...authored by Nguyen Van Thieu, alias thieu1995.
However, working with discrete variables (particularly categoric variables in the form of strings, or integer variables) remains a nightmare. Variables have to be encoded, then decoded again in the fitness function, or outside-- which are prone to cause several anomalies and vulnerabilities, especially when there are some dependent variables in the model, alongside discrete constraints or ranges.
Same (though somewhat less painful) for integer variables, which have to be rounded off or truncated everytime a fitness function is calculated, and once again when the best solution is presented.
Is it possible to encode integer or categoric variables with mealpy ?
Till October 2023
mealpyversion2.x.yhad its "problem_dictionary" defined as :where lower and upper bounds
lbandubhad to be mandatorily specified as floating point (real-valued) ranges.New in November 2023
mealpyversion3.0.0onward, there are options to define several new variable types, denoted in :FloatVar,IntegerVar,StringVar,BoolVar,PermutationVar,BinaryVar, andMixedSetVarclasses
Here's the code to try them out on three simple 3-varaible problems, where :
int,str, andint, another isstr, while the third isfloat.which produces the output :
Caveat
Unfortunately, a real
floatvariable cannot be mixed with discrete variables inmealpystill, and they will have to be coded as "pseudo-float" with a finite precision.We can expect this feature in their future releases. But still, what's here is precious enough !