示例#1
0
    def test_permutations(self):
        """Permutations must return only unique combinations, excluding combinations
        that are mirrored (example: should not contain 'AB' and 'BA').
        """
        permutations_one = [('a', 'b', 'c'), ('a', 'c', 'b'), ('b', 'a', 'c')]
        permutations_two = [('a', 'b'), ('a', 'c'), ('a', 'd'), ('b', 'c'),
                            ('b', 'd'), ('c', 'd')]

        self.assertEqual(permutations_one,
                         list(helpers.permutations(['a', 'b', 'c'])))
        self.assertEqual(permutations_two,
                         list(helpers.permutations('abcd', 2)))
示例#2
0
    def test_permutations(self):
        """Permutations must return only unique combinations, excluding combinations
        that are mirrored (example: should not contain 'AB' and 'BA').
        """
        permutations_one = [('a', 'b', 'c'), ('a', 'c', 'b'), ('b', 'a', 'c')]
        permutations_two = [
            ('a', 'b'), ('a', 'c'), ('a', 'd'), ('b', 'c'), ('b', 'd'),
            ('c', 'd')
        ]

        self.assertEqual(
            permutations_one, list(helpers.permutations(['a', 'b', 'c']))
        )
        self.assertEqual(
            permutations_two, list(helpers.permutations('abcd', 2))
        )
示例#3
0
    def find_layout(self, avaliable_plants=None, length=None, width=None):
        if avaliable_plants is None:
            avaliable_plants = self.plants
        if length is None:
            length = self.length
        if width is None:
            width = self.width

        plants = []
        plots = Plots()
        for k, v in avaliable_plants.items():
            plants.extend([k]*v)
        plot_scores = []
        for p in helpers.permutations(plants, length*width):
            plots.set_plots(
                matrix(p).reshape(length, width).tolist()
                )
            score = plots.get_total_score()
            plot_scores.append((score, p))

        best_plot = max(plot_scores)[1]
        return matrix(best_plot).reshape(length, width).tolist()