def test_manydags_simple(): # 1 -> 2 -> 3 dag = {1: (2,), 2: (3, ), 3:()} jobson = {'A': (1, 2), 'B': (3, )} dags = manydags(dag, jobson) assert dags['A'] == {1: (2, ), 2: (send('A', 'B', 2, 3), ), send('A', 'B', 2, 3): ()} assert dags['B'] == {recv('A', 'B', 2, 3): (3, ), 3:()}
def test_manydags_simple(): # 1 -> 2 -> 3 dag = {1: (2, ), 2: (3, ), 3: ()} jobson = {'A': (1, 2), 'B': (3, )} dags = manydags(dag, jobson) assert dags['A'] == { 1: (2, ), 2: (send('A', 'B', 2, 3), ), send('A', 'B', 2, 3): () } assert dags['B'] == {recv('A', 'B', 2, 3): (3, ), 3: ()}
def test_replace_send_recv(): dag = { 1: (2, send(1, 2, 3, 4)), 2: (), send(1, 2, 3, 4): (), recv(1, 2, 3, 4): (1, ) } o = replace_send_recv(dag, lambda a, b, c, d: a + b + c + d, lambda a, b, c, d: a * b * c * d) assert o == { 1: (2, 1 + 2 + 3 + 4), 2: (), 1 + 2 + 3 + 4: (), 1 * 2 * 3 * 4: (1, ) }
def test_replace_send_recv(): dag = {1: (2, send(1,2,3,4)), 2: (), send(1,2,3,4): (), recv(1,2,3,4): (1,)} o = replace_send_recv(dag, lambda a,b,c,d: a+b+c+d, lambda a,b,c,d: a*b*c*d) assert o == {1: (2, 1+2+3+4), 2: (), 1+2+3+4: (), 1*2*3*4: (1,)}
def test_isrecv(): assert isrecv(recv(1,2,3,4)) assert not isrecv(send(1,2,3,4))
def bicommunication_cost(var, agent1, agent2): if agent1 == agent2: return 0 return 1 def R(job): return 0 def B(job, agent): return 1 M = 10 solution = { 'dags': {'A': {1: (send('A', 'B', 1, 2), send('A', 'C', 1, 3)), send('A', 'B', 1, 2): (), send('A', 'C', 1, 3): ()}, 'B': {2: (), ('recv', 'A', 'B', 1, 2): (2,)}, 'C': {3: (), ('recv', 'A', 'C', 1, 3): (3,)}}, 'makespan': 1, 'sched': [(1, 0.0, 'A'), (2, 1.0, 'B'), (3, 1.0, 'C')], 'orders': {'A': [1], 'B': [2], 'C': [3]}, # 'bidags': # {'A': ({a: (1,), b: (send('A', 'B'), ), c: (send('A', 'C'),)}, # {1: (b, c), send('A', 'B'): (), send('A', 'C'): ()}), # 'B': ({b: (2,), d: ()}, # {recv('A', 'B'): (b,), 2: (d,)}), # 'C': ({c: (3,), e: ()}, # {recv('A', 'C'): (c,), 3: (e,)})} }
def test_isrecv(): assert isrecv(recv(1, 2, 3, 4)) assert not isrecv(send(1, 2, 3, 4))