Exemplo n.º 1
0
    def test_random_mimic():
        """Test random_mimic method"""

        dists = [(0, 1, 3), (0, 2, 5), (0, 3, 1), (0, 4, 7), (1, 3, 6),
                 (4, 1, 9), (2, 3, 8), (2, 4, 2), (3, 2, 8), (3, 4, 4)]

        pop = np.array([[1, 0, 3, 2, 4], [0, 2, 1, 3, 4], [0, 2, 4, 3, 1],
                        [4, 1, 3, 2, 0], [3, 4, 0, 2, 1], [2, 4, 0, 3, 1]])

        problem = TSPOpt(5, distances=dists)
        problem.keep_sample = pop
        problem.eval_node_probs()
        problem.find_sample_order()

        rand = problem.random_mimic()

        assert (len(rand) == 5 and len(set(rand)) == 5)
Exemplo n.º 2
0
    def test_sample_pop():
        """Test sample_pop method"""

        dists = [(0, 1, 3), (0, 2, 5), (0, 3, 1), (0, 4, 7), (1, 3, 6),
                 (4, 1, 9), (2, 3, 8), (2, 4, 2), (3, 2, 8), (3, 4, 4)]

        pop = np.array([[1, 0, 3, 2, 4], [0, 2, 1, 3, 4], [0, 2, 4, 3, 1],
                        [4, 1, 3, 2, 0], [3, 4, 0, 2, 1], [2, 4, 0, 3, 1]])

        problem = TSPOpt(5, distances=dists)

        problem.keep_sample = pop
        problem.eval_node_probs()

        sample = problem.sample_pop(100)
        row_sums = np.sum(sample, axis=1)

        assert (np.shape(sample)[0] == 100 and np.shape(sample)[1] == 5
                and max(row_sums) == 10 and min(row_sums) == 10)