Example #1
0
    def test_corresponding_location(self):
        c1 = Component(100, (0, 0))
        c2 = Component(100, (0, 1))

        comp_to_loc = comp_to_loc_mapping([c1, c2])

        assert tuple(comp_to_loc[0]) == (0, 0, 0)
        assert tuple(comp_to_loc[1]) == (1, 0, 1)
Example #2
0
    def test_application_mapping(self):
        c1 = Component(100, (0, 1))
        c2 = Component(100, (1, 0))
        a1 = Application(60)
        a2 = Application(70)

        input_mapping = [(c1, a1), (c2, a2)]
        app_mapping = application_mapping([c1, c2], input_mapping)

        assert np.array_equal(app_mapping['comp'], np.array([0, 1]))
        assert np.array_equal(app_mapping['app'], np.array([60, 70]))
Example #3
0
    def example_designpoint(cap1=100,
                            cap2=100,
                            loc1=(0, 0),
                            loc2=(1, 1),
                            app1=50,
                            app2=50):
        c1 = Component(cap1, loc1)
        c2 = Component(cap2, loc2)

        a1 = Application(app1)
        a2 = Application(app2)

        return DesignPoint([c1, c2], [a1, a2], [(c1, a1), (c2, a2)])
Example #4
0
    def get_simulator_example(cap1=100,
                              cap2=100,
                              loc1=(0, 0),
                              loc2=(1, 1),
                              app1=50,
                              app2=50):
        c1 = Component(cap1, loc1)
        c2 = Component(cap2, loc2)

        a1 = Application(app1)
        a2 = Application(app2)

        dp = DesignPoint([c1, c2], [a1, a2], [(c1, a1), (c2, a2)])

        return Simulator(dp)
Example #5
0
    def create(caps, locs, apps, maps, policy='random'):
        """ Simplified static function to quickly generate design points.

        No other objects (e.g. Components or Applications) have to be created in order
        to initialize this design point.

        :param caps: [integer] - List of integers representing the comp_need capacity
        :param locs: [(integer, integer)] - List of integer tuples representing the coordinates of components
        :param apps: [integer] - List of integers representing the comp_need requirement of applications
        :param maps: [(integer, integer)] - Indexwise mapping of component indices and application indices
        :param policy: ['random', 'most', 'least'] - adaptivity policy (see Simulator)
        :return: DesignPoint object
        """
        comp_indices = [comp for comp, _ in maps]
        app_indices = [app for _, app in maps]

        assert len(app_indices) == len(
            set(app_indices)), "Applications are not uniquely mapped."
        assert all(
            x >= 0 for x in comp_indices
        ), "Components in the application mapping have negative indices."
        assert all(
            x >= 0 for x in app_indices
        ), "Components in the application mapping have negative indices."

        comps = [Component(caps[i], locs[i]) for i in range(len(caps))]
        apps = [Application(a) for a in apps]
        mapping = [(comps[maps[i][0]], apps[maps[i][1]])
                   for i in range(len(maps))]

        return DesignPoint(comps, apps, mapping, policy=policy)
Example #6
0
    def test_invalid_variables(self):
        power_cap = random.randint(-300, -1)
        location = (random.randint(-10, -1), random.randint(-10, -1))
        max_temp = random.randint(-100, -1)

        with pytest.raises(AssertionError):
            c = Component(power_cap, location, max_temp)
Example #7
0
    def get_components_example(cap1=100,
                               cap2=100,
                               loc1=(0, 0),
                               loc2=(1, 1),
                               app1=50,
                               app2=50):

        c1 = Component(cap1, loc1)
        c2 = Component(cap2, loc2)

        a1 = Application(app1)
        a2 = Application(app2)

        dp = DesignPoint([c1, c2], [a1, a2], [(c1, a1), (c2, a2)])
        dp_data = dp.to_numpy()

        return Components(dp_data['capabilities'], dp_data['power_usage'],
                          dp_data['comp_loc_map'], dp_data['app_map'])
Example #8
0
    def test_correct_variables(self):
        power_cap = random.randint(0, 300)
        location = (random.randint(0, 10), random.randint(0, 10))
        max_temp = random.randint(1, 100)

        c = Component(power_cap, location, max_temp)

        assert c.capacity == power_cap
        assert c.loc == location
        assert c.max_temp == max_temp
Example #9
0
    def test_duplicate_locations(self):
        c1 = Component(random.randint(1, 200), (1, 2))
        c2 = Component(random.randint(1, 200), (1, 2))

        with pytest.raises(AssertionError):
            comp_to_loc_mapping([c1, c2])
Example #10
0
    def test_unique_locations(self):
        c1 = Component(random.randint(1, 200), (random.randint(0, 5), random.randint(0, 5)))
        c2 = Component(random.randint(1, 200), (random.randint(6, 11), random.randint(6, 11)))

        comp_to_loc_mapping([c1, c2])