Exemplo n.º 1
0
    def add_algorithm_input(self, name, low, high):
        """ Adds a new input trait for the algorithm
        """
        if len(name) == 0 or low >= high:
            return

        self.algorithm_inputs.append((name, Range(low, high)))
        value = (low+high)/2

        # Create the new instance and add the input traits to it
        algorithm = Algorithm()
        for input in self.algorithm_inputs:
            algorithm.add_trait(*input)
        # Set a default value for the new trait
        setattr(algorithm, name, value)

        # Copy values from the old instance
        old = self.algorithm
        traits = set(old.trait_names()) - {'trait_added', 'trait_modified'}
        for trait in traits:
            setattr(algorithm, trait, getattr(old, trait))

        self.algorithm = algorithm