コード例 #1
0
 def test_alternate(self):
     iteration = SolverIterator([SolverPhase(SolverMethod.ALTERNATING, 3)])
     expected = [
         SolverMethod.CLUSTERING, SolverMethod.SCHEDULING,
         SolverMethod.CLUSTERING
     ]
     self.helper_iterator(iteration, expected)
コード例 #2
0
    def helper_single(self, method):
        iteration = SolverIterator([SolverPhase(method, 3)])
        for _ in range(3):
            step = next(iteration)
            self.assertEqual(step.method, method)

        with self.assertRaises(StopIteration):
            next(iteration)
コード例 #3
0
    def test_time_for_normal(self):
        iteration = SolverIterator(
            [SolverPhase(SolverMethod.CLUSTERING, 100, maxtime=1)])

        for _ in range(10):
            next(iteration)
            time.sleep(0.1)

        with self.assertRaises(StopIteration):
            next(iteration)
コード例 #4
0
    def test_progression(self):
        iteration = SolverIterator([
            SolverProgressionPhase(SolverMethod.CLUSTERING, 5),
            SolverProgressionPhase(SolverMethod.CLUSTERING, 5)
        ])

        for _ in range(3):
            next(iteration)
        solution_score = SolutionScore(1.0, 1.0)
        solution_score.assignment['score'] = 1.0

        iteration.register_fitness(solution_score)

        for _ in range(3):
            next(iteration)
        iteration.register_fitness(solution_score)
        self.assertEqual(iteration._current_phase, 0)

        for _ in range(3):
            next(iteration)
        self.assertEqual(iteration._current_phase, 1)

        for _ in range(4):
            next(iteration)
        self.assertEqual(iteration._current_phase, 1)

        with self.assertRaises(StopIteration):
            next(iteration)
コード例 #5
0
    def test_complex(self):
        iteration = SolverIterator([
            SolverPhase(SolverMethod.CLUSTERING, 2),
            SolverPhase(SolverMethod.SCHEDULING, 3),
            SolverPhase(SolverMethod.ALTERNATING, 4),
            SolverPhase(SolverMethod.BOTH, 5)
        ])

        expected = ([SolverMethod.CLUSTERING] * 2 +
                    [SolverMethod.SCHEDULING] * 3 + [
                        SolverMethod.CLUSTERING, SolverMethod.SCHEDULING,
                        SolverMethod.CLUSTERING, SolverMethod.SCHEDULING
                    ] + [SolverMethod.BOTH] * 5)

        self.helper_iterator(iteration, expected)
コード例 #6
0
 def test_empty(self):
     iteration = SolverIterator([])
     with self.assertRaises(StopIteration):
         next(iteration)
コード例 #7
0
from esme.common import SolverMethod
from esme.iterator import SolverPhase, SolverIterator

iteration = SolverIterator([
    SolverPhase(SolverMethod.CLUSTERING, 2),
    SolverPhase(SolverMethod.SCHEDULING, 3),
    SolverPhase(SolverMethod.ALTERNATING, 4),
    SolverPhase(SolverMethod.BOTH, 5)
])

expected = ([SolverMethod.CLUSTERING] * 2 + [SolverMethod.SCHEDULING] * 3 + [
    SolverMethod.CLUSTERING, SolverMethod.SCHEDULING, SolverMethod.CLUSTERING,
    SolverMethod.SCHEDULING
] + [SolverMethod.BOTH] * 5)

for x in iteration:
    print(x.method, x.i)

print(expected)