def biased_random(): cfg = ConfigurationManipulator.random(manipulator) # duplicates in the search space, bias to `n / 2` enabled disabled = random.sample(range(self.flags_limit), k=self.flags_limit - self.env.action_space.n) cfg.update({f"flag{x}": False for x in disabled}) return cfg
def manipulator(self) -> ConfigurationManipulator: """Define the search space.""" manipulator = ConfigurationManipulator() # A permutation parameter to order the passes that are present. manipulator.add_parameter( PermutationParameter("flag_order", list(range(self.flags_limit)))) # Boolean parameters for whether each pass is present. for i in range(self.flags_limit): manipulator.add_parameter(BooleanParameter(f"flag{i}")) def biased_random(): cfg = ConfigurationManipulator.random(manipulator) # duplicates in the search space, bias to `n / 2` enabled disabled = random.sample(range(self.flags_limit), k=self.flags_limit - self.env.action_space.n) cfg.update({f"flag{x}": False for x in disabled}) return cfg manipulator.random = biased_random return manipulator