示例#1
0
    def __call__(self, truss_1, truss_2):
        """Calls a crossover object on two trusses to combine them.

        Crossover object must have been instantiated specifying which
        methods to use.

        Args:
            truss_1 (Truss object): First truss to be combined.
            truss_2 (Truss object): Second truss to be combined.

        Returns:
            child_1, child_2 (Truss objects): Children trusses produced by crossover.

        """

        user_spec_nodes = self.params['user_spec_nodes']
        child_1 = Truss(user_spec_nodes, 0, 0, 0)
        child_2 = Truss(user_spec_nodes, 0, 0, 0)
        child_1.rand_nodes, child_2.rand_nodes = self.node_method(
            truss_1.rand_nodes, truss_2.rand_nodes,
            **self.params['node_crossover_params'])
        child_1.edges, child_2.edges = self.edge_method(
            truss_1.edges, truss_2.edges,
            **self.params['edge_crossover_params'])
        child_1.properties, child_2.properties = self.property_method(
            truss_1.properties, truss_2.properties,
            **self.params['property_crossover_params'])

        return child_1, child_2
示例#2
0
    def __call__(self, truss):
        """Calls a mutator object on a truss to change it.

        Mutator object must have been instantiated specifying which
        methods to use.

        Args:
            truss (Truss object): Truss to be mutated.

        Returns:
            child (Truss object): Child truss produced by mutation.

        """
        user_spec_nodes = self.params['user_spec_nodes']
        child = Truss(user_spec_nodes, 0, 0, 0)
        child.rand_nodes = self.node_method(
            truss.rand_nodes, **self.params['node_mutator_params'])
        child.edges = self.edge_method(truss.edges,
                                       **self.params['edge_mutator_params'])
        child.properties = self.property_method(
            truss.properties, **self.params['property_mutator_params'])

        return child