Esempio n. 1
0
        rv = np.random.randint(0, nstrats)
        node_strat = {node: robot_strategies[rv]}

        edge_strats = {e: robot_strategies[rv] for e in edges}

        self.internal_policy = {'nodes': nodes,
                       'edges': edges,
                       'quantity': initial_balls,
                       'node_strats': node_strat,
                       'edge_strats': edge_strats,
                       'delta': np.zeros(node + 1)
                       }

        return self

robot_udo = UDO(udo=robot(G, balls), masked_members=['obj'])
initial_conditions = {'balls': balls, 'network': G, 'robot': robot_udo}


def update_balls(params, step, sL, s, _input):
    delta_balls = _input['robot'].internal_policy['delta']
    new_balls = s['balls']
    for e in G.edges:
        move_ball = delta_balls[e]
        src = e[0]
        dst = e[1]
        if (new_balls[src] >= move_ball) and (new_balls[dst] >= -move_ball):
            new_balls[src] = new_balls[src] - move_ball
            new_balls[dst] = new_balls[dst] + move_ball

    key = 'balls'
    def read(self, ds_uri):
        self.ds = SilentDF(pd.read_csv(ds_uri))
        return self

    def write(self, ds_uri):
        pd.to_csv(ds_uri)

    # Generic update function

    pass


# can be accessed after an update within the same substep and timestep

state_udo = UDO(udo=udoExample(0, DF), masked_members=['obj', 'perception'])
policy_udoA = UDO(udo=udoExample(0, DF), masked_members=['obj', 'perception'])
policy_udoB = UDO(udo=udoExample(0, DF), masked_members=['obj', 'perception'])


def udo_policyA(_g, step, sL, s, **kwargs):
    s['udo_policies']['udo_A'].updateX()
    return {'udo_A': udoPipe(s['udo_policies']['udo_A'])}


def udo_policyB(_g, step, sL, s, **kwargs):
    s['udo_policies']['udo_B'].updateX()
    return {'udo_B': udoPipe(s['udo_policies']['udo_B'])}


policies = {"p1": udo_policyA, "p2": udo_policyB}
Esempio n. 3
0
T = 50 #iterations in our simulation
n = 3 #number of boxes in our network
m = 2 #for barabasi graph type number of edges is (n-2)*m

G = nx.barabasi_albert_graph(n, m)
k = len(G.edges)


# class udoExample(object):
#     def __init__(self, G):
#         self.G = G
#         self.mem_id = str(hex(id(self)))


g = UDO(udo=G)
print()
# print(g.edges)
# print(G.edges)
# pp.pprint(f"{type(g)}: {g}")
# next
balls = np.zeros(n,)

for node in g.nodes:
    rv = np.random.randint(1,25)
    g.nodes[node]['initial_balls'] = rv
    balls[node] = rv

# pp.pprint(balls)

# next