-
-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use Integer type with others? #31
Comments
Well, the problem is line 54: |
@dhadka Could you post an example with Float and Integer and how do I add custom variators By default in config.py:
The line added by me:
Adding problem.types -> Integer:
and after change to
I see that when running it, the Integer variables do not mutate or change, and always integer have the same values in population, but Real variables work fine (mutate, etc). How can I make it work with Integer? |
You would need to do something like: from platypus import *
def mixed_type(x):
print("Evaluating", x)
return [x[0], x[1]]
problem = Problem(2, 2)
problem.types[0] = Real(0, 10)
problem.types[1] = Integer(0, 10)
problem.function = mixed_type
algorithm = NSGAII(problem, variator=CompoundOperator(SBX(), HUX(), PM(), BitFlip()))
algorithm.run(10000)
print("Final solutions:")
for solution in unique(nondominated(algorithm.result)):
print(solution.variables, solution.objectives) The key here is that you need to provide a custom variator that is capable of mutating both real and int. We can use the CompoundOperator in most cases to combine operators of different types. |
@dhadka Thank you! I can confirm that this works in my case, involving 2 integers and 4 reals, with an unmodified |
This issue is stale and will be closed soon. If you feel this issue is still relevant, please comment to keep it active. Please also consider working on a fix and submitting a PR. |
If I attempt to use a
problem.types
array that contains anInteger
type and aReal
, it runs for a while and then I get the errorUnfortunately, I cannot find an explanation in the documentation about what this error means and what I can do about it. Looking at the source code, the error comes from
isinstance
comparisons to the class of the first element in the listproblem.types
. Now, the typeInteger
is defined as a subclass ofBinary
in the file types.py, andBinary
is a type defined inPlatypusConfig.default_variator
, so it seems like it should work and that the failure comes from not detecting the subclass relationship.As a test of this hypothesis, I added definitions of
Integer
to config.py like this (copying the definitions fromBinary
, sinceInteger
is based on it anyway):and then bypassed the tests for
all([isinstance(t, base_type) for t in problem.types])
on lines 56 and 74 in the file config.py (by simply writingif True:
). The result runs and seems to be working.This was a hack and a correct solution is needed, but I wanted to report the problem and a possible direction to explore for fixing it.
The text was updated successfully, but these errors were encountered: