Beispiel #1
0
    def test_first_fit(self):
        failed, mapping = apa.edf_first_fit_decreasing_difficulty(
            self.ts, [1, 2, 3])

        self.assertEqual(failed, set())
        self.assertEqual(len(mapping), 3)
        self.assertEqual(mapping[1], [self.ts[0], self.ts[1]])
        self.assertEqual(mapping[2], [self.ts[3]])
        self.assertEqual(mapping[3], [self.ts[2]])

        failed, mapping = apa.edf_first_fit_decreasing_difficulty(
            self.ts, [2, 1, 3])

        self.assertEqual(failed, set())
        self.assertEqual(len(mapping), 3)
        self.assertEqual(mapping[2], [self.ts[2], self.ts[1]])
        self.assertEqual(mapping[1], [self.ts[0], self.ts[3]])
        self.assertEqual(mapping[3], [])

        # give it one more to place
        self.ts.append(tasks.SporadicTask(19, 31))
        self.ts[-1].affinity = set([2, 3])
        self.ts.assign_ids()

        failed, mapping = apa.edf_first_fit_decreasing_difficulty(
            self.ts, [1, 2, 3])
        self.assertEqual(failed, set([self.ts[-1]]))

        failed, mapping = apa.edf_first_fit_decreasing_difficulty(
            self.ts, [2, 1, 3])

        self.assertEqual(failed, set())
        self.assertEqual(len(mapping), 3)
        self.assertEqual(mapping[2], [self.ts[2], self.ts[1]])
        self.assertEqual(mapping[1], [self.ts[0], self.ts[3]])
        self.assertEqual(mapping[3], [self.ts[4]])

        # give it yet another more to place
        self.ts.append(tasks.SporadicTask(40, 50))
        self.ts[-1].affinity = set([1, 2, 3])
        self.ts.assign_ids()

        failed, mapping = apa.edf_first_fit_decreasing_difficulty(
            self.ts, [2, 1, 3])

        self.assertEqual(failed, set([self.ts[4]]))
        self.assertEqual(len(mapping), 3)
        self.assertEqual(mapping[1], [self.ts[0], self.ts[5]])
        self.assertEqual(mapping[2], [self.ts[2], self.ts[1]])
        self.assertEqual(mapping[3], [self.ts[3]])
Beispiel #2
0
    def test_first_fit_with_split(self):
        failed, mapping = apa.edf_first_fit_decreasing_difficulty(self.ts,
            [1, 2, 3], with_splits=True)

        self.assertEqual(failed, set())
        self.assertEqual(len(mapping), 3)
        self.assertEqual(mapping[1][0], self.ts[0])
Beispiel #3
0
    def test_first_fit_with_split(self):
        failed, mapping = apa.edf_first_fit_decreasing_difficulty(
            self.ts, [1, 2, 3], with_splits=True)

        self.assertEqual(failed, set())
        self.assertEqual(len(mapping), 3)
        self.assertEqual(mapping[1][0], self.ts[0])
Beispiel #4
0
    def test_first_fit(self):
        failed, mapping = apa.edf_first_fit_decreasing_difficulty(self.ts, [1, 2, 3])

        self.assertEqual(failed, set())
        self.assertEqual(len(mapping), 3)
        self.assertEqual(mapping[1], [self.ts[0], self.ts[1]])
        self.assertEqual(mapping[2], [self.ts[3]])
        self.assertEqual(mapping[3], [self.ts[2]])

        failed, mapping = apa.edf_first_fit_decreasing_difficulty(self.ts, [2, 1, 3])

        self.assertEqual(failed, set())
        self.assertEqual(len(mapping), 3)
        self.assertEqual(mapping[2], [self.ts[2], self.ts[1]])
        self.assertEqual(mapping[1], [self.ts[0], self.ts[3]])
        self.assertEqual(mapping[3], [])


        # give it one more to place
        self.ts.append(tasks.SporadicTask(19, 31))
        self.ts[-1].affinity = set([2, 3])
        self.ts.assign_ids()

        failed, mapping = apa.edf_first_fit_decreasing_difficulty(self.ts, [1, 2, 3])
        self.assertEqual(failed, set([self.ts[-1]]))

        failed, mapping = apa.edf_first_fit_decreasing_difficulty(self.ts, [2, 1, 3])

        self.assertEqual(failed, set())
        self.assertEqual(len(mapping), 3)
        self.assertEqual(mapping[2], [self.ts[2], self.ts[1]])
        self.assertEqual(mapping[1], [self.ts[0], self.ts[3]])
        self.assertEqual(mapping[3], [self.ts[4]])

        # give it yet another more to place
        self.ts.append(tasks.SporadicTask(40, 50))
        self.ts[-1].affinity = set([1, 2, 3])
        self.ts.assign_ids()

        failed, mapping = apa.edf_first_fit_decreasing_difficulty(self.ts, [2, 1, 3])

        self.assertEqual(failed, set([self.ts[4]]))
        self.assertEqual(len(mapping), 3)
        self.assertEqual(mapping[1], [self.ts[0], self.ts[5]])
        self.assertEqual(mapping[2], [self.ts[2], self.ts[1]])
        self.assertEqual(mapping[3], [self.ts[3]])
Beispiel #5
0
    def test_first_fit_with_splits(self):
        failed, mapping = apa.edf_first_fit_decreasing_difficulty(self.ts1,
                            [1, 2], with_splits=True)

        self.assertEqual(failed, set())
        self.assertEqual(len(mapping), 2)
        self.assertEqual(mapping[1][0].cost, 66)
        self.assertEqual(mapping[1][1].cost, 34)
        self.assertEqual(mapping[2][0].cost, 66)
        self.assertEqual(mapping[2][1].cost, 32)
Beispiel #6
0
    def test_first_fit_with_splits(self):
        failed, mapping = apa.edf_first_fit_decreasing_difficulty(
            self.ts1, [1, 2], with_splits=True)

        self.assertEqual(failed, set())
        self.assertEqual(len(mapping), 2)
        self.assertEqual(mapping[1][0].cost, 66)
        self.assertEqual(mapping[1][1].cost, 34)
        self.assertEqual(mapping[2][0].cost, 66)
        self.assertEqual(mapping[2][1].cost, 32)
Beispiel #7
0
    def test_first_fit_with_splits2(self):
        self.ts1.append(tasks.SporadicTask(31, 100))
        self.ts1[-1].affinity = set([1, 2])
        failed, mapping = apa.edf_first_fit_decreasing_difficulty(self.ts1,
                            [1, 2], with_splits=True)

        self.assertNotEqual(failed, set())
        self.assertEqual(failed.pop().id, self.ts1[-1].id)
        self.assertEqual(len(mapping), 2)
        self.assertEqual(mapping[1][0].cost, 66)
        self.assertEqual(mapping[1][1].cost, 34)
        self.assertEqual(mapping[2][0].cost, 66)
        self.assertEqual(mapping[2][1].cost, 32)
        self.assertEqual(mapping[2][2].cost, 2)
Beispiel #8
0
    def test_first_fit_with_splits2(self):
        self.ts1.append(tasks.SporadicTask(31, 100))
        self.ts1[-1].affinity = set([1, 2])
        failed, mapping = apa.edf_first_fit_decreasing_difficulty(
            self.ts1, [1, 2], with_splits=True)

        self.assertNotEqual(failed, set())
        self.assertEqual(failed.pop().id, self.ts1[-1].id)
        self.assertEqual(len(mapping), 2)
        self.assertEqual(mapping[1][0].cost, 66)
        self.assertEqual(mapping[1][1].cost, 34)
        self.assertEqual(mapping[2][0].cost, 66)
        self.assertEqual(mapping[2][1].cost, 32)
        self.assertEqual(mapping[2][2].cost, 2)