Platypus
Platypus copied to clipboard
Can't fix the value of a variable
It is not possible to fix the value of a variable.
Integer(0,0)
It would be useful in the context of multiple iterations in a optimization process where I keep narrowing the solution space, focusing on the best solutions.
One option is to define a custom type for constants:
class Constant(Type):
def __init__(self, value):
super(Constant, self).__init__()
self.value = value
def rand(self):
return self.value
def __str__(self):
return "Constant(%s)" % (self.value)
The only issue with this is you must explicitly tell Platypus what variation operators to use. It does not have default operators for mixed types.
from platypus import *
def example(x):
return [x[0], x[1]]
problem = Problem(2, 2)
problem.types[0] = Real(-10, 10)
problem.types[1] = Constant(5)
problem.function = example
algorithm = NSGAII(problem, variator=CompoundOperator(SBX(), PM()))
algorithm.run(10000)
print(algorithm.result)
The mutation and crossover operators will only be applied to the Real variable(s) and will skip the Constant variable.
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.