Issue Description
The maximize parameter in the mlrose library is not clearly documented, leading to unexpected behavior in certain problem types. Specifically, setting maximize=True does not properly convert some problems to maximization problems and may inadvertently make them easier to solve.
Example: N-Queens Problem
In the case of the N-Queens problem, simply setting the parameter maximize=True can drastically reduce the complexity of the problem. This happens because when the objective is to maximize the number of collisions on the chessboard, there are many trivial solutions (e.g., all queens on the first rank, all queens on the second rank, all queens on the same diagonal, etc.).
To properly convert the N-Queens problem into a maximization problem, additional steps are required. Below is an example of how to manually handle this:
# Improper conversion of N-Queens to maximization problem (DO NOT DO THIS)
# problem = mlrose.QueensOpt(length=size, maximize=True) (DO NOT DO THIS)
# Proper conversion of N-Queens to maximization problem
queens_fit = lambda state: mlrose.Queens().evaluate(state) * -1
problem = mlrose.DiscreteOpt(length=size, max_val=size, maximize=True, fitness_fn=mlrose.CustomFitness(queens_fit))
Using this approach, the objective is maximized correctly without introducing trivial solutions.
Proposed Documentation Improvements
Clarify the behavior of the maximize parameter in the documentation and example notebooks.
Provide examples of problems that need need manual conversion to maximization problems.
Consider adding a note in the QueensOpt (and other relevant classes) docstrings to address this issue specifically, as it could mislead users into thinking the maximize=True flag is enough in this case.
Issue Description The
maximize
parameter in themlrose
library is not clearly documented, leading to unexpected behavior in certain problem types. Specifically, settingmaximize=True
does not properly convert some problems to maximization problems and may inadvertently make them easier to solve.Example: N-Queens Problem In the case of the N-Queens problem, simply setting the parameter
maximize=True
can drastically reduce the complexity of the problem. This happens because when the objective is to maximize the number of collisions on the chessboard, there are many trivial solutions (e.g., all queens on the first rank, all queens on the second rank, all queens on the same diagonal, etc.).To properly convert the N-Queens problem into a maximization problem, additional steps are required. Below is an example of how to manually handle this:
Using this approach, the objective is maximized correctly without introducing trivial solutions.
Proposed Documentation Improvements
maximize
parameter in the documentation and example notebooks.QueensOpt
(and other relevant classes) docstrings to address this issue specifically, as it could mislead users into thinking themaximize=True
flag is enough in this case.