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]))
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)])
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)
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)
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'])
def test_correct_variables(self): power_req = random.randint(0, 300) a = Application(power_req) assert a.power_req == power_req
def test_incorrect_variables(self): power_req = random.randint(-300, -1) with pytest.raises(AssertionError): a = Application(power_req)