Skip to content

Instantly share code, notes, and snippets.

@bwasti
Created May 27, 2018 08:54
Show Gist options
  • Save bwasti/91cf5d282d819dfce241dc3408d31c0a to your computer and use it in GitHub Desktop.
Save bwasti/91cf5d282d819dfce241dc3408d31c0a to your computer and use it in GitHub Desktop.
for iteration in range(iters * batch_size):
# Create a graph with random weights
G = nx.complete_graph(num_nodes, nx.DiGraph())
# ... add random weights ...
# Give an edge to a sample of agents (not all are going to be playing)
players = random.sample(agents, len(G.edges))
# Calculate the shortest path
path = nx.shortest_path(G, source=source, target=sink, weight="price")
# Pay each player on the shortest path
for edge in get_edge_list(path):
pay_player_owning_edge(edge)
# Once a batch of runs is done, prune players and add new ones
if iteration % batch_size == 0:
prune_poor_agents()
clone_wealthy_agents()
add_new_agents()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment